diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..8497a3f --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,50 @@ +{ + "files.associations": { + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "compare": "cpp", + "concepts": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "initializer_list": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "new": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "typeinfo": "cpp", + "fstream": "cpp" + } +} \ No newline at end of file diff --git a/ex04/Makefile b/ex04/Makefile index 730a48b..5458e0e 100644 --- a/ex04/Makefile +++ b/ex04/Makefile @@ -6,12 +6,12 @@ # By: whaffman +#+ # # +#+ # # Created: 2025/03/19 16:44:48 by whaffman #+# #+# # -# Updated: 2025/03/21 15:17:22 by whaffman ######## odam.nl # +# Updated: 2025/03/23 14:02:26 by whaffman ######## odam.nl # # # # **************************************************************************** # -NAME = -SRC = +NAME = Replacer +SRC = Replacer.cpp main.cpp -include ../common.mk diff --git a/ex04/Replacer b/ex04/Replacer new file mode 100755 index 0000000..afb8be5 Binary files /dev/null and b/ex04/Replacer differ diff --git a/ex04/Replacer.o b/ex04/Replacer.o new file mode 100644 index 0000000..c2221b9 Binary files /dev/null and b/ex04/Replacer.o differ diff --git a/ex04/inc/Replacer.hpp b/ex04/inc/Replacer.hpp new file mode 100644 index 0000000..c3cc30b --- /dev/null +++ b/ex04/inc/Replacer.hpp @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* :::::::: */ +/* Replacer.hpp :+: :+: */ +/* +:+ */ +/* By: whaffman +#+ */ +/* +#+ */ +/* Created: 2025/03/23 13:26:27 by whaffman #+# #+# */ +/* Updated: 2025/03/23 14:04:08 by whaffman ######## odam.nl */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include + +class Replacer +{ + private: + std::string oldString; + std::string newString; + Replacer(); + + public: + ~Replacer(); + Replacer(std::string const &oldString, std::string const &newString); + std::string process(std::string const &input) const; +}; + \ No newline at end of file diff --git a/ex04/main.o b/ex04/main.o new file mode 100644 index 0000000..c9507a0 Binary files /dev/null and b/ex04/main.o differ diff --git a/ex04/src/Replacer.cpp b/ex04/src/Replacer.cpp new file mode 100644 index 0000000..459dce6 --- /dev/null +++ b/ex04/src/Replacer.cpp @@ -0,0 +1,52 @@ +/* ************************************************************************** */ +/* */ +/* :::::::: */ +/* Replacer.cpp :+: :+: */ +/* +:+ */ +/* By: whaffman +#+ */ +/* +#+ */ +/* Created: 2025/03/23 13:30:57 by whaffman #+# #+# */ +/* Updated: 2025/03/23 14:05:40 by whaffman ######## odam.nl */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include "Replacer.hpp" + +Replacer::Replacer() +{ +} + +Replacer::~Replacer() +{ +} + +Replacer::Replacer(std::string const &oldString, std::string const &newString) : oldString(oldString), newString(newString) +{ +} + + +std::string Replacer::process(std::string const &input) const +{ + std::string result = ""; + size_t i = 0; + size_t j = 0; + + for (i = 0; i < input.size(); i++) + { + j = 0; + while (i + j < input.size() && input[i + j] == oldString[j]) + j++; + if (j == oldString.size()) + { + result += newString; + i += j - 1; + } + else + result += input[i]; + } + + return result; +} + diff --git a/ex04/src/main.cpp b/ex04/src/main.cpp new file mode 100644 index 0000000..0deda4a --- /dev/null +++ b/ex04/src/main.cpp @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* :::::::: */ +/* main.cpp :+: :+: */ +/* +:+ */ +/* By: whaffman +#+ */ +/* +#+ */ +/* Created: 2025/03/23 13:59:46 by whaffman #+# #+# */ +/* Updated: 2025/03/23 14:28:19 by whaffman ######## odam.nl */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include +#include "Replacer.hpp" + +int main(int argc, char *argv[]) +{ + + std::ifstream inFile; + std::fstream outFile; + std::string outFileName; + std::string line; + + if (argc != 4) + std::cout << "Usage: ./Replacer " << std::endl; + + inFile.open(argv[1], std::ios::in); + if (!inFile.is_open()) + std::cout << "Can't open In file" << std::endl; + + outFileName = argv[1]; + outFileName += ".replace"; + outFile.open(outFileName, std::ios::out); + if (!outFile.is_open()) + std::cout << "Can't open OUT file" << std::endl; + + Replacer replacer(argv[2], argv[3]); + + while(std::getline(inFile, line)) + { + outFile << replacer.process(line); + if (!inFile.eof()) + outFile << std::endl; + } +} \ No newline at end of file diff --git a/ex04/testfile b/ex04/testfile new file mode 100644 index 0000000..5762658 --- /dev/null +++ b/ex04/testfile @@ -0,0 +1,2 @@ +Dit is een test, maar niet zomaar een test +Dit is een test, maar niet zomaar een test diff --git a/ex04/testfile.replace b/ex04/testfile.replace new file mode 100644 index 0000000..402ddac --- /dev/null +++ b/ex04/testfile.replace @@ -0,0 +1,2 @@ +Dit is een proef, maar niet zomaar een proef +Dit is een proef, maar niet zomaar een proef diff --git a/ex05/Harl b/ex05/Harl new file mode 100755 index 0000000..26648ab Binary files /dev/null and b/ex05/Harl differ diff --git a/ex05/Harl.o b/ex05/Harl.o new file mode 100644 index 0000000..92bb6fa Binary files /dev/null and b/ex05/Harl.o differ diff --git a/ex05/Makefile b/ex05/Makefile index 730a48b..f4ac644 100644 --- a/ex05/Makefile +++ b/ex05/Makefile @@ -6,12 +6,12 @@ # By: whaffman +#+ # # +#+ # # Created: 2025/03/19 16:44:48 by whaffman #+# #+# # -# Updated: 2025/03/21 15:17:22 by whaffman ######## odam.nl # +# Updated: 2025/03/23 15:40:09 by whaffman ######## odam.nl # # # # **************************************************************************** # -NAME = -SRC = +NAME = Harl +SRC = Harl.cpp main.cpp -include ../common.mk diff --git a/ex05/inc/Harl.hpp b/ex05/inc/Harl.hpp new file mode 100644 index 0000000..25329eb --- /dev/null +++ b/ex05/inc/Harl.hpp @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* :::::::: */ +/* Harl.hpp :+: :+: */ +/* +:+ */ +/* By: whaffman +#+ */ +/* +#+ */ +/* Created: 2025/03/23 15:06:27 by whaffman #+# #+# */ +/* Updated: 2025/03/23 15:35:07 by whaffman ######## odam.nl */ +/* */ +/* ************************************************************************** */ + +#include + +class Harl +{ + private: + std::string levels[4]; + void (Harl::*levelFunc[4])(); + void info(); + void debug(); + void warning(); + void error(); + public: + Harl(); + ~Harl(); + void complain(std::string level); + }; \ No newline at end of file diff --git a/ex05/main.o b/ex05/main.o new file mode 100644 index 0000000..ff164ee Binary files /dev/null and b/ex05/main.o differ diff --git a/ex05/src/Harl.cpp b/ex05/src/Harl.cpp new file mode 100644 index 0000000..c40456b --- /dev/null +++ b/ex05/src/Harl.cpp @@ -0,0 +1,62 @@ +/* ************************************************************************** */ +/* */ +/* :::::::: */ +/* Harl.cpp :+: :+: */ +/* +:+ */ +/* By: whaffman +#+ */ +/* +#+ */ +/* Created: 2025/03/23 15:09:28 by whaffman #+# #+# */ +/* Updated: 2025/03/23 15:44:03 by whaffman ######## odam.nl */ +/* */ +/* ************************************************************************** */ + +#include "Harl.hpp" + +Harl::Harl() +{ + levels[0] = "DEBUG"; + levels[1] = "INFO"; + levels[2] = "WARNING"; + levels[3] = "ERROR"; + levelFunc[0] = &Harl::debug; + levelFunc[1] = &Harl::info; + levelFunc[2] = &Harl::warning; + levelFunc[3] = &Harl::error; +} +Harl::~Harl() {} + +void Harl::debug() +{ + std::cout << "[DEBUG]" << std::endl; + std::cout << "I love having extra bacon for my 7XL-double-cheese-triple-pickle-special-ketchup burger. I really do!" << std::endl; +} +void Harl::info() +{ + std::cout << "[INFO]" << std::endl; + std::cout << "I cannot believe adding extra bacon costs more money. You didn’t put enough bacon in my burger! If you did, I wouldn’t be asking for more!" << std::endl; +} + +void Harl::warning() +{ + std::cout << "[WARNING]" << std::endl; + std::cout << "I think I deserve to have some extra bacon for free. I’ve been coming for years, whereas you started working here just last month." << std::endl; +} + +void Harl::error() +{ + std::cout << "[ERROR]" << std::endl; + std::cout << "This is unacceptable! I want to speak to the manager now." << std::endl; +} + +void Harl::complain(std::string level) +{ + for (int i = 0; i < 4; i++) + { + if (level == levels[i]) + { + (this->*levelFunc[i])(); + return ; + } + } + std::cout << "I don't know anymorre what to complain about" << std::endl; +} \ No newline at end of file diff --git a/ex05/src/main.cpp b/ex05/src/main.cpp new file mode 100644 index 0000000..63bbb77 --- /dev/null +++ b/ex05/src/main.cpp @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* :::::::: */ +/* main.cpp :+: :+: */ +/* +:+ */ +/* By: whaffman +#+ */ +/* +#+ */ +/* Created: 2025/03/23 15:38:32 by whaffman #+# #+# */ +/* Updated: 2025/03/23 15:44:11 by whaffman ######## odam.nl */ +/* */ +/* ************************************************************************** */ + +#include "Harl.hpp" + +int main(void) +{ + Harl harl; + harl.complain("DEBUG"); + harl.complain("INFO"); + harl.complain("WARNING"); + harl.complain("ERROR"); + harl.complain("TEST"); +} \ No newline at end of file