glibmm  2.62.0
About: glibmm is a set of C++ bindings for glib, including cross-platform APIs such as a std::string-like UTF8 string class, string utility methods, such as a text encoding converter API, file access, and threads.
  Fossies Dox: glibmm-2.62.0.tar.xz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

String Utility Functions

This section describes a number of utility functions for creating and manipulating strings, as well as other string-related stuff. More...

Functions

bool Glib::str_has_prefix (const std::string &str, const std::string &prefix)
 Looks whether the string str begins with prefix. More...
 
bool Glib::str_has_suffix (const std::string &str, const std::string &suffix)
 Looks whether the string str ends with suffix. More...
 
double Glib::Ascii::strtod (const std::string &str)
 Converts a string to a double value. More...
 
double Glib::Ascii::strtod (const std::string &str, std::string::size_type &end_index, std::string::size_type start_index=0)
 Converts a string to a double value. More...
 
std::string Glib::Ascii::dtostr (double d)
 Converts a double to a string, using the '. More...
 
std::string Glib::strescape (const std::string &source)
 Escapes all special characters in the string. More...
 
std::string Glib::strescape (const std::string &source, const std::string &exceptions)
 Escapes all special characters in the string. More...
 
std::string Glib::strcompress (const std::string &source)
 Replaces all escaped characters with their one byte equivalent. More...
 
Glib::ustring Glib::strerror (int errnum)
 Returns a string corresponding to the given error code, e.g. "no such process". More...
 
Glib::ustring Glib::strsignal (int signum)
 Returns a string describing the given signal, e.g. "Segmentation fault". More...
 

Detailed Description

This section describes a number of utility functions for creating and manipulating strings, as well as other string-related stuff.

Function Documentation

◆ dtostr()

std::string Glib::Ascii::dtostr ( double  d)

Converts a double to a string, using the '.

' as decimal point.

This functions generates enough precision that converting the string back using Glib::Ascii::strtod() gives the same machine-number (on machines with IEEE compatible 64bit doubles).

Parameters
dThe double value to convert.
Returns
The converted string.

Definition at line 81 of file stringutils.cc.

◆ str_has_prefix()

bool Glib::str_has_prefix ( const std::string &  str,
const std::string &  prefix 
)

Looks whether the string str begins with prefix.

Parameters
strA string.
prefixThe prefix to look for.
Returns
true if str begins with prefix, false otherwise.

Definition at line 25 of file stringutils.cc.

◆ str_has_suffix()

bool Glib::str_has_suffix ( const std::string &  str,
const std::string &  suffix 
)

Looks whether the string str ends with suffix.

Parameters
strA string.
suffixThe suffix to look for.
Returns
true if str ends with suffix, false otherwise.

Definition at line 31 of file stringutils.cc.

◆ strcompress()

std::string Glib::strcompress ( const std::string &  source)

Replaces all escaped characters with their one byte equivalent.

This function does the reverse conversion of Glib::strescape().

Parameters
sourceA string to compress.
Returns
A copy of source with all escaped characters compressed.

Definition at line 103 of file stringutils.cc.

◆ strerror()

Glib::ustring Glib::strerror ( int  errnum)

Returns a string corresponding to the given error code, e.g. "no such process".

This function is included since not all platforms support the strerror() function.

Parameters
errnumThe system error number. See the standard C errno documentation.
Returns
A string describing the error code. If the error code is unknown, "unknown error (<errnum>)" is returned.

Definition at line 110 of file stringutils.cc.

◆ strescape() [1/2]

std::string Glib::strescape ( const std::string &  source)

Escapes all special characters in the string.

Escapes the special characters '\b', '\f', '\n', '\r', '\t', '\' and '"' in the string source by inserting a '\' before them. Additionally all characters in the range 0x01 - 0x1F (everything below SPACE) and in the range 0x80 - 0xFF (all non-ASCII chars) are replaced with a '\' followed by their octal representation.

Glib::strcompress() does the reverse conversion.

Parameters
sourceA string to escape.
Returns
A copy of source with certain characters escaped. See above.

Definition at line 89 of file stringutils.cc.

◆ strescape() [2/2]

std::string Glib::strescape ( const std::string &  source,
const std::string &  exceptions 
)

Escapes all special characters in the string.

Escapes the special characters '\b', '\f', '\n', '\r', '\t', '\' and '"' in the string source by inserting a '\' before them. Additionally all characters in the range 0x01 - 0x1F (everything below SPACE) and in the range 0x80 - 0xFF (all non-ASCII chars) are replaced with a '\' followed by their octal representation. Characters supplied in exceptions are not escaped.

Glib::strcompress() does the reverse conversion.

Parameters
sourceA string to escape.
exceptionsA string of characters not to escape in source.
Returns
A copy of source with certain characters escaped. See above.

Definition at line 96 of file stringutils.cc.

◆ strsignal()

Glib::ustring Glib::strsignal ( int  signum)

Returns a string describing the given signal, e.g. "Segmentation fault".

This function is included since not all platforms support the strsignal() function.

Parameters
signumThe signal number. See the signal() documentation.
Returns
A string describing the signal. If the signal is unknown, "unknown signal (<signum>)" is returned.

Definition at line 116 of file stringutils.cc.

◆ strtod() [1/2]

double Glib::Ascii::strtod ( const std::string &  str)

Converts a string to a double value.

This function behaves like the standard strtod() function does in the C locale. It does this without actually changing the current locale, since that would not be thread-safe.

This function is typically used when reading configuration files or other non-user input that should be locale independent. To handle input from the user you should normally use locale-sensitive C++ streams.

To convert from a string to double in a locale-insensitive way, use Glib::Ascii::dtostr().

Parameters
strThe string to convert to a numeric value.
Returns
The double value.
Exceptions
std::overflow_errorThrown if the correct value would cause overflow.
std::underflow_errorThrown if the correct value would cause underflow.

Definition at line 37 of file stringutils.cc.

◆ strtod() [2/2]

double Glib::Ascii::strtod ( const std::string &  str,
std::string::size_type &  end_index,
std::string::size_type  start_index = 0 
)

Converts a string to a double value.

This function behaves like the standard strtod() function does in the C locale. It does this without actually changing the current locale, since that would not be thread-safe.

This function is typically used when reading configuration files or other non-user input that should be locale independent. To handle input from the user you should normally use locale-sensitive C++ streams.

To convert from a string to double in a locale-insensitive way, use Glib::Ascii::dtostr().

Parameters
strThe string to convert to a numeric value.
start_indexThe index of the first character that should be used in the conversion.
[out]end_indexThe index of the character after the last character used in the conversion.
Returns
The double value.
Exceptions
std::out_of_rangeThrown if start_index is out of range.
std::overflow_errorThrown if the correct value would cause overflow.
std::underflow_errorThrown if the correct value would cause underflow.

Definition at line 44 of file stringutils.cc.