update: finishing the ex04 of the module 01
This commit is contained in:
parent
08a23cc42b
commit
afd6bd90af
3 changed files with 30 additions and 12 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/05 15:58:02 by rparodi #+# #+# */
|
||||
/* Updated: 2024/11/05 21:58:30 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/11/06 16:14:03 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -33,13 +33,25 @@ const char *Sed::getFilename()
|
|||
return (_filename.c_str());
|
||||
}
|
||||
|
||||
bool Sed::line(std::ofstream output)
|
||||
bool Sed::line(std::ofstream& output)
|
||||
{
|
||||
std::string to_ret;
|
||||
|
||||
if (!std::getline((*_input), to_ret))
|
||||
return (false);
|
||||
output << to_ret << std::endl;
|
||||
std::cout << to_ret << std::endl;
|
||||
return (true);
|
||||
if (!std::getline(*_input, to_ret)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string result;
|
||||
std::size_t pos = 0;
|
||||
std::size_t found = 0;
|
||||
|
||||
while ((found = to_ret.find(_to_replace, pos)) != std::string::npos) {
|
||||
result += to_ret.substr(pos, found - pos) + _by_word;
|
||||
pos = found + _to_replace.length();
|
||||
}
|
||||
|
||||
result += to_ret.substr(pos);
|
||||
|
||||
output << result << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue