Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include "string.h"
- class String;
- String::String()
- {
- len = 0;
- str = new char[1];
- str[0] = '\0';
- }
- String::String(const char* s)
- {
- len = strlen(s);
- str = new char[len + 1];
- strcpy(str, s);
- }
- String::String(const String& other)
- {
- len = other.len;
- str = new char[len + 1];
- strcpy(str, other.str);
- }
- String& String::operator=(const String& other)
- {
- if (this == &other)
- return *this;
- delete[] str;
- len = other.len;
- str = new char[len + 1];
- strcpy(str, other.str);
- return *this;
- }
- WordIterator String::split(const String& separators)
- {
- WordIterator result;
- char* p = this->str;
- while(p)
- {
- p = skip_spaces(p, separators);
- if (!*p)
- break;
- char* word = p;
- p = skip_until_spaces(p, separators);
- int len = p-word;
- char* wordcc = new char[len+1];
- strncpy(wordcc, word, len);
- wordcc[len] = 0;
- result.add(wordcc);
- delete[] wordcc;
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement