* The subscript operator is provided for access to individual characters
*/
-// TODO: boundary check.
// TODO: Assignment to an individual character does not decouple references (BUG)
char& String::operator[](size_t i)
else
return -1;
}
+
+SuperString String::split(const String &separator)
+{
+ SuperString splitted;
+ char *sep, *part;
+
+ part = p->s;
+ sep = strstr(p->s, separator.p->s);
+
+ while (sep != NULL)
+ {
+ // Create a new string from the part until the separator
+
+ int len = sep - part;
+ char *str = new char[len + 1];
+
+ strncpy(str, part, len);
+ str[len] = '\0';
+ splitted += String(str);
+
+ // Look for the next separator
+
+ sep += ~separator;
+ part = sep;
+ sep = strstr(sep, separator.p->s);
+ }
+
+ // Add the leftover after the last separator.
+
+ splitted += String(part);
+
+ return splitted;
+}