Geogram
Version 1.9.1-rc
A programming library of geometric algorithms
|
Functions for string manipulation. More...
#include <geogram/basic/common.h>
#include <geogram/basic/numeric.h>
#include <string>
#include <sstream>
#include <stdexcept>
#include <iomanip>
#include <vector>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <limits.h>
Go to the source code of this file.
Classes | |
class | GEO::String::ConversionError |
Conversion exception. More... | |
Namespaces | |
GEO | |
Global Vorpaline namespace. | |
Functions | |
void | GEO::String::split_string (const std::string &in, char separator, std::vector< std::string > &out, bool skip_empty_fields=true) |
Splits a string into parts. More... | |
void | GEO::String::split_string (const std::string &in, const std::string &separator, std::vector< std::string > &out, bool skip_empty_fields=true) |
Splits a string into parts. More... | |
bool | GEO::String::split_string (const std::string &in, char separator, std::string &left, std::string &right) |
Splits a string into two parts. More... | |
std::string | GEO::String::join_strings (const std::vector< std::string > &in, char separator) |
Join multiple strings. More... | |
std::string | GEO::String::join_strings (const std::vector< std::string > &in, const std::string &separator) |
Join multiple strings. More... | |
std::string | GEO::String::to_lowercase (const std::string &s) |
Converts a string to lowercase. More... | |
std::string | GEO::String::to_uppercase (const std::string &s) |
Converts a string to uppercase. More... | |
std::string | GEO::String::char_to_string (char c) |
Creates a one char string. More... | |
std::string | GEO::String::quote (const std::string &s, char quotes='\"' ) |
Adds quotes to a string. More... | |
bool | GEO::String::string_starts_with (const std::string &haystack, const std::string &needle) |
Checks if a string starts with a substring. More... | |
bool | GEO::String::string_ends_with (const std::string &haystack, const std::string &needle) |
Checks if a string ends with a substring. More... | |
std::string | GEO::String::format (const char *format,...) |
Creates a string from a format string and additional arguments. Works like sprintf() More... | |
template<class T > | |
std::string | GEO::String::to_string (const T &value) |
Converts a typed value to a string. More... | |
template<class T > | |
std::string | GEO::String::to_display_string (const T &value) |
Converts a typed value to a string for display. More... | |
template<> | |
std::string | GEO::String::to_display_string (const double &value) |
Converts a typed value to a string for display. More... | |
template<> | |
std::string | GEO::String::to_display_string (const float &value) |
Converts a typed value to a string for display. More... | |
template<> | |
std::string | GEO::String::to_string (const bool &value) |
Converts a boolean value to a string. More... | |
template<class T > | |
bool | GEO::String::from_string (const char *s, T &value) |
Converts a C string to a typed value. More... | |
template<class T > | |
bool | GEO::String::from_string (const std::string &s, T &value) |
Converts a std::string to a typed value. More... | |
template<> | |
bool | GEO::String::from_string (const char *s, double &value) |
Converts a string to a double value. More... | |
template<typename T > | |
bool | GEO::String::string_to_signed_integer (const char *s, T &value) |
Converts a string to a signed integer value. More... | |
template<> | |
bool | GEO::String::from_string (const char *s, Numeric::int8 &value) |
Converts a string to a Numeric::int8 value. More... | |
template<> | |
bool | GEO::String::from_string (const char *s, Numeric::int16 &value) |
Converts a string to a Numeric::int16 value. More... | |
template<> | |
bool | GEO::String::from_string (const char *s, Numeric::int32 &value) |
Converts a string to a Numeric::int32 value. More... | |
template<> | |
bool | GEO::String::from_string (const char *s, Numeric::int64 &value) |
Converts a string to a Numeric::int64 value. | |
template<typename T > | |
bool | GEO::String::string_to_unsigned_integer (const char *s, T &value) |
Converts a string to a unsigned integer value. More... | |
template<> | |
bool | GEO::String::from_string (const char *s, Numeric::uint8 &value) |
Converts a string to a Numeric::uint8 value. More... | |
template<> | |
bool | GEO::String::from_string (const char *s, Numeric::uint16 &value) |
Converts a string to a Numeric::uint16 value. More... | |
template<> | |
bool | GEO::String::from_string (const char *s, Numeric::uint32 &value) |
Converts a string to a Numeric::uint32 value. More... | |
template<> | |
bool | GEO::String::from_string (const char *s, Numeric::uint64 &value) |
Converts a string to a Numeric::uint64 value. | |
template<> | |
bool | GEO::String::from_string (const char *s, bool &value) |
Converts a string to a boolean value. More... | |
int | GEO::String::to_int (const std::string &s) |
Converts a string to an int. More... | |
unsigned int | GEO::String::to_uint (const std::string &s) |
Converts a string to an unsigned int. More... | |
double | GEO::String::to_double (const std::string &s) |
Converts a string to a double. More... | |
bool | GEO::String::to_bool (const std::string &s) |
Converts a string to a boolean. More... | |
std::string | GEO::String::wchar_to_UTF8 (const wchar_t *in) |
Converts a wide char string into an UTF8 string. More... | |
Functions for string manipulation.
Definition in file string.h.
|
inline |
std::string GEO::String::format | ( | const char * | format, |
... | |||
) |
Creates a string from a format string and additional arguments. Works like sprintf()
[in] | format | the format string |
|
inline |
Converts a string to a boolean value.
Legal values for the true boolean value are "true","True" and "1". Legal values for the false boolean value are "false","False" and "0".
[in] | s | the source string |
[out] | value | the boolean value |
true | if the conversion was successful |
false | otherwise |
|
inline |
|
inline |
Converts a string to a Numeric::int16 value.
|
inline |
Converts a string to a Numeric::int32 value.
|
inline |
Converts a string to a Numeric::int8 value.
|
inline |
Converts a string to a Numeric::uint16 value.
|
inline |
Converts a string to a Numeric::uint32 value.
|
inline |
Converts a string to a Numeric::uint8 value.
|
inline |
Converts a C string to a typed value.
This is a generic version that uses a std::istringstream to extract the value from the string. This function is specialized for integral types to reach the maximum efficiency.
[in] | s | the source string |
[out] | value | the typed value |
true | if the conversion was successful |
false | otherwise |
|
inline |
Converts a std::string to a typed value.
This is a generic version that uses a std::istringstream to extract the value from the string. This function is specialized for integral types to reach the maximum efficiency.
[in] | s | the source string |
[out] | value | the typed value |
true | if the conversion was successful |
false | otherwise |
std::string GEO::String::join_strings | ( | const std::vector< std::string > & | in, |
char | separator | ||
) |
Join multiple strings.
Joins all the strings in list in
into a single string with each element separated by the given separator
character.
[in] | in | the list of strings to join |
[in] | separator | the separator character |
std::string GEO::String::join_strings | ( | const std::vector< std::string > & | in, |
const std::string & | separator | ||
) |
Join multiple strings.
Joins all the strings in list in
into a single string with each element separated by the given separator
string.
[in] | in | the list of strings to join |
[in] | separator | the separator string (can be an empty string) |
std::string GEO::String::quote | ( | const std::string & | s, |
char | quotes = '\"' |
||
) |
Adds quotes to a string.
Adds character quote
at the beginning and the end of string s
and returns the resulting string.
[in] | s | the string to quote |
[in] | quotes | the quoting char (default is '"') |
bool GEO::String::split_string | ( | const std::string & | in, |
char | separator, | ||
std::string & | left, | ||
std::string & | right | ||
) |
Splits a string into two parts.
[in] | in | the input string to split |
[in] | separator | the separator character |
[in] | left | the part of the input string on the left of the separator or the empty string if the separator did not appear in the input string |
[in] | right | the right of the input string on the left of the separator or the empty string if the separator did not appear in the input string |
true | if the separator was found in the input string |
false | otherwise |
void GEO::String::split_string | ( | const std::string & | in, |
char | separator, | ||
std::vector< std::string > & | out, | ||
bool | skip_empty_fields = true |
||
) |
Splits a string into parts.
Splits the string in
into a list of substrings out
wherever separator
occurs.
[in] | in | the input string to split |
[in] | separator | the separator character |
[in] | out | the resulting list of substrings |
[in] | skip_empty_fields | specifies whether empty parts should be ignored and not stored in list out (this is true by default). |
void GEO::String::split_string | ( | const std::string & | in, |
const std::string & | separator, | ||
std::vector< std::string > & | out, | ||
bool | skip_empty_fields = true |
||
) |
Splits a string into parts.
Splits the string in
into a list of substrings out
wherever separator
occurs.
[in] | in | the input string to split |
[in] | separator | the separator string |
[in] | out | the resulting list of substrings |
[in] | skip_empty_fields | specifies whether empty parts should be ignored and not stored in list out (this is true by default). |
bool GEO::String::string_ends_with | ( | const std::string & | haystack, |
const std::string & | needle | ||
) |
Checks if a string ends with a substring.
[in] | haystack | the input string |
[in] | needle | the substring to check |
true
if haystack
ends with needle
, false
otherwise. bool GEO::String::string_starts_with | ( | const std::string & | haystack, |
const std::string & | needle | ||
) |
Checks if a string starts with a substring.
[in] | haystack | the input string |
[in] | needle | the substring to check |
true
if haystack
starts with needle
, false
otherwise.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
std::string GEO::String::to_lowercase | ( | const std::string & | s | ) |
Converts a string to lowercase.
The conversion is done in place in the string s
.
[in,out] | s | The string to convert |
|
inline |
|
inline |
|
inline |
std::string GEO::String::to_uppercase | ( | const std::string & | s | ) |
Converts a string to uppercase.
The conversion is done in place in the string s
.
[in,out] | s | The string to convert |
std::string GEO::String::wchar_to_UTF8 | ( | const wchar_t * | in | ) |
Converts a wide char string into an UTF8 string.
[in] | in | the input null-terminated wide-char string. |