From c5144c9d77bf920635e4d1a1b267c71cb03fd9ef Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 13 Nov 2024 22:13:26 +0100 Subject: [PATCH] push --- cpp00/ex01/.clangd | 5 ++-- cpp01/ex04/main.cpp | 2 +- cpp01/ex04/sed.cpp | 68 ++++++++++++++++++++------------------------- 3 files changed, 33 insertions(+), 42 deletions(-) diff --git a/cpp00/ex01/.clangd b/cpp00/ex01/.clangd index 9974bf0..f4ba9f9 100644 --- a/cpp00/ex01/.clangd +++ b/cpp00/ex01/.clangd @@ -1,9 +1,8 @@ CompileFlags: - Compiler: clang Add: - "-xc++" - - "-stdlib=libc++" + - "-std=c++98" - "-I/usr/local/include" - "-I/nix/store/pzmpyb9hxfv60vh0l67avr94h71nip1b-llvm-16.0.6-dev/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" diff --git a/cpp01/ex04/main.cpp b/cpp01/ex04/main.cpp index 27a0375..d33b22c 100644 --- a/cpp01/ex04/main.cpp +++ b/cpp01/ex04/main.cpp @@ -6,7 +6,7 @@ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/cpp01/ex04/sed.cpp b/cpp01/ex04/sed.cpp index 5efef75..d7908f5 100644 --- a/cpp01/ex04/sed.cpp +++ b/cpp01/ex04/sed.cpp @@ -6,7 +6,7 @@ /* 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 #include -Sed::Sed(char **argv, std::ifstream *input) -{ - _filename = argv[1]; - _filename += ".replace"; - _to_replace = argv[2]; - _by_word = argv[3]; - _input = input; +Sed::Sed(char **argv, std::ifstream *input) { + _filename = argv[1]; + _filename += ".replace"; + _to_replace = argv[2]; + _by_word = argv[3]; + _input = input; } -Sed::~Sed() -{ +Sed::~Sed() {} -} - -const char *Sed::getFilename() -{ - return (_filename.c_str()); -} - -bool Sed::line(std::ofstream& output) -{ - std::string to_ret; - - 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; +const char *Sed::getFilename() { return (_filename.c_str()); } + +bool Sed::line(std::ofstream &output) { + std::string to_ret; + + 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; }