d01 ex04 a peu pres ok mais une erreure, et unitests ok
This commit is contained in:
@@ -2,30 +2,35 @@
|
||||
|
||||
Sed::Sed(char *file, char *find, char *replacement)
|
||||
: _file( file )
|
||||
// , _new_file( file.append(".replace") )
|
||||
, _new_file( std::string(file).append(".replace") )
|
||||
, _find( find )
|
||||
, _replacement( replacement )
|
||||
{
|
||||
, _replacement( replacement ) {
|
||||
|
||||
// this->_buf =
|
||||
return;
|
||||
|
||||
}
|
||||
Sed::~Sed() {
|
||||
|
||||
// delete[] this->_buf;
|
||||
return;
|
||||
|
||||
}
|
||||
Sed::~Sed() {return;}
|
||||
|
||||
void Sed::replace() {
|
||||
|
||||
std::ifstream file(this->_file.c_str());
|
||||
char c;
|
||||
std::ofstream new_file(this->_new_file.c_str());
|
||||
char str[this->_find.length() - 1];
|
||||
int len = this->_find.length();
|
||||
char tmp;
|
||||
|
||||
while (file.get(c))
|
||||
while (file.get(str, 1 + 1, EOF))
|
||||
{
|
||||
std::cout << c;
|
||||
if (str[0] == this->_find[0])
|
||||
{
|
||||
tmp = str[0];
|
||||
file.get(str, len, EOF);
|
||||
if (this->_find.compare(1, len - 1, str) == 0)
|
||||
new_file << this->_replacement;
|
||||
else
|
||||
new_file << tmp << str;
|
||||
}
|
||||
else
|
||||
new_file << str;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user