aboutsummaryrefslogtreecommitdiff
path: root/week13/Exercise1/WordString.cpp
blob: 4ba3cca2ed37fbcda780f15e2fedb1db81541869 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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;
		}
	}
}