aboutsummaryrefslogtreecommitdiff
path: root/oop1w5
diff options
context:
space:
mode:
Diffstat (limited to 'oop1w5')
-rw-r--r--oop1w5/StringWeek5.cpp12
-rw-r--r--oop1w5/StringWeek5.h16
-rw-r--r--oop1w5/StringWeek5.hpp12
-rw-r--r--oop1w5/main.cpp20
l---------oop1w5/makefile1
5 files changed, 61 insertions, 0 deletions
diff --git a/oop1w5/StringWeek5.cpp b/oop1w5/StringWeek5.cpp
new file mode 100644
index 0000000..ae8ba9f
--- /dev/null
+++ b/oop1w5/StringWeek5.cpp
@@ -0,0 +1,12 @@
+#include <regex>
+
+#include "StringWeek5.h"
+
+void StringWeek5::removeAll(const std::string& remove) {
+ this->text = std::regex_replace(this->text, std::regex(remove), "");
+}
+
+const std::string& StringWeek5::getText() const {
+ return this->text;
+}
+
diff --git a/oop1w5/StringWeek5.h b/oop1w5/StringWeek5.h
new file mode 100644
index 0000000..8c2bdac
--- /dev/null
+++ b/oop1w5/StringWeek5.h
@@ -0,0 +1,16 @@
+#pragma once
+
+#include <string>
+#include <sstream>
+
+class StringWeek5 {
+public:
+ template <class T>
+ void add(const T& value);
+ void removeAll(const std::string& remove);
+ const std::string& getText() const;
+private:
+ std::string text;
+};
+
+#include "StringWeek5.hpp"
diff --git a/oop1w5/StringWeek5.hpp b/oop1w5/StringWeek5.hpp
new file mode 100644
index 0000000..ed71e75
--- /dev/null
+++ b/oop1w5/StringWeek5.hpp
@@ -0,0 +1,12 @@
+#pragma once
+
+#include "StringWeek5.h"
+#include <string>
+
+template <typename T>
+void StringWeek5::add(const T& value) {
+ std::stringstream value_str("");
+ value_str << value;
+ this->text.append(value_str.str());
+}
+
diff --git a/oop1w5/main.cpp b/oop1w5/main.cpp
new file mode 100644
index 0000000..a2603fa
--- /dev/null
+++ b/oop1w5/main.cpp
@@ -0,0 +1,20 @@
+#include "StringWeek5.h"
+
+#include <iostream>
+
+int main() {
+ StringWeek5 myString;
+
+ myString.add("hallo allemaal ");
+ myString.add(42);
+ myString.add(" ");
+ myString.add(3.14159265358979);
+
+ std::cout << myString.getText() << std::endl;
+
+ myString.removeAll("all");
+
+ std::cout << myString.getText() << std::endl << std::endl;
+
+ return 0;
+}
diff --git a/oop1w5/makefile b/oop1w5/makefile
new file mode 120000
index 0000000..a4e84c6
--- /dev/null
+++ b/oop1w5/makefile
@@ -0,0 +1 @@
+../week.mk \ No newline at end of file