Простая настраиваемая реализация строкового класса, которая имитирует функциональность Std :: String, включая итераторы.
using size_type = size_t; // size_type for positions of char in cstring
using const_pointer = const_iterator;
using pointer = iterator;
using const_reverse_pointer = const_reverse_iterator;
using reverse_pointer = reverse_iterator;
String(); // default constructor
String(const String &); // copy constructor
String(const String& other, size_type pos, size_t len = npos); // substring constructor
String(String &&); // move constructor
String(const char *); // from c-string
String(const char* s, size_t n); // from buffer
String(size_t n, char c);// fill constructor
String(const const_iterator first, const const_iterator second); // range constructor
String & operator= (const String &); // copy assignment
String & operator = (String &&); // move assignment
~String();
Возвращает итератор/const_iterator в первый символ
iterator begin();
const_iterator begin() const;
Возвращает итератор/const_iterator, указывая на символ прошлого строки
iterator end();
const_iterator end() const;
Возвращает Const_iterator, указывающий на первый символ / прошлый символ строки
const_iterator cbegin() const;
const_iterator cend() const;
Возвращает обратный_итертор/const_reverse_iterator к последнему символу
reverse_iterator rbegin();
const_reverse_iterator rbegin() const;
Returns reverse_iterator/const_reverse_iterator, указывая на обращение с символом в прошлом строке
reverse_iterator rend();
const_reverse_iterator rend() const;
Возвращает const_reverse_iterator, указывая на последний символ / обратный символ прошлого строки
const_reverse_iterator crbegin() const;
const_reverse_iterator crend() const;
Получить символ строки
const char & operator [] (size_type) const;
char & operator [] (size_type);
Получить символ в строке
const char & at(size_type) const;
char & at(size_type);
Доступ первого персонажа
const char & front() const;
char & front();
Доступ к последнему персонажу
const char & back() const;
char & back();
Добавить в строку
String & operator += (const String &); // string (1)
String & operator += (const char *); // c - string (2)
String & operator += (char); // char (3)
Добавить в строку
String& append(const String& str); // string (1)
String& append(const String& str, size_type subpos, size_t sublen = npos); // substring (2)
String& append(const char* s); // c - string (3)
String& append(const char* s, size_t n); // buffer(4)
String& append(size_type n, char c); // fill(5)
String& append(const const_iterator first, const const_iterator second); // range(6)
String & push_back(char);
Вставить в строку
String& insert(size_type pos, const String& other); // string(1)
String& insert(size_type pos, const String& other, size_type subpos, size_t sublen = npos); // substring(2)
String& insert(size_type pos, const char* other); // c - string(3)
String& insert(size_type pos, const char* s, size_t n); // buffer(4)
String& insert(size_type pos, size_t n, char c); // fill(5)
void insert(iterator p, size_t n, char c); // fill(6)
iterator insert(iterator p, char c); // single character(7)
void insert(iterator p, const const_iterator first, const const_iterator last); // range(8)
Стереть символы из строки
String& erase(size_type pos = 0, size_t len = npos); // sequence(1)
iterator erase(const_iterator p); // character(2)
iterator erase(const_iterator first, const_iterator last); // range(3)
Заменить часть строки
String& replace(size_type pos, size_t len, const String& other); // string(1)
String& replace(const_iterator i1, const_iterator i2, const String& other); // string(2)
String& replace(size_type pos, size_t len, const String& other, size_type subpos, size_t sublen = npos); // substring(3)
String& replace(size_type pos, size_t len, const char* s); // c - string(4)
String& replace(const_iterator i1, const_iterator i2, const char* other); // c - string(5)
String& replace(size_type pos, size_t len, const char* other, size_t n); // buffer(6)
String& replace(const_iterator i1, const_iterator i2, const char* other, size_t n); // buffer(7)
String& replace(size_type pos, size_t len, size_t n, char c); // fill(8)
String& replace(const_iterator i1, const_iterator i2, size_type n, char c); // fill(9)
String& replace(const_iterator i1, const_iterator i2, const_iterator first, const_iterator second); // range(10)
Смена значений строки
void swap(String &);
Удалить последний персонаж
String & pop_back();
Получить C строку эквивалента
const char * c_str() const;
Последовательность копирования символов из строки
size_t copy(char* s, size_t len, size_type pos = 0) const;
Найти контент в строке
size_type find(const String& other, size_type pos = 0) const; //string(1)
size_type find(const char* s, size_type pos = 0) const; // c - string(2)
size_type find(const char* s, size_type pos, size_type n) const; // buffer(3)
size_type find(char c, size_type pos = 0) const; // character(4)
Найти последнее происшествие в строке
size_type rfind(const String& other, size_type pos = npos) const; // string(1)
size_type rfind(const char* s, size_type pos = npos) const; // c - string(2)
size_type rfind(const char* s, size_type pos, size_t n) const; // buffer(3)
size_type rfind(char c, size_type pos = npos) const; // character(4)
Найти символ в строке
size_type find_first_of(const String& other, size_type pos = 0) const; // string(1)
size_type find_first_of(const char* other, size_type pos = 0) const; // c - string(2)
size_type find_first_of(const char* other, size_type pos, size_t n) const; // buffer(3)
size_type find_first_of(char c, size_type pos = 0) const; // character(4)
Найдите символ в строке из конца
size_type find_last_of(const String& other, size_type pos = String::npos) const; // string(1)
size_type find_last_of(const char* other, size_type pos = String::npos) const; // c - string(2)
size_type find_last_of(const char* other, size_type pos, size_t n) const; // buffer(3)
size_type find_last_of(char c, size_type pos = String::npos) const; // character(4)
Найти отсутствие символа в строке
size_type find_first_not_of(const String& other, size_type pos = 0) const; // string(1)
size_type find_first_not_of(const char* other, size_type pos = 0) const; // c - string(2)
size_type find_first_not_of(const char* other, size_type pos, size_t n) const; // buffer(3)
size_type find_first_not_of(char c, size_type pos = 0) const; // character(4)
Найти не совпадающий символ в строке с конца
size_type find_last_not_of(const String& other, size_type pos = String::npos) const; // string(1)
size_type find_last_not_of(const char* other, size_type pos = String::npos) const; // c - string(2)
size_type find_last_not_of(const char* other, size_type pos, size_t n) const; // buffer(3)
size_type find_last_not_of(char c, size_type pos = String::npos) const; // character(4)
Генерировать подстроение
String substr(size_type pos = 0, size_t len = npos) const;
Возвращает длину строки
size_t length() const;
size_t size() const;
Возвращает максимальный размер строки
size_t max_size() const;
Изменить размер строки
void resize(size_t n);
void resize(size_type n, char c);
Возврат размер выделенного хранилища
size_t capacity() const;
Запросить изменение емкости
void reserve(size_t n = 0);
Чистая строка
void clear();
Вернуть True Is String пуста
bool empty() const;
Сжиматься, чтобы соответствовать
void shrink_to_fit();
static const size_t npos = -1; // Maximum value for size_t
Сравнения
// Size is compared and if equal then comapred lexicographically
friend bool operator == (const String &, const String &);
friend bool operator != (const String &, const String &);
friend bool operator < (const String &, const String &);
friend bool operator > (const String &, const String &);
friend bool operator <= (const String &, const String &);
friend bool operator >= (const String &, const String &);
Обменивается значениями двух строк
void swap(String& x, String& y);
Возвращает конкатенированные строки
String operator+ (const String& lhs, const String& rhs);
String operator+ (const String& lhs, const char* rhs);
String operator+ (const char* lhs, const String& rhs);
String operator+ (const String& lhs, char rhs);
String operator+ (char lhs, const String& rhs);
Вставить строку в потоку
std::ostream& operator<< (std::ostream& os, const _JD String& str);
Извлечь строку из потока
std::istream& operator>> (std::istream& is, _JD String& str);
Получить линию от потока в строку
std::istream& getline(std::istream& is, _JD String& str, char delim);
std::istream& getline(std::istream& is, _JD String& str);