Uma simples implementação personalizável de uma classe String que imita a funcionalidade do STD :: String, incluindo iteradores.
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();
Retorna o iterador/const_iterator ao primeiro caractere
iterator begin();
const_iterator begin() const;
Retorna o iterador/const_iterator apontando para o caráter do passado da string
iterator end();
const_iterator end() const;
Retorna const_iterator apontando para o primeiro personagem / personagem do passado da string
const_iterator cbegin() const;
const_iterator cend() const;
Retorna reverse_iterator/const_reverse_iterator ao último caractere
reverse_iterator rbegin();
const_reverse_iterator rbegin() const;
Retorna reverse_iterator/const_reverse_iterator apontando para reverter o caráter do passado da string
reverse_iterator rend();
const_reverse_iterator rend() const;
Retorna const_reverse_iterator apontando para o último personagem / reverter o caráter do passado da string
const_reverse_iterator crbegin() const;
const_reverse_iterator crend() const;
Obtenha o caráter da corda
const char & operator [] (size_type) const;
char & operator [] (size_type);
Obtenha o personagem em string
const char & at(size_type) const;
char & at(size_type);
Acesse o primeiro caractere
const char & front() const;
char & front();
Acesse o último caractere
const char & back() const;
char & back();
Anexar a string
String & operator += (const String &); // string (1)
String & operator += (const char *); // c - string (2)
String & operator += (char); // char (3)
Anexar a string
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);
Insira na string
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)
Apague os caracteres da string
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)
Substitua parte da corda
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)
Trocar valores de string
void swap(String &);
Exclua o último personagem
String & pop_back();
Get C String equivalente
const char * c_str() const;
Sequência de copiar de caracteres da string
size_t copy(char* s, size_t len, size_type pos = 0) const;
Encontre conteúdo em string
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)
Encontre a última ocorrência de conteúdo em string
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)
Encontre o personagem em string
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)
Encontre o personagem em string do final
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)
Encontre ausência de caráter na corda
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)
Encontre caractere não correspondente na string do final
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)
Gerar substring
String substr(size_type pos = 0, size_t len = npos) const;
Retorna o comprimento da corda
size_t length() const;
size_t size() const;
Retorna o tamanho máximo da corda
size_t max_size() const;
Redimensione a string
void resize(size_t n);
void resize(size_type n, char c);
Tamanho do retorno do armazenamento alocado
size_t capacity() const;
Solicite uma mudança na capacidade
void reserve(size_t n = 0);
String clara
void clear();
Retornar true é string está vazio
bool empty() const;
Encolher para caber
void shrink_to_fit();
static const size_t npos = -1; // Maximum value for size_t
Comparações
// 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 &);
Troca os valores de duas cordas
void swap(String& x, String& y);
Retorna cordas concatenadas
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);
Insira a string no fluxo
std::ostream& operator<< (std::ostream& os, const _JD String& str);
Extrair string do fluxo
std::istream& operator>> (std::istream& is, _JD String& str);
Obtenha a linha do fluxo para a string
std::istream& getline(std::istream& is, _JD String& str, char delim);
std::istream& getline(std::istream& is, _JD String& str);