aboutsummaryrefslogtreecommitdiff
path: root/week13/Exercise1/WordString.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'week13/Exercise1/WordString.cpp')
-rw-r--r--week13/Exercise1/WordString.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/week13/Exercise1/WordString.cpp b/week13/Exercise1/WordString.cpp
new file mode 100644
index 0000000..4ba3cca
--- /dev/null
+++ b/week13/Exercise1/WordString.cpp
@@ -0,0 +1,25 @@
+#include "WordString.h"
+
+bool isBlank(char ch) {
+ return ch == ' ' || ch == '\n' || ch == '\t';
+}
+
+WordString::WordString(const char* str) : String(str), IndexArray() {
+ this->size = 1;
+ for (int i = 1; str[i] != '\0'; i++) {
+ if (isBlank(str[i - 1]) && !isBlank(str[i])) {
+ this->size++;
+ }
+ }
+
+ this->indecies = new int[this->size];
+
+ this->indecies[0] = 0;
+ unsigned indeciesI = 1;
+
+ for (int i = 1; str[i] != '\0'; i++) {
+ if (isBlank(str[i - 1]) && !isBlank(str[i])) {
+ indecies[indeciesI++] = i;
+ }
+ }
+}