This commit is contained in:
Raphael 2024-11-13 22:13:26 +01:00
parent 7565eabf9b
commit c5144c9d77
3 changed files with 33 additions and 42 deletions

View file

@ -1,9 +1,8 @@
CompileFlags: CompileFlags:
Compiler: clang
Add: Add:
- "-xc++" - "-xc++"
- "-stdlib=libc++" - "-std=c++98"
- "-I/usr/local/include" - "-I/usr/local/include"
- "-I/nix/store/pzmpyb9hxfv60vh0l67avr94h71nip1b-llvm-16.0.6-dev/include" - "-I/nix/store/pzmpyb9hxfv60vh0l67avr94h71nip1b-llvm-16.0.6-dev/include"
- "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include" - "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include"
- "-I/Users/raphael/Documents/42_cursus/circle4/cpp/cpp00/ex01" - "-I/Users/raphael/Documents/42_cursus/circle4/cpp/cpp00/ex01/includes"

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/05 15:24:29 by rparodi #+# #+# */ /* Created: 2024/11/05 15:24:29 by rparodi #+# #+# */
/* Updated: 2024/11/06 16:36:48 by rparodi ### ########.fr */ /* Updated: 2024/11/09 10:36:55 by rparodi ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/05 15:58:02 by rparodi #+# #+# */ /* Created: 2024/11/05 15:58:02 by rparodi #+# #+# */
/* Updated: 2024/11/06 16:14:03 by rparodi ### ########.fr */ /* Updated: 2024/11/09 10:41:45 by rparodi ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,44 +14,36 @@
#include <fstream> #include <fstream>
#include <ios> #include <ios>
Sed::Sed(char **argv, std::ifstream *input) Sed::Sed(char **argv, std::ifstream *input) {
{ _filename = argv[1];
_filename = argv[1]; _filename += ".replace";
_filename += ".replace"; _to_replace = argv[2];
_to_replace = argv[2]; _by_word = argv[3];
_by_word = argv[3]; _input = input;
_input = input;
} }
Sed::~Sed() Sed::~Sed() {}
{
} const char *Sed::getFilename() { return (_filename.c_str()); }
const char *Sed::getFilename() bool Sed::line(std::ofstream &output) {
{ std::string to_ret;
return (_filename.c_str());
} if (!std::getline(*_input, to_ret)) {
return false;
bool Sed::line(std::ofstream& output) }
{
std::string to_ret; std::string result;
std::size_t pos = 0;
if (!std::getline(*_input, to_ret)) { std::size_t found = 0;
return false;
} while ((found = to_ret.find(_to_replace, pos)) != std::string::npos) {
result += to_ret.substr(pos, found - pos) + _by_word;
std::string result; pos = found + _to_replace.length();
std::size_t pos = 0; }
std::size_t found = 0;
result += to_ret.substr(pos);
while ((found = to_ret.find(_to_replace, pos)) != std::string::npos) {
result += to_ret.substr(pos, found - pos) + _by_word; output << result << std::endl;
pos = found + _to_replace.length(); return true;
}
result += to_ret.substr(pos);
output << result << std::endl;
return true;
} }