iceoryx_hoofs 2.0.5
|
string implementation with some adjustments in the API, because we are not allowed to throw exceptions or use heap. More...
#include <iceoryx_hoofs/cxx/string.hpp>
Public Member Functions | |
constexpr | string () noexcept=default |
creates an empty string with size 0 | |
string (const string &other) noexcept | |
copy constructor | |
string (string &&other) noexcept | |
move constructor | |
string & | operator= (const string &rhs) noexcept |
copy assignment | |
string & | operator= (string &&rhs) noexcept |
move assignment | |
template<uint64_t N> | |
string (const string< N > &other) noexcept | |
creates a new string of given capacity as a copy of other with compile time check whether the capacity of other is less than or equal to this' capacity | |
template<uint64_t N> | |
string (string< N > &&other) noexcept | |
moves other to this with compile time check whether the capacity of other is less than or equal to this' capacity | |
template<uint64_t N> | |
string & | operator= (const string< N > &rhs) noexcept |
assigns rhs fixed string to this with compile time check whether the capacity of rhs is less than or equal to this' capacity | |
template<uint64_t N> | |
string & | operator= (string< N > &&rhs) noexcept |
moves rhs fixed string to this with compile time check whether the capacity of rhs is less than or equal to this' capacity | |
template<uint64_t N> | |
string (const char(&other)[N]) noexcept | |
conversion constructor for char array with compile time check if the array size is less than or equal to the string capacity | |
string (TruncateToCapacity_t, const char *const other) noexcept | |
conversion constructor for cstring to string which truncates characters if the size is greater than the string capacity | |
string (TruncateToCapacity_t, const std::string &other) noexcept | |
conversion constructor for std::string to string which truncates characters if the std::string size is greater than the string capacity | |
string (TruncateToCapacity_t, const char *const other, const uint64_t count) noexcept | |
constructor from cstring to string. Constructs the string with the first count characters of the cstring including null characters. If count is greater than the string capacity the remainder of the characters are truncated. | |
template<uint64_t N> | |
string & | operator= (const char(&rhs)[N]) noexcept |
assigns a char array to string with compile time check if the array size is less than or equal to the string capacity | |
template<uint64_t N> | |
string & | assign (const string< N > &str) noexcept |
fixed string assignment with compile time check if capacity of str is less than or equal to this' capacity | |
template<uint64_t N> | |
string & | assign (const char(&str)[N]) noexcept |
assigns a char array to string with compile time check if the array size is less than or equal to the string capacity | |
bool | unsafe_assign (const char *const str) noexcept |
assigns a cstring to string. The assignment fails if the cstring size is greater than the string capacity. | |
bool | unsafe_assign (const std::string &str) noexcept |
assigns a std::string to string. The assignment fails if the std::string size is greater than the string capacity. | |
template<uint64_t N> | |
int64_t | compare (const string< N > &other) const noexcept |
compares two strings | |
template<uint64_t N> | |
bool | operator== (const string< N > &rhs) const noexcept |
checks if self is equal to rhs | |
template<uint64_t N> | |
bool | operator!= (const string< N > &rhs) const noexcept |
checks if self is not equal to rhs | |
template<uint64_t N> | |
bool | operator< (const string< N > &rhs) const noexcept |
checks if self is less than rhs, in lexicographical order | |
template<uint64_t N> | |
bool | operator<= (const string< N > &rhs) const noexcept |
checks if self is less than or equal to rhs, in lexicographical order | |
template<uint64_t N> | |
bool | operator> (const string< N > &rhs) const noexcept |
checks if self is greater than rhs, in lexicographical order | |
template<uint64_t N> | |
bool | operator>= (const string< N > &rhs) const noexcept |
checks if self is greater than or equal to rhs, in lexicographical order | |
bool | operator== (const char *const rhs) const noexcept |
The equality operator for fixed string and char pointer is disabled via a static_assert, because it may lead to undefined behavior if the char array is not null-terminated. Please convert the char array to a fixed string with string(TruncateToCapacity_t, const char* const other, const uint64_t count) before compare it to a fixed string. | |
bool | operator!= (const char *const rhs) const noexcept |
The inequality operator for fixed string and char pointer is disabled via a static_assert, because it may lead to undefined behavior if the char array is not null-terminated. Please convert the char array to a fixed string with string(TruncateToCapacity_t, const char* const other, const uint64_t count) before compare it to a fixed string. | |
const char * | c_str () const noexcept |
returns a pointer to the char array of self | |
constexpr uint64_t | size () const noexcept |
returns the number of characters stored in the string | |
constexpr bool | empty () const noexcept |
returns if the string is empty or not | |
operator std::string () const noexcept | |
converts the string to a std::string | |
template<typename T > | |
string & | operator+= (const T &) noexcept |
since there are two valid options for what should happen when appending a string larger than this' capacity (failing or truncating), the fixed string does not support operator+=; use append for truncating or unsafe_append for failing in that case | |
template<typename T > | |
std::enable_if< internal::IsCharArray< T >::value||internal::IsCxxString< T >::value, string & >::type | append (TruncateToCapacity_t, const T &t) noexcept |
appends a fixed string or string literal to the end of this. If this' capacity is too small for appending the whole string (literal) the remainder of the characters are truncated. | |
template<typename T > | |
std::enable_if< internal::IsCharArray< T >::value||internal::IsCxxString< T >::value, bool >::type | unsafe_append (const T &t) noexcept |
appends a fixed string or string literal to the end of this. The appending fails if the sum of both sizes is greater than this' capacity. | |
iox::cxx::optional< string< Capacity > > | substr (const uint64_t pos, const uint64_t count) const noexcept |
creates a substring containing the characters from pos until count; if pos+count is greater than the size of the original string the returned substring only contains the characters from pos until size(); iox::cxx::nullopt is returned if pos is greater than the size of the original string; | |
iox::cxx::optional< string< Capacity > > | substr (const uint64_t pos=0U) const noexcept |
creates a substring containing the characters from pos until size(); iox::cxx::nullopt is returned if pos is greater than the size of the original string | |
template<typename T > | |
std::enable_if< std::is_same< T, std::string >::value||internal::IsCharArray< T >::value||internal::IsCxxString< T >::value, iox::cxx::optional< uint64_t > >::type | find (const T &t, const uint64_t pos=0U) const noexcept |
finds the first occurence of the given character sequence; returns the position of the first character of the found substring, returns iox::cxx::nullopt if no substring is found or if pos is greater than this' size | |
template<typename T > | |
std::enable_if< std::is_same< T, std::string >::value||internal::IsCharArray< T >::value||internal::IsCxxString< T >::value, iox::cxx::optional< uint64_t > >::type | find_first_of (const T &t, const uint64_t pos=0U) const noexcept |
finds the first occurence of a character equal to one of the characters of the given character sequence and returns its position; returns iox::cxx::nullopt if no character is found or if pos is greater than this' size | |
template<typename T > | |
std::enable_if< std::is_same< T, std::string >::value||internal::IsCharArray< T >::value||internal::IsCxxString< T >::value, iox::cxx::optional< uint64_t > >::type | find_last_of (const T &t, const uint64_t pos=Capacity) const noexcept |
finds the last occurence of a character equal to one of the characters of the given character sequence and returns its position; returns iox::cxx::nullopt if no character is found | |
Static Public Member Functions | |
static constexpr uint64_t | capacity () noexcept |
returns the maximum number of characters that can be stored in the string | |
Friends | |
template<typename T1 , typename T2 > | |
std::enable_if<(internal::IsCharArray< T1 >::value||internal::IsCxxString< T1 >::value)&&(internal::IsCharArray< T2 >::value||internal::IsCxxString< T2 >::value), string< internal::GetCapa< T1 >::capa+internal::GetCapa< T2 >::capa > >::type | concatenate (const T1 &t1, const T2 &t2) noexcept |
concatenates two fixed strings/string literals | |
string implementation with some adjustments in the API, because we are not allowed to throw exceptions or use heap.
|
noexcept |
copy constructor
[in] | other | is the copy origin |
|
noexcept |
move constructor
[in] | other | is the move origin |
|
noexcept |
creates a new string of given capacity as a copy of other with compile time check whether the capacity of other is less than or equal to this' capacity
[in] | other | is the copy origin |
|
noexcept |
moves other to this with compile time check whether the capacity of other is less than or equal to this' capacity
[in] | other | is the move origin |
|
noexcept |
conversion constructor for char array with compile time check if the array size is less than or equal to the string capacity
N | is the implicit template parameter for the char array size |
[in] | other | is the char array |
|
noexcept |
conversion constructor for cstring to string which truncates characters if the size is greater than the string capacity
[in] | TruncateToCapacity_t | is a compile time variable which is used to distinguish between constructors with certain behavior |
[in] | other | is the cstring to convert |
|
noexcept |
conversion constructor for std::string to string which truncates characters if the std::string size is greater than the string capacity
[in] | TruncateToCapacity_t | is a compile time variable which is used to distinguish between constructors with certain behavior |
[in] | other | is the std::string to convert |
|
noexcept |
constructor from cstring to string. Constructs the string with the first count characters of the cstring including null characters. If count is greater than the string capacity the remainder of the characters are truncated.
[in] | TruncateToCapacity_t | is a compile time variable which is used to distinguish between constructors with certain behavior |
[in] | other | is the cstring to convert |
[in] | count | is the number of characters for constructing the string |
|
noexcept |
appends a fixed string or string literal to the end of this. If this' capacity is too small for appending the whole string (literal) the remainder of the characters are truncated.
[in] | TruncateToCapacity_t | is a compile time variable which is used to make the user aware of the possible truncation |
[in] | t | is the fixed string/string literal to append |
|
noexcept |
assigns a char array to string with compile time check if the array size is less than or equal to the string capacity
[in] | N is the implicit template parameter for the char array size |
[in] | str | is the char array |
|
noexcept |
fixed string assignment with compile time check if capacity of str is less than or equal to this' capacity
[in] | str | is the fixed string object to assign |
|
noexcept |
returns a pointer to the char array of self
|
staticconstexprnoexcept |
returns the maximum number of characters that can be stored in the string
|
noexcept |
compares two strings
[in] | other | is the string to compare with self |
|
constexprnoexcept |
returns if the string is empty or not
|
noexcept |
finds the first occurence of the given character sequence; returns the position of the first character of the found substring, returns iox::cxx::nullopt if no substring is found or if pos is greater than this' size
[in] | t | is the character sequence to search for; must be a cxx::string, string literal or std::string |
[in] | pos | is the position at which to start the search |
|
noexcept |
finds the first occurence of a character equal to one of the characters of the given character sequence and returns its position; returns iox::cxx::nullopt if no character is found or if pos is greater than this' size
[in] | t | is the character sequence to search for; must be a cxx::string, string literal or std::string |
[in] | pos | is the position at which to start the search |
|
noexcept |
finds the last occurence of a character equal to one of the characters of the given character sequence and returns its position; returns iox::cxx::nullopt if no character is found
[in] | t | is the character sequence to search for; must be a cxx::string, string literal or std::string |
[in] | pos | is the position at which to finish the search |
|
noexcept |
converts the string to a std::string
|
noexcept |
The inequality operator for fixed string and char pointer is disabled via a static_assert, because it may lead to undefined behavior if the char array is not null-terminated. Please convert the char array to a fixed string with string(TruncateToCapacity_t, const char* const other, const uint64_t count) before compare it to a fixed string.
[in] | rhs | is the char pointer to the array to compare |
|
noexcept |
checks if self is not equal to rhs
[in] | rhs | is the string to compare with self |
|
noexcept |
checks if self is less than rhs, in lexicographical order
[in] | rhs | is the string to compare with self |
|
noexcept |
checks if self is less than or equal to rhs, in lexicographical order
[in] | rhs | is the string to compare with self |
|
noexcept |
assigns a char array to string with compile time check if the array size is less than or equal to the string capacity
[in] | N is the implicit template parameter for the char array size |
[in] | rhs | is the char array |
|
noexcept |
copy assignment
[in] | rhs | is the copy origin |
|
noexcept |
assigns rhs fixed string to this with compile time check whether the capacity of rhs is less than or equal to this' capacity
[in] | rhs | is the copy origin |
|
noexcept |
move assignment
[in] | rhs | is the move origin |
|
noexcept |
moves rhs fixed string to this with compile time check whether the capacity of rhs is less than or equal to this' capacity
[in] | rhs | is the move origin |
|
noexcept |
The equality operator for fixed string and char pointer is disabled via a static_assert, because it may lead to undefined behavior if the char array is not null-terminated. Please convert the char array to a fixed string with string(TruncateToCapacity_t, const char* const other, const uint64_t count) before compare it to a fixed string.
[in] | rhs | is the char pointer to the array to compare |
|
noexcept |
checks if self is equal to rhs
[in] | rhs | is the string to compare with self |
|
noexcept |
checks if self is greater than rhs, in lexicographical order
[in] | rhs | is the string to compare with self |
|
noexcept |
checks if self is greater than or equal to rhs, in lexicographical order
[in] | rhs | is the string to compare with self |
|
constexprnoexcept |
returns the number of characters stored in the string
|
noexcept |
creates a substring containing the characters from pos until count; if pos+count is greater than the size of the original string the returned substring only contains the characters from pos until size(); iox::cxx::nullopt is returned if pos is greater than the size of the original string;
[in] | pos | is the position of the first character used for the substring |
[in] | count | is the requested length of the substring |
|
noexcept |
creates a substring containing the characters from pos until size(); iox::cxx::nullopt is returned if pos is greater than the size of the original string
[in] | pos | is the position of the first character used for the substring |
|
noexcept |
appends a fixed string or string literal to the end of this. The appending fails if the sum of both sizes is greater than this' capacity.
[in] | fixed | string/string literal to append |
|
noexcept |
assigns a cstring to string. The assignment fails if the cstring size is greater than the string capacity.
[in] | str | is the cstring to assign |
|
noexcept |
assigns a std::string to string. The assignment fails if the std::string size is greater than the string capacity.
[in] | str | is the std::string to assign |
|
friend |
concatenates two fixed strings/string literals
[in] | fixed | strings/string literals to concatenate |