libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions | List of all members
crn::StringUTF8 Class Reference

A character string class. More...

#include <CRNStringUTF8.h>

+ Inheritance diagram for crn::StringUTF8:
+ Collaboration diagram for crn::StringUTF8:

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
 
StringUTF8operator= (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...
 
StringUTF8operator= (const StringUTF8 &s)
 Copies from another string. More...
 
StringUTF8operator+= (const StringUTF8 &s)
 Appends a string. More...
 
StringUTF8Insert (size_t pos, const StringUTF8 &s)
 Inserts a string. More...
 
StringUTF8Crop (size_t pos, size_t n=0)
 Crops the string. More...
 
StringUTF8Erase (size_t pos, size_t n=0)
 Erases a part of the string. More...
 
StringUTF8Replace (const StringUTF8 &s, size_t pos, size_t n=0)
 Replaces a part of the string. More...
 
StringUTF8Replace (char from, char to)
 Replaces all occurrences of a character with another. More...
 
StringUTF8ToUpper ()
 Converts the string to uppercase. More...
 
StringUTF8FirstCharacterToUpper ()
 Converts the first character of string to uppercase. More...
 
StringUTF8ToLower ()
 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...
 
StringUTF8ReplaceSuffix (const StringUTF8 &old_suffix, const StringUTF8 &new_suffix)
 Replaces suffix by another pattern if present. More...
 
std::vector< StringUTF8Split (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...
 
- Public Member Functions inherited from crn::Object
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...
 

Detailed Description

A character string class.

class SStringUTF8 Convenience string class.

Author
Yann LEYDIER
Date
May 2008
Version
0.1

Definition at line 49 of file CRNStringUTF8.h.

Constructor & Destructor Documentation

crn::StringUTF8::StringUTF8 ( )
default

Default constructor (empty string)

virtual crn::StringUTF8::~StringUTF8 ( )
overridevirtualdefault
crn::StringUTF8::StringUTF8 ( const std::string &  s)
inline

Constructor from a std string.

Definition at line 59 of file CRNStringUTF8.h.

crn::StringUTF8::StringUTF8 ( std::string &&  s)
inlinenoexcept

Constructor from a std string.

Definition at line 61 of file CRNStringUTF8.h.

crn::StringUTF8::StringUTF8 ( char *  s)
inline

Constructor from a cstring.

Definition at line 63 of file CRNStringUTF8.h.

crn::StringUTF8::StringUTF8 ( const char *  s)
inline

Constructor from a cstring.

Definition at line 65 of file CRNStringUTF8.h.

crn::StringUTF8::StringUTF8 ( const StringUTF8 s)
inline

Copy constructor.

Definition at line 67 of file CRNStringUTF8.h.

StringUTF8::StringUTF8 ( const String s)
explicit

Constructor from a UTF32 string.

Constructor from a wide string

Parameters
[in]sthe string to convert

Definition at line 67 of file CRNStringUTF8.cpp.

StringUTF8::StringUTF8 ( const Prop3 p)

Constructor from a Prop3.

Constructor from a Prop3

Parameters
[in]pthe 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

Parameters
[in]cthe character to use
[in]nthe number of characters to add

Definition at line 57 of file CRNStringUTF8.cpp.

crn::StringUTF8::StringUTF8 ( int  i)
inline

Constructor from an int.

Definition at line 75 of file CRNStringUTF8.h.

crn::StringUTF8::StringUTF8 ( unsigned int  i)
inline

Constructor from an unsigned int.

Definition at line 77 of file CRNStringUTF8.h.

crn::StringUTF8::StringUTF8 ( long  i)
inline

Constructor from a long.

Definition at line 79 of file CRNStringUTF8.h.

crn::StringUTF8::StringUTF8 ( unsigned long  i)
inline

Constructor from an unsigned long.

Definition at line 81 of file CRNStringUTF8.h.

crn::StringUTF8::StringUTF8 ( float  f)
inline

Constructor from a float.

Definition at line 83 of file CRNStringUTF8.h.

crn::StringUTF8::StringUTF8 ( double  d)
inline

Constructor from a double.

Definition at line 85 of file CRNStringUTF8.h.

crn::StringUTF8::StringUTF8 ( long double  d)
inline

Constructor from a long double.

Definition at line 87 of file CRNStringUTF8.h.

crn::StringUTF8::StringUTF8 ( long long  i)
inline

Constructor from an long.

Definition at line 89 of file CRNStringUTF8.h.

crn::StringUTF8::StringUTF8 ( unsigned long long  i)
inline

Constructor from an unsigned long.

Definition at line 91 of file CRNStringUTF8.h.

template<typename T >
crn::StringUTF8::StringUTF8 ( const std::complex< T > &  c)
inline

Constructor from a complex.

Definition at line 93 of file CRNStringUTF8.h.

crn::StringUTF8::StringUTF8 ( StringUTF8 &&  )
default

Member Function Documentation

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

Exceptions
ExceptionDomainindex out of bounds
Parameters
[in]sthe string to search
[in]last_posthe position of the beginning, NPos for the end.
Returns
the index of the first occurrence, or NPos if not found.

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

Exceptions
ExceptionDomainindex out of bounds
Parameters
[in]sthe list
[in]last_posthe position of the beginning, NPos for the end.
Returns
the index of the first occurrence, or NPos if not found.

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

Exceptions
ExceptionDomainindex out of bounds
Parameters
[in]sthe list
[in]last_posthe position of the beginning, NPos for the end.
Returns
the index of the first occurrence, or NPos if not found.

Definition at line 461 of file CRNStringUTF8.cpp.

StringUTF8 StringUTF8::CreateUniqueId ( size_t  len = 8)
static

Generates an almost unique id.

Generates an almost unique id

Parameters
[in]lenthe length of the string
Returns
an random combination of [0..9], [a..z] and [A..Z]

Definition at line 544 of file CRNStringUTF8.cpp.

StringUTF8 & StringUTF8::Crop ( size_t  pos,
size_t  n = 0 
)

Crops the string.

Crops the string

Parameters
[in]posthe position of the beginning
[in]nthe number of characters to keep. 0 for all remaining characters.
Returns
a reference to the modified string

Definition at line 190 of file CRNStringUTF8.cpp.

const char* crn::StringUTF8::CStr ( ) const
inlinenoexcept

Conversion to UTF8 cstring.

Definition at line 108 of file CRNStringUTF8.h.

void StringUTF8::Deserialize ( xml::Element el)
virtual

Initializes the object from an XML element.

Initializes the object from an XML element. Unsafe.

Exceptions
ExceptionInvalidArgumentnot a StringUTF8
ExceptionDomainno CDATA found
Parameters
[in]elthe 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

Parameters
[in]sthe suffix to be searched
Returns
true if success, false else

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

Exceptions
ExceptionDomainindex out of bounds
Parameters
[in]posthe position of the beginning
[in]nthe number of characters to erase. 0 for all remaining characters.
Returns
a reference to the modified string

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

Exceptions
ExceptionDomainindex out of bounds
Parameters
[in]sthe string to search
[in]from_posthe position of the beginning
Returns
the index of the first occurrence, or NPos if not found.

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

Exceptions
ExceptionDomainindex out of bounds
Parameters
[in]sthe list
[in]from_posthe position of the beginning
Returns
the index of the first occurrence, or NPos if not found.

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

Exceptions
ExceptionDomainindex out of bounds
Parameters
[in]sthe list
[in]from_posthe position of the beginning
Returns
the index of the first occurrence, or NPos if not found.

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.

Returns
a reference to the modified string

Definition at line 272 of file CRNStringUTF8.cpp.

StringUTF8 & StringUTF8::Insert ( size_t  pos,
const StringUTF8 s 
)

Inserts a string.

Inserts a string

Exceptions
ExceptionDomainindex out of bounds
Parameters
[in]posthe position of the insertion. 0 for begining, NPos for end.
[in]sthe string to insert
Returns
a reference to the modified string

Definition at line 138 of file CRNStringUTF8.cpp.

bool crn::StringUTF8::IsEmpty ( ) const
inlinenoexcept

Checks if the string is empty.

Definition at line 146 of file CRNStringUTF8.h.

bool crn::StringUTF8::IsNotEmpty ( ) const
inlinenoexcept

Checks if the string is not empty.

Definition at line 148 of file CRNStringUTF8.h.

size_t StringUTF8::Length ( ) const
noexcept

Returns the number of characters the string.

Returns the number of characters the string (lower or equal to Size())

Returns
the actual number of character (letters, numbers and symbols) in the string

Definition at line 576 of file CRNStringUTF8.cpp.

size_t StringUTF8::NPos ( )
staticnoexcept

Last position in a string.

Last position in a string

Returns
std::string::npos

Definition at line 46 of file CRNStringUTF8.cpp.

bool crn::StringUTF8::operator! ( ) const
inlinenoexcept

Checks if the string is empty.

Definition at line 144 of file CRNStringUTF8.h.

StringUTF8& crn::StringUTF8::operator+= ( const StringUTF8 s)
inline

Appends a string.

Definition at line 159 of file CRNStringUTF8.h.

StringUTF8& crn::StringUTF8::operator= ( StringUTF8 &&  )
default
StringUTF8& crn::StringUTF8::operator= ( const StringUTF8 s)
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

Exceptions
ExceptionDomainindex out of bounds
Parameters
[in]indexthe index of the character in the string
Returns
a reference to the character

Definition at line 93 of file CRNStringUTF8.cpp.

const char & StringUTF8::operator[] ( size_t  index) const

Access to a character.

Access to a character

Exceptions
ExceptionDomainindex out of bounds
Parameters
[in]indexthe index of the character in the string
Returns
a reference to the character

Definition at line 108 of file CRNStringUTF8.cpp.

int & StringUTF8::Precision ( )
staticnoexcept

Precision of the floating point conversion.

Precision of the floating point conversion

Returns
a reference to the configuration variable

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

Exceptions
ExceptionDomainindex out of bounds
Parameters
[in]sthe string to insert
[in]posthe position of the beginning
[in]nthe number of characters to erase. 0 for all remaining characters.
Returns
a reference to the modified string

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

Parameters
[in]fromthe character to replace
[in]tothe replacement character
Returns
a reference to the modified string

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

Exceptions
ExceptionInvalidArgumentnull suffix to search
Parameters
[in]old_suffixthe suffix to be repaced
[in]new_suffixthe new pattern
Returns
a reference to the modified string

Definition at line 599 of file CRNStringUTF8.cpp.

xml::Element StringUTF8::Serialize ( xml::Element parent) const
virtual

Dumps the object to an XML element.

Dumps the object to an XML element. Unsafe.

Parameters
[in]parentthe parent element to which we will add the new element
Returns
The newly created element, nullptr if failed.

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.

size_t crn::StringUTF8::Size ( ) const
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

Parameters
[in]sepa list of separators
Returns
a list of substrings

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

Parameters
[in]sthe prefix to be searched
Returns
true if success, false else

Definition at line 298 of file CRNStringUTF8.cpp.

std::string& crn::StringUTF8::Std ( )
inlinenoexcept

Conversion to std string.

Definition at line 102 of file CRNStringUTF8.h.

const std::string& crn::StringUTF8::Std ( ) const
inlinenoexcept

Conversion to std string.

Definition at line 104 of file CRNStringUTF8.h.

std::string crn::StringUTF8::Std ( )
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

Exceptions
ExceptionDomainindex out of bounds
Parameters
[in]posthe position of the beginning
[in]nthe number of characters to keep. 0 for all remaining characters.
Returns
a reference to the modified string

Definition at line 163 of file CRNStringUTF8.cpp.

void crn::StringUTF8::Swap ( StringUTF8 str)
inlinenoexcept

Swaps two strings.

Definition at line 215 of file CRNStringUTF8.h.

double crn::StringUTF8::ToDouble ( ) const
inline

Conversion to double.

Definition at line 122 of file CRNStringUTF8.h.

float crn::StringUTF8::ToFloat ( ) const
inline

Conversion to float.

Definition at line 120 of file CRNStringUTF8.h.

int crn::StringUTF8::ToInt ( ) const
inline

Conversion to int.

Definition at line 112 of file CRNStringUTF8.h.

int64_t crn::StringUTF8::ToInt64 ( ) const
inline

Conversion to int64_t.

Definition at line 132 of file CRNStringUTF8.h.

long crn::StringUTF8::ToLong ( ) const
inline

Conversion to long.

Definition at line 116 of file CRNStringUTF8.h.

long double crn::StringUTF8::ToLongDouble ( ) const
inline

Conversion to long double.

Definition at line 125 of file CRNStringUTF8.h.

long long crn::StringUTF8::ToLongLong ( ) const
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.

Returns
a reference to the modified string

Definition at line 283 of file CRNStringUTF8.cpp.

Prop3 StringUTF8::ToProp3 ( ) const

Conversion to Prop3.

Conversion to Prop3

Returns
a Prop3

Definition at line 119 of file CRNStringUTF8.cpp.

unsigned int crn::StringUTF8::ToUInt ( ) const
inline

Conversion to unsigned int.

Definition at line 114 of file CRNStringUTF8.h.

uint64_t crn::StringUTF8::ToUInt64 ( ) const
inline

Conversion to uint64_t.

Definition at line 134 of file CRNStringUTF8.h.

unsigned long crn::StringUTF8::ToULong ( ) const
inline

Conversion to unsigned long.

Definition at line 118 of file CRNStringUTF8.h.

unsigned long long crn::StringUTF8::ToULongLong ( ) const
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.

Returns
a reference to the modified string

Definition at line 260 of file CRNStringUTF8.cpp.


The documentation for this class was generated from the following files: