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::String Class Reference

A UTF32 character string class. More...

#include <CRNString.h>

+ Inheritance diagram for crn::String:
+ Collaboration diagram for crn::String:

Public Member Functions

 String ()=default
 Default constructor (empty string) More...
 
virtual ~String () override=default
 
 String (const std::u32string &s)
 Constructor from a std wide string. More...
 
 String (std::u32string &&s) noexcept
 Constructor from a std wide string. More...
 
 String (char32_t *s)
 Constructor from a wide cstring. More...
 
 String (const char32_t *s)
 Constructor from a wide cstring. More...
 
 String (const String &s)
 Copy constructor. More...
 
 String (char32_t c, size_t n=1)
 Constructor from a wide char. More...
 
 String (const StringUTF8 &s)
 Constructor from a UTF8 string. More...
 
 String (const Prop3 &p)
 Constructor from a Prop3. More...
 
 String (char *s)
 Constructor from a cstring. More...
 
 String (const char *s)
 Constructor from a cstring. More...
 
 String (const std::string &s)
 Constructor from a std string. More...
 
 String (char c, size_t n=1)
 Constructor from a char. More...
 
 String (int i)
 Constructor from an int. More...
 
 String (unsigned int i)
 Constructor from an unsigned int. More...
 
 String (long i)
 Constructor from an long. More...
 
 String (unsigned long i)
 Constructor from an unsigned long. More...
 
 String (float f)
 Constructor from a float. More...
 
 String (double d)
 Constructor from a double. More...
 
 String (long double d)
 Constructor from a long double. More...
 
 String (long long i)
 Constructor from an long. More...
 
 String (unsigned long long i)
 Constructor from an unsigned long. More...
 
template<typename T >
 String (const std::complex< T > &c)
 Constructor from a complex. More...
 
 String (String &&)=default
 
Stringoperator= (String &&)=default
 
std::u32string & Std ()&noexcept
 Conversion to std u32string. More...
 
const std::u32string & Std () const &noexcept
 Conversion to std u32string. More...
 
std::u32string Std ()&&
 Conversion to std u32string. More...
 
const char32_t * CWStr () const noexcept
 Conversion to wide cstring. More...
 
const char * CStr () const
 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 length of the string. More...
 
size_t Length () const noexcept
 Returns the length of 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...
 
char32_t & operator[] (size_t index)
 Access to a character. More...
 
const char32_t & operator[] (size_t index) const
 Access to a character. More...
 
Stringoperator= (const String &s)
 Copies from another string. More...
 
Stringoperator+= (const String &s)
 Appends a string. More...
 
StringInsert (size_t pos, const String &s)
 Inserts a string. More...
 
StringCrop (size_t pos, size_t n=0)
 Crops the string. More...
 
StringErase (size_t pos, size_t n=0)
 Erases a part of the string. More...
 
StringReplace (const String &s, size_t pos, size_t n=0)
 Replaces a part of the string. More...
 
StringReplaceSuffix (const String &old_suffix, const String &new_suffix)
 Replaces suffix by another pattern if present. More...
 
StringReplaceSuffix (const size_t n, const String &new_suffix)
 Replaces last characters of the string by a given pattern. More...
 
StringDeleteSuffix (const String &suffix)
 Delete suffix if found. More...
 
std::vector< StringWhichSuffixes (const std::vector< String > &suffixes) const
 Returns suffixes found within a collection. More...
 
std::vector< StringWhichPrefixes (const std::vector< String > &prefixes) const
 Returns prefixes found within a collection. More...
 
std::vector< StringWhichSubstrings (const std::vector< String > &substrings) const
 Returns substring found within a collection. More...
 
StringReplace (char32_t from, char32_t to)
 Replaces all occurrences of a character with another. More...
 
StringToUpper ()
 Converts the string to uppercase. More...
 
StringFirstCharacterToUpper ()
 Converts the first character of string to uppercase. More...
 
StringToLower ()
 Converts the string to lowercase. More...
 
String SubString (size_t pos, size_t n=0) const
 Extracts a part of the string. More...
 
size_t Find (const String &s, size_t from_pos=0) const
 Finds the first occurrence of a string. More...
 
size_t FindAnyOf (const String &s, size_t from_pos=0) const
 Finds the first occurrence of character in a list. More...
 
size_t FindNotOf (const String &s, size_t from_pos=0) const
 Finds the first occurrence of character not in a list. More...
 
size_t BackwardFind (const String &s, size_t last_pos=NPos()) const
 Finds the last occurrence of a string. More...
 
size_t BackwardFindAnyOf (const String &s, size_t from_pos=NPos()) const
 Finds the last occurrence of character in a list. More...
 
size_t BackwardFindNotOf (const String &s, size_t from_pos=NPos()) const
 Finds the last occurrence of character not in a list. More...
 
bool StartsWith (const String &s) const
 Check if string has a given prefix. More...
 
bool EndsWith (const String &s) const
 Check if string has a given suffix. More...
 
bool EndsWith (const std::vector< String > &suffixes) const
 Check if string has suffix among some given ones. More...
 
std::vector< StringSplit (const String &sep) const
 Splits the string in multiple strings delimited by a set of separators. More...
 
int EditDistance (const String &s) const
 Edit distance. More...
 
void ShrinkToFit ()
 Optimizes the memory usage. More...
 
void Swap (String &str) noexcept
 Swaps two strings. More...
 
void Deserialize (xml::Element &el)
 Initializes the object from an XML element. Unsafe. More...
 
xml::Element Serialize (xml::Element &parent) const
 Dumps the object to an XML element. Unsafe. 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 String CreateUniqueId (size_t len=8)
 Generates an almost unique id. More...
 

Detailed Description

A UTF32 character string class.

class String Convenience UTF32 string class.

Author
Yann LEYDIER
Date
May 2008
Version
0.3

Definition at line 61 of file CRNString.h.

Constructor & Destructor Documentation

crn::String::String ( )
default

Default constructor (empty string)

virtual crn::String::~String ( )
overridevirtualdefault
crn::String::String ( const std::u32string &  s)
inline

Constructor from a std wide string.

Definition at line 71 of file CRNString.h.

crn::String::String ( std::u32string &&  s)
inlinenoexcept

Constructor from a std wide string.

Definition at line 73 of file CRNString.h.

crn::String::String ( char32_t *  s)
inline

Constructor from a wide cstring.

Definition at line 75 of file CRNString.h.

crn::String::String ( const char32_t *  s)
inline

Constructor from a wide cstring.

Definition at line 77 of file CRNString.h.

crn::String::String ( const String s)
inline

Copy constructor.

Definition at line 79 of file CRNString.h.

String::String ( char32_t  c,
size_t  n = 1 
)

Constructor from a wide char.

Constructor from a character

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

Definition at line 58 of file CRNString.cpp.

String::String ( const StringUTF8 s)

Constructor from a UTF8 string.

Constructor from an UTF8 string

Parameters
[in]sthe string to convert

Definition at line 68 of file CRNString.cpp.

String::String ( const Prop3 p)

Constructor from a Prop3.

Constructor from a Prop3

Parameters
[in]pthe Prop3 to convert

Definition at line 77 of file CRNString.cpp.

String::String ( char *  s)

Constructor from a cstring.

Constructor from a cstring

Parameters
[in]sthe string to convert

Definition at line 92 of file CRNString.cpp.

String::String ( const char *  s)

Constructor from a cstring.

Constructor from a cstring

Parameters
[in]sthe string to convert

Definition at line 102 of file CRNString.cpp.

String::String ( const std::string &  s)

Constructor from a std string.

Constructor from a std string

Parameters
[in]sthe string to convert

Definition at line 112 of file CRNString.cpp.

String::String ( 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 123 of file CRNString.cpp.

crn::String::String ( int  i)
inline

Constructor from an int.

Definition at line 95 of file CRNString.h.

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

Constructor from an unsigned int.

Definition at line 97 of file CRNString.h.

crn::String::String ( long  i)
inline

Constructor from an long.

Definition at line 99 of file CRNString.h.

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

Constructor from an unsigned long.

Definition at line 101 of file CRNString.h.

crn::String::String ( float  f)
inline

Constructor from a float.

Definition at line 103 of file CRNString.h.

crn::String::String ( double  d)
inline

Constructor from a double.

Definition at line 105 of file CRNString.h.

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

Constructor from a long double.

Definition at line 107 of file CRNString.h.

crn::String::String ( long long  i)
inline

Constructor from an long.

Definition at line 109 of file CRNString.h.

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

Constructor from an unsigned long.

Definition at line 111 of file CRNString.h.

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

Constructor from a complex.

Definition at line 113 of file CRNString.h.

crn::String::String ( String &&  )
default

Member Function Documentation

size_t String::BackwardFind ( const String 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 651 of file CRNString.cpp.

size_t String::BackwardFindAnyOf ( const String 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 674 of file CRNString.cpp.

size_t String::BackwardFindNotOf ( const String 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 695 of file CRNString.cpp.

crn::String String::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 799 of file CRNString.cpp.

String & String::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 247 of file CRNString.cpp.

const char * String::CStr ( ) const

Conversion to UTF8 cstring.

Conversion to a cstring

Returns
a cstring (do not free!)

Definition at line 167 of file CRNString.cpp.

const char32_t* crn::String::CWStr ( ) const
inlinenoexcept

Conversion to wide cstring.

Definition at line 128 of file CRNString.h.

String & String::DeleteSuffix ( const String suffix)

Delete suffix if found.

Delete suffix if found

Exceptions
ExceptionInvalidArgumentnull suffix to delete
Parameters
[in]suffixthe suffix to be dropped
Returns
a reference to the modified string

Definition at line 354 of file CRNString.cpp.

void String::Deserialize ( xml::Element el)

Initializes the object from an XML element. Unsafe.

Initializes the object from an XML element. Unsafe.

Exceptions
ExceptionInvalidArgumentnot a String
ExceptionDomainno CDATA found
Parameters
[in]elthe XML element to read

Definition at line 738 of file CRNString.cpp.

int String::EditDistance ( const String s) const

Edit distance.

Edit distance

Author
Wikibooks
Parameters
[in]sthe string to compare
Returns
the amount of suppression, addition and change to morph from one string to the other

Definition at line 714 of file CRNString.cpp.

bool String::EndsWith ( const String 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 562 of file CRNString.cpp.

bool String::EndsWith ( const std::vector< String > &  suffixes) const

Check if string has suffix among some given ones.

Check if string ends with a suffix in a given collection

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

Definition at line 587 of file CRNString.cpp.

String & String::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 262 of file CRNString.cpp.

size_t String::Find ( const String 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 509 of file CRNString.cpp.

size_t String::FindAnyOf ( const String 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 611 of file CRNString.cpp.

size_t String::FindNotOf ( const String 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 631 of file CRNString.cpp.

String & String::FirstCharacterToUpper ( )

Converts the first character of string to uppercase.

Converts first character of the string to uppercase.

Returns
a reference to the modified string

Definition at line 481 of file CRNString.cpp.

String & String::Insert ( size_t  pos,
const String 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 195 of file CRNString.cpp.

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

Checks if the string is empty.

Definition at line 166 of file CRNString.h.

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

Checks if the string is not empty.

Definition at line 168 of file CRNString.h.

size_t crn::String::Length ( ) const
inlinenoexcept

Returns the length of the string.

Definition at line 162 of file CRNString.h.

size_t String::NPos ( )
staticnoexcept

Last position in a string.

Last position in a string

Returns
std::string::npos

Definition at line 47 of file CRNString.cpp.

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

Checks if the string is empty.

Definition at line 164 of file CRNString.h.

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

Appends a string.

Definition at line 179 of file CRNString.h.

String& crn::String::operator= ( String &&  )
default
String& crn::String::operator= ( const String s)
inline

Copies from another string.

Definition at line 176 of file CRNString.h.

char32_t & String::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 137 of file CRNString.cpp.

const char32_t & String::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 154 of file CRNString.cpp.

int & String::Precision ( )
staticnoexcept

Precision of the floating point conversion.

Precision of the floating point conversion

Returns
a reference to the configuration variable

Definition at line 38 of file CRNString.cpp.

String & String::Replace ( const String 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 286 of file CRNString.cpp.

String & String::Replace ( char32_t  from,
char32_t  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 456 of file CRNString.cpp.

String & String::ReplaceSuffix ( const String old_suffix,
const String 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 304 of file CRNString.cpp.

String & String::ReplaceSuffix ( const size_t  n,
const String new_suffix 
)

Replaces last characters of the string by a given pattern.

Replaces last characters by a given pattern

Parameters
[in]nthe number of character to erase at the end of the word
[in]new_suffixthe pattern to append
Returns
a reference to the modified string

Definition at line 332 of file CRNString.cpp.

xml::Element String::Serialize ( xml::Element parent) const

Dumps the object to an XML element. Unsafe.

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.

Definition at line 759 of file CRNString.cpp.

void String::ShrinkToFit ( )

Optimizes the memory usage.

Optimizes the memory usage

Definition at line 788 of file CRNString.cpp.

size_t crn::String::Size ( ) const
inlinenoexcept

Returns the length of the string.

Definition at line 160 of file CRNString.h.

std::vector< String > String::Split ( const String 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 772 of file CRNString.cpp.

bool String::StartsWith ( const String 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 533 of file CRNString.cpp.

std::u32string& crn::String::Std ( )
inlinenoexcept

Conversion to std u32string.

Definition at line 122 of file CRNString.h.

const std::u32string& crn::String::Std ( ) const
inlinenoexcept

Conversion to std u32string.

Definition at line 124 of file CRNString.h.

std::u32string crn::String::Std ( )
inline

Conversion to std u32string.

Definition at line 126 of file CRNString.h.

String String::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 new string

Definition at line 220 of file CRNString.cpp.

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

Swaps two strings.

Definition at line 254 of file CRNString.h.

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

Conversion to double.

Definition at line 144 of file CRNString.h.

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

Conversion to float.

Definition at line 142 of file CRNString.h.

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

Conversion to int.

Definition at line 134 of file CRNString.h.

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

Conversion to int64_t.

Definition at line 152 of file CRNString.h.

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

Conversion to long.

Definition at line 138 of file CRNString.h.

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

Conversion to long double.

Definition at line 146 of file CRNString.h.

long long crn::String::ToLongLong ( ) const
inline

Conversion to long long.

Definition at line 148 of file CRNString.h.

String & String::ToLower ( )

Converts the string to lowercase.

Converts the string to lowercase.

Returns
a reference to the modified string

Definition at line 493 of file CRNString.cpp.

Prop3 String::ToProp3 ( ) const

Conversion to Prop3.

Conversion to Prop3

Returns
a Prop3

Definition at line 176 of file CRNString.cpp.

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

Conversion to unsigned int.

Definition at line 136 of file CRNString.h.

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

Conversion to uint64_t.

Definition at line 154 of file CRNString.h.

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

Conversion to unsigned long.

Definition at line 140 of file CRNString.h.

unsigned long long crn::String::ToULongLong ( ) const
inline

Conversion to unsigned long long.

Definition at line 150 of file CRNString.h.

String & String::ToUpper ( )

Converts the string to uppercase.

Converts the string to uppercase.

Returns
a reference to the modified string

Definition at line 469 of file CRNString.cpp.

std::vector< String > String::WhichPrefixes ( const std::vector< String > &  prefixes) const

Returns prefixes found within a collection.

Returns prefix within a collection (void String if not found)

Parameters
[in]prefixescollection of prefixes to try
Returns
a vector of candidates found as prefixes of the string

Definition at line 405 of file CRNString.cpp.

std::vector< String > String::WhichSubstrings ( const std::vector< String > &  substrings) const

Returns substring found within a collection.

Returns substrings within a collection (void String if not found)

Parameters
[in]substringscollection of substrings to try
Returns
a vector of candidates found as subpatterns of the string

Definition at line 430 of file CRNString.cpp.

std::vector< String > String::WhichSuffixes ( const std::vector< String > &  suffixes) const

Returns suffixes found within a collection.

Returns suffix within a collection (void String if not found)

Parameters
[in]suffixescollection of suffixes to try
Returns
a vector of candidates found as suffixes of the string

Definition at line 380 of file CRNString.cpp.


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