An alternative to std::string with a custom SSO (small string optimization) container size. Unlike std::string, SmallString is not null-terminated thus it has no c_str(), data() returns a not null-terminated buffer. More...
#include <userver/utils/small_string.hpp>
Public Types | |
using | iterator = typename Container::iterator |
using | const_iterator = typename Container::const_iterator |
Public Member Functions | |
SmallString ()=default | |
Create empty string. | |
SmallString (const SmallString< N > &)=default | |
Create a string from another one. | |
SmallString (SmallString< N > &&) noexcept=default | |
Create a string from another one. | |
SmallString (std::string_view sv) | |
Create a string from std::string_view. | |
SmallString & | operator= (std::string_view sv) |
Assign the value of other string_view to this string. | |
SmallString & | operator= (const SmallString &)=default |
Assign the value of other string to this string. | |
SmallString & | operator= (SmallString &&) noexcept=default |
Assign the value of other string to this string. | |
operator std::string_view () const | |
Convert string to a std::string_view. | |
const char & | operator[] (std::size_t pos) const |
Read-only subscript access to the data contained in the string. | |
char & | operator[] (std::size_t pos) |
Subscript access to the data contained in the string. | |
const char & | at (std::size_t pos) const |
Provides access to the data contained in the string. | |
char & | at (std::size_t pos) |
Provides access to the data contained in the string. | |
iterator | begin () noexcept |
const_iterator | begin () const noexcept |
iterator | end () noexcept |
const_iterator | end () const noexcept |
std::size_t | size () const noexcept |
Get string size. | |
const char * | data () const noexcept |
Get pointer to data. | |
char * | data () noexcept |
Get pointer to data. | |
void | resize (std::size_t n, char c) |
Resize the string. If its length is increased, fill new chars with c. | |
std::size_t | capacity () const noexcept |
Get current capacity. | |
void | reserve (std::size_t n) |
Reserve to n bytes. | |
void | clear () noexcept |
Clear the string. | |
bool | empty () const noexcept |
Is the string empty? | |
char & | front () |
Get a reference to the first character. | |
const char & | front () const |
Get a reference to the first character. | |
char & | back () |
Get a reference to the last character. | |
const char & | back () const |
Get a reference to the last character. | |
void | push_back (char c) |
Append a character to the string. | |
void | pop_back () |
Remove the last character from the string. | |
An alternative to std::string with a custom SSO (small string optimization) container size. Unlike std::string, SmallString is not null-terminated thus it has no c_str(), data() returns a not null-terminated buffer.
Definition at line 24 of file small_string.hpp.
using utils::SmallString< N >::const_iterator = typename Container::const_iterator |
Definition at line 66 of file small_string.hpp.
using utils::SmallString< N >::iterator = typename Container::iterator |
Definition at line 64 of file small_string.hpp.
|
explicit |
Create a string from std::string_view.
Definition at line 124 of file small_string.hpp.
char & utils::SmallString< N >::at | ( | std::size_t | pos | ) |
Provides access to the data contained in the string.
Definition at line 175 of file small_string.hpp.
const char & utils::SmallString< N >::at | ( | std::size_t | pos | ) | const |
Provides access to the data contained in the string.
Definition at line 169 of file small_string.hpp.
char & utils::SmallString< N >::back | ( | ) |
Get a reference to the last character.
Definition at line 231 of file small_string.hpp.
const char & utils::SmallString< N >::back | ( | ) | const |
Get a reference to the last character.
Definition at line 236 of file small_string.hpp.
|
noexcept |
Definition at line 186 of file small_string.hpp.
|
noexcept |
Definition at line 181 of file small_string.hpp.
|
noexcept |
Get current capacity.
Definition at line 256 of file small_string.hpp.
|
noexcept |
Get pointer to data.
Definition at line 206 of file small_string.hpp.
|
noexcept |
Get pointer to data.
Definition at line 211 of file small_string.hpp.
|
noexcept |
Is the string empty?
Definition at line 216 of file small_string.hpp.
|
noexcept |
Definition at line 196 of file small_string.hpp.
|
noexcept |
Definition at line 191 of file small_string.hpp.
char & utils::SmallString< N >::front | ( | ) |
Get a reference to the first character.
Definition at line 221 of file small_string.hpp.
const char & utils::SmallString< N >::front | ( | ) | const |
Get a reference to the first character.
Definition at line 226 of file small_string.hpp.
utils::SmallString< N >::operator std::string_view | ( | ) | const |
Convert string to a std::string_view.
Definition at line 128 of file small_string.hpp.
SmallString< N > & utils::SmallString< N >::operator= | ( | std::string_view | sv | ) |
Assign the value of other string_view to this string.
Definition at line 133 of file small_string.hpp.
char & utils::SmallString< N >::operator[] | ( | std::size_t | pos | ) |
Subscript access to the data contained in the string.
Definition at line 164 of file small_string.hpp.
const char & utils::SmallString< N >::operator[] | ( | std::size_t | pos | ) | const |
Read-only subscript access to the data contained in the string.
Definition at line 159 of file small_string.hpp.
void utils::SmallString< N >::pop_back | ( | ) |
Remove the last character from the string.
Definition at line 246 of file small_string.hpp.
void utils::SmallString< N >::push_back | ( | char | c | ) |
Append a character to the string.
Definition at line 241 of file small_string.hpp.
void utils::SmallString< N >::reserve | ( | std::size_t | n | ) |
Reserve to n bytes.
Definition at line 261 of file small_string.hpp.
void utils::SmallString< N >::resize | ( | std::size_t | n, |
char | c | ||
) |
Resize the string. If its length is increased, fill new chars with c.
Definition at line 251 of file small_string.hpp.
|
noexcept |
Get string size.
Definition at line 201 of file small_string.hpp.