libcrn
3.9.5
A document image processing library
|
A character string class. More...
#include <CRNStringUTF8.h>
Public Member Functions | |
StringUTF8 ()=default | |
Default constructor (empty string) More... | |
virtual | ~StringUTF8 () override=default |
StringUTF8 (const std::string &s) | |
Constructor from a std string. More... | |
StringUTF8 (std::string &&s) noexcept | |
Constructor from a std string. More... | |
StringUTF8 (char *s) | |
Constructor from a cstring. More... | |
StringUTF8 (const char *s) | |
Constructor from a cstring. More... | |
StringUTF8 (const StringUTF8 &s) | |
Copy constructor. More... | |
StringUTF8 (const String &s) | |
Constructor from a UTF32 string. More... | |
StringUTF8 (const Prop3 &p) | |
Constructor from a Prop3. More... | |
StringUTF8 (char c, size_t n=1) | |
Constructor from a char. More... | |
StringUTF8 (int i) | |
Constructor from an int. More... | |
StringUTF8 (unsigned int i) | |
Constructor from an unsigned int. More... | |
StringUTF8 (long i) | |
Constructor from a long. More... | |
StringUTF8 (unsigned long i) | |
Constructor from an unsigned long. More... | |
StringUTF8 (float f) | |
Constructor from a float. More... | |
StringUTF8 (double d) | |
Constructor from a double. More... | |
StringUTF8 (long double d) | |
Constructor from a long double. More... | |
StringUTF8 (long long i) | |
Constructor from an long. More... | |
StringUTF8 (unsigned long long i) | |
Constructor from an unsigned long. More... | |
template<typename T > | |
StringUTF8 (const std::complex< T > &c) | |
Constructor from a complex. More... | |
StringUTF8 (StringUTF8 &&)=default | |
StringUTF8 & | operator= (StringUTF8 &&)=default |
std::string & | Std ()&noexcept |
Conversion to std string. More... | |
const std::string & | Std () const &noexcept |
Conversion to std string. More... | |
std::string | Std ()&& |
Conversion to std string. More... | |
const char * | CStr () const noexcept |
Conversion to UTF8 cstring. More... | |
Prop3 | ToProp3 () const |
Conversion to Prop3. More... | |
int | ToInt () const |
Conversion to int. More... | |
unsigned int | ToUInt () const |
Conversion to unsigned int. More... | |
long | ToLong () const |
Conversion to long. More... | |
unsigned long | ToULong () const |
Conversion to unsigned long. More... | |
float | ToFloat () const |
Conversion to float. More... | |
double | ToDouble () const |
Conversion to double. More... | |
long double | ToLongDouble () const |
Conversion to long double. More... | |
long long | ToLongLong () const |
Conversion to long long. More... | |
unsigned long long | ToULongLong () const |
Conversion to unsigned long long. More... | |
int64_t | ToInt64 () const |
Conversion to int64_t. More... | |
uint64_t | ToUInt64 () const |
Conversion to uint64_t. More... | |
size_t | Size () const noexcept |
Returns the number of bytes in the string. More... | |
size_t | Length () const noexcept |
Returns the number of characters the string. More... | |
bool | operator! () const noexcept |
Checks if the string is empty. More... | |
bool | IsEmpty () const noexcept |
Checks if the string is empty. More... | |
bool | IsNotEmpty () const noexcept |
Checks if the string is not empty. More... | |
char & | operator[] (size_t index) |
Access to a character. More... | |
const char & | operator[] (size_t index) const |
Access to a character. More... | |
StringUTF8 & | operator= (const StringUTF8 &s) |
Copies from another string. More... | |
StringUTF8 & | operator+= (const StringUTF8 &s) |
Appends a string. More... | |
StringUTF8 & | Insert (size_t pos, const StringUTF8 &s) |
Inserts a string. More... | |
StringUTF8 & | Crop (size_t pos, size_t n=0) |
Crops the string. More... | |
StringUTF8 & | Erase (size_t pos, size_t n=0) |
Erases a part of the string. More... | |
StringUTF8 & | Replace (const StringUTF8 &s, size_t pos, size_t n=0) |
Replaces a part of the string. More... | |
StringUTF8 & | Replace (char from, char to) |
Replaces all occurrences of a character with another. More... | |
StringUTF8 & | ToUpper () |
Converts the string to uppercase. More... | |
StringUTF8 & | FirstCharacterToUpper () |
Converts the first character of string to uppercase. More... | |
StringUTF8 & | ToLower () |
Converts the string to lowercase. More... | |
StringUTF8 | SubString (size_t pos, size_t n=0) const |
Extracts a part of the string. More... | |
bool | StartsWith (const StringUTF8 &s) const |
Check if string has a given prefix. More... | |
bool | EndsWith (const StringUTF8 &s) const |
Check if string has a given suffix. More... | |
size_t | Find (const StringUTF8 &s, size_t from_pos=0) const |
Finds the first occurrence of a string. More... | |
size_t | FindAnyOf (const StringUTF8 &s, size_t from_pos=0) const |
Finds the first occurrence of character in a list. More... | |
size_t | FindNotOf (const StringUTF8 &s, size_t from_pos=0) const |
Finds the first occurrence of character not in a list. More... | |
size_t | BackwardFind (const StringUTF8 &s, size_t last_pos=NPos()) const |
Finds the last occurrence of a string. More... | |
size_t | BackwardFindAnyOf (const StringUTF8 &s, size_t from_pos=NPos()) const |
Finds the last occurrence of character in a list. More... | |
size_t | BackwardFindNotOf (const StringUTF8 &s, size_t from_pos=NPos()) const |
Finds the last occurrence of character not in a list. More... | |
StringUTF8 & | ReplaceSuffix (const StringUTF8 &old_suffix, const StringUTF8 &new_suffix) |
Replaces suffix by another pattern if present. More... | |
std::vector< StringUTF8 > | Split (const StringUTF8 &sep) const |
Splits the string in multiple strings delimited by a set of separators. More... | |
void | ShrinkToFit () |
Optimizes the memory usage. More... | |
void | Swap (StringUTF8 &str) noexcept |
Swaps two strings. More... | |
virtual void | Deserialize (xml::Element &el) |
Initializes the object from an XML element. More... | |
virtual xml::Element | Serialize (xml::Element &parent) const |
Dumps the object to an XML element. More... | |
![]() | |
virtual | ~Object ()=default |
Static Public Member Functions | |
static int & | Precision () noexcept |
Precision of the floating point conversion. More... | |
static size_t | NPos () noexcept |
Last position in a string. More... | |
static crn::StringUTF8 | CreateUniqueId (size_t len=8) |
Generates an almost unique id. More... | |
A character string class.
class SStringUTF8 Convenience string class.
Definition at line 49 of file CRNStringUTF8.h.
|
default |
Default constructor (empty string)
|
overridevirtualdefault |
|
inline |
Constructor from a std string.
Definition at line 59 of file CRNStringUTF8.h.
|
inlinenoexcept |
Constructor from a std string.
Definition at line 61 of file CRNStringUTF8.h.
|
inline |
Constructor from a cstring.
Definition at line 63 of file CRNStringUTF8.h.
|
inline |
Constructor from a cstring.
Definition at line 65 of file CRNStringUTF8.h.
|
inline |
Copy constructor.
Definition at line 67 of file CRNStringUTF8.h.
|
explicit |
Constructor from a UTF32 string.
Constructor from a wide string
[in] | s | the string to convert |
Definition at line 67 of file CRNStringUTF8.cpp.
StringUTF8::StringUTF8 | ( | const Prop3 & | p | ) |
Constructor from a Prop3.
Constructor from a Prop3
[in] | p | the Prop3 to convert |
Definition at line 76 of file CRNStringUTF8.cpp.
StringUTF8::StringUTF8 | ( | char | c, |
size_t | n = 1 |
||
) |
Constructor from a char.
Constructor from a character
[in] | c | the character to use |
[in] | n | the number of characters to add |
Definition at line 57 of file CRNStringUTF8.cpp.
|
inline |
Constructor from an int.
Definition at line 75 of file CRNStringUTF8.h.
|
inline |
Constructor from an unsigned int.
Definition at line 77 of file CRNStringUTF8.h.
|
inline |
Constructor from a long.
Definition at line 79 of file CRNStringUTF8.h.
|
inline |
Constructor from an unsigned long.
Definition at line 81 of file CRNStringUTF8.h.
|
inline |
Constructor from a float.
Definition at line 83 of file CRNStringUTF8.h.
|
inline |
Constructor from a double.
Definition at line 85 of file CRNStringUTF8.h.
|
inline |
Constructor from a long double.
Definition at line 87 of file CRNStringUTF8.h.
|
inline |
Constructor from an long.
Definition at line 89 of file CRNStringUTF8.h.
|
inline |
Constructor from an unsigned long.
Definition at line 91 of file CRNStringUTF8.h.
|
inline |
Constructor from a complex.
Definition at line 93 of file CRNStringUTF8.h.
|
default |
size_t StringUTF8::BackwardFind | ( | const StringUTF8 & | s, |
size_t | last_pos = NPos() |
||
) | const |
Finds the last occurrence of a string.
Finds the last occurrence of a string
ExceptionDomain | index out of bounds |
[in] | s | the string to search |
[in] | last_pos | the position of the beginning, NPos for the end. |
Definition at line 417 of file CRNStringUTF8.cpp.
size_t StringUTF8::BackwardFindAnyOf | ( | const StringUTF8 & | s, |
size_t | last_pos = NPos() |
||
) | const |
Finds the last occurrence of character in a list.
Finds the last occurrence of a character in a list
ExceptionDomain | index out of bounds |
[in] | s | the list |
[in] | last_pos | the position of the beginning, NPos for the end. |
Definition at line 440 of file CRNStringUTF8.cpp.
size_t StringUTF8::BackwardFindNotOf | ( | const StringUTF8 & | s, |
size_t | last_pos = NPos() |
||
) | const |
Finds the last occurrence of character not in a list.
Finds the last occurrence of a character not in a list
ExceptionDomain | index out of bounds |
[in] | s | the list |
[in] | last_pos | the position of the beginning, NPos for the end. |
Definition at line 461 of file CRNStringUTF8.cpp.
|
static |
Generates an almost unique id.
Generates an almost unique id
[in] | len | the length of the string |
Definition at line 544 of file CRNStringUTF8.cpp.
StringUTF8 & StringUTF8::Crop | ( | size_t | pos, |
size_t | n = 0 |
||
) |
Crops the string.
Crops the string
[in] | pos | the position of the beginning |
[in] | n | the number of characters to keep. 0 for all remaining characters. |
Definition at line 190 of file CRNStringUTF8.cpp.
|
inlinenoexcept |
Conversion to UTF8 cstring.
Definition at line 108 of file CRNStringUTF8.h.
|
virtual |
Initializes the object from an XML element.
Initializes the object from an XML element. Unsafe.
ExceptionInvalidArgument | not a StringUTF8 |
ExceptionDomain | no CDATA found |
[in] | el | the XML element to read |
Reimplemented in crn::Path.
Definition at line 483 of file CRNStringUTF8.cpp.
bool StringUTF8::EndsWith | ( | const StringUTF8 & | s | ) | const |
Check if string has a given suffix.
Check if string ends with a certain suffix
[in] | s | the suffix to be searched |
Definition at line 327 of file CRNStringUTF8.cpp.
StringUTF8 & StringUTF8::Erase | ( | size_t | pos, |
size_t | n = 0 |
||
) |
Erases a part of the string.
Erases a part of the string
ExceptionDomain | index out of bounds |
[in] | pos | the position of the beginning |
[in] | n | the number of characters to erase. 0 for all remaining characters. |
Definition at line 205 of file CRNStringUTF8.cpp.
size_t StringUTF8::Find | ( | const StringUTF8 & | s, |
size_t | from_pos = 0 |
||
) | const |
Finds the first occurrence of a string.
Finds the first occurrence of a string
ExceptionDomain | index out of bounds |
[in] | s | the string to search |
[in] | from_pos | the position of the beginning |
Definition at line 356 of file CRNStringUTF8.cpp.
size_t StringUTF8::FindAnyOf | ( | const StringUTF8 & | s, |
size_t | from_pos = 0 |
||
) | const |
Finds the first occurrence of character in a list.
Finds the first occurrence of a character in a list
ExceptionDomain | index out of bounds |
[in] | s | the list |
[in] | from_pos | the position of the beginning |
Definition at line 379 of file CRNStringUTF8.cpp.
size_t StringUTF8::FindNotOf | ( | const StringUTF8 & | s, |
size_t | from_pos = 0 |
||
) | const |
Finds the first occurrence of character not in a list.
Finds the first occurrence of a character not in a list
ExceptionDomain | index out of bounds |
[in] | s | the list |
[in] | from_pos | the position of the beginning |
Definition at line 398 of file CRNStringUTF8.cpp.
StringUTF8 & StringUTF8::FirstCharacterToUpper | ( | ) |
Converts the first character of string to uppercase.
Converts the first character of string to uppercase.
Definition at line 272 of file CRNStringUTF8.cpp.
StringUTF8 & StringUTF8::Insert | ( | size_t | pos, |
const StringUTF8 & | s | ||
) |
Inserts a string.
Inserts a string
ExceptionDomain | index out of bounds |
[in] | pos | the position of the insertion. 0 for begining, NPos for end. |
[in] | s | the string to insert |
Definition at line 138 of file CRNStringUTF8.cpp.
|
inlinenoexcept |
Checks if the string is empty.
Definition at line 146 of file CRNStringUTF8.h.
|
inlinenoexcept |
Checks if the string is not empty.
Definition at line 148 of file CRNStringUTF8.h.
|
noexcept |
Returns the number of characters the string.
Returns the number of characters the string (lower or equal to Size())
Definition at line 576 of file CRNStringUTF8.cpp.
|
staticnoexcept |
Last position in a string.
Last position in a string
Definition at line 46 of file CRNStringUTF8.cpp.
|
inlinenoexcept |
Checks if the string is empty.
Definition at line 144 of file CRNStringUTF8.h.
|
inline |
Appends a string.
Definition at line 159 of file CRNStringUTF8.h.
|
default |
|
inline |
Copies from another string.
Definition at line 156 of file CRNStringUTF8.h.
char & StringUTF8::operator[] | ( | size_t | index | ) |
Access to a character.
Access to a character
ExceptionDomain | index out of bounds |
[in] | index | the index of the character in the string |
Definition at line 93 of file CRNStringUTF8.cpp.
const char & StringUTF8::operator[] | ( | size_t | index | ) | const |
Access to a character.
Access to a character
ExceptionDomain | index out of bounds |
[in] | index | the index of the character in the string |
Definition at line 108 of file CRNStringUTF8.cpp.
|
staticnoexcept |
Precision of the floating point conversion.
Precision of the floating point conversion
Definition at line 37 of file CRNStringUTF8.cpp.
StringUTF8 & StringUTF8::Replace | ( | const StringUTF8 & | s, |
size_t | pos, | ||
size_t | n = 0 |
||
) |
Replaces a part of the string.
Replaces a part of the string
ExceptionDomain | index out of bounds |
[in] | s | the string to insert |
[in] | pos | the position of the beginning |
[in] | n | the number of characters to erase. 0 for all remaining characters. |
Definition at line 229 of file CRNStringUTF8.cpp.
StringUTF8 & StringUTF8::Replace | ( | char | from, |
char | to | ||
) |
Replaces all occurrences of a character with another.
Replaces all occurrences of a character with another
[in] | from | the character to replace |
[in] | to | the replacement character |
Definition at line 247 of file CRNStringUTF8.cpp.
StringUTF8 & StringUTF8::ReplaceSuffix | ( | const StringUTF8 & | old_suffix, |
const StringUTF8 & | new_suffix | ||
) |
Replaces suffix by another pattern if present.
Replaces suffix by another pattern if present
ExceptionInvalidArgument | null suffix to search |
[in] | old_suffix | the suffix to be repaced |
[in] | new_suffix | the new pattern |
Definition at line 599 of file CRNStringUTF8.cpp.
|
virtual |
Dumps the object to an XML element.
Dumps the object to an XML element. Unsafe.
[in] | parent | the parent element to which we will add the new element |
Reimplemented in crn::Path.
Definition at line 504 of file CRNStringUTF8.cpp.
void StringUTF8::ShrinkToFit | ( | ) |
Optimizes the memory usage.
Optimizes the memory usage
Definition at line 533 of file CRNStringUTF8.cpp.
|
inlinenoexcept |
Returns the number of bytes in the string.
Definition at line 140 of file CRNStringUTF8.h.
std::vector< StringUTF8 > StringUTF8::Split | ( | const StringUTF8 & | sep | ) | const |
Splits the string in multiple strings delimited by a set of separators.
Splits the string in multiple strings delimited by a set of separators
[in] | sep | a list of separators |
Definition at line 517 of file CRNStringUTF8.cpp.
bool StringUTF8::StartsWith | ( | const StringUTF8 & | s | ) | const |
Check if string has a given prefix.
Check if string begins with a certain prefix
[in] | s | the prefix to be searched |
Definition at line 298 of file CRNStringUTF8.cpp.
|
inlinenoexcept |
Conversion to std string.
Definition at line 102 of file CRNStringUTF8.h.
|
inlinenoexcept |
Conversion to std string.
Definition at line 104 of file CRNStringUTF8.h.
|
inline |
Conversion to std string.
Definition at line 106 of file CRNStringUTF8.h.
StringUTF8 StringUTF8::SubString | ( | size_t | pos, |
size_t | n = 0 |
||
) | const |
Extracts a part of the string.
Extracts a part of the string
ExceptionDomain | index out of bounds |
[in] | pos | the position of the beginning |
[in] | n | the number of characters to keep. 0 for all remaining characters. |
Definition at line 163 of file CRNStringUTF8.cpp.
|
inlinenoexcept |
Swaps two strings.
Definition at line 215 of file CRNStringUTF8.h.
|
inline |
Conversion to double.
Definition at line 122 of file CRNStringUTF8.h.
|
inline |
Conversion to float.
Definition at line 120 of file CRNStringUTF8.h.
|
inline |
Conversion to int.
Definition at line 112 of file CRNStringUTF8.h.
|
inline |
Conversion to int64_t.
Definition at line 132 of file CRNStringUTF8.h.
|
inline |
Conversion to long.
Definition at line 116 of file CRNStringUTF8.h.
|
inline |
Conversion to long double.
Definition at line 125 of file CRNStringUTF8.h.
|
inline |
Conversion to long long.
Definition at line 128 of file CRNStringUTF8.h.
StringUTF8 & StringUTF8::ToLower | ( | ) |
Converts the string to lowercase.
Converts the string to lowercase.
Definition at line 283 of file CRNStringUTF8.cpp.
Prop3 StringUTF8::ToProp3 | ( | ) | const |
Conversion to Prop3.
Conversion to Prop3
Definition at line 119 of file CRNStringUTF8.cpp.
|
inline |
Conversion to unsigned int.
Definition at line 114 of file CRNStringUTF8.h.
|
inline |
Conversion to uint64_t.
Definition at line 134 of file CRNStringUTF8.h.
|
inline |
Conversion to unsigned long.
Definition at line 118 of file CRNStringUTF8.h.
|
inline |
Conversion to unsigned long long.
Definition at line 130 of file CRNStringUTF8.h.
StringUTF8 & StringUTF8::ToUpper | ( | ) |
Converts the string to uppercase.
Converts the string to uppercase.
Definition at line 260 of file CRNStringUTF8.cpp.