|
Geogram Version 1.9.7
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 | |
| namespace | 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. | |
| 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. | |
| bool | GEO::String::split_string (const std::string &in, char separator, std::string &left, std::string &right) |
| Splits a string into two parts. | |
| std::string | GEO::String::join_strings (const std::vector< std::string > &in, char separator) |
| Join multiple strings. | |
| std::string | GEO::String::join_strings (const std::vector< std::string > &in, const std::string &separator) |
| Join multiple strings. | |
| std::string | GEO::String::to_lowercase (const std::string &s) |
| Converts a string to lowercase. | |
| std::string | GEO::String::to_uppercase (const std::string &s) |
| Converts a string to uppercase. | |
| std::string | GEO::String::char_to_string (char c) |
| Creates a one char string. | |
| std::string | GEO::String::quote (const std::string &s, char quotes='\"' ) |
| Adds quotes to a string. | |
| bool | GEO::String::string_starts_with (const std::string &haystack, const std::string &needle) |
| Checks if a string starts with a substring. | |
| bool | GEO::String::string_ends_with (const std::string &haystack, const std::string &needle) |
| Checks if a string ends with a substring. | |
| std::string | GEO::String::format (const char *format,...) |
| Creates a string from a format string and additional arguments. Works like sprintf() | |
| std::string | GEO::String::format_time (double seconds, bool HMS_only=false) |
| Converts a time in seconds into a human-readable string. | |
| template<class T > | |
| std::string | GEO::String::to_string (const T &value) |
| Converts a typed value to a string. | |
| template<class T > | |
| std::string | GEO::String::to_display_string (const T &value) |
| Converts a typed value to a string for display. | |
| template<> | |
| std::string | GEO::String::to_display_string (const double &value) |
| Converts a typed value to a string for display. | |
| template<> | |
| std::string | GEO::String::to_display_string (const float &value) |
| Converts a typed value to a string for display. | |
| template<> | |
| std::string | GEO::String::to_string (const bool &value) |
| Converts a boolean value to a string. | |
| template<class T > | |
| bool | GEO::String::from_string (const char *s, T &value) |
| Converts a C string to a typed value. | |
| template<class T > | |
| bool | GEO::String::from_string (const std::string &s, T &value) |
| Converts a std::string to a typed value. | |
| template<> | |
| bool | GEO::String::from_string (const char *s, double &value) |
| Converts a string to a double value. | |
| template<typename T > | |
| bool | GEO::String::string_to_signed_integer (const char *s, T &value) |
| Converts a string to a signed integer value. | |
| template<> | |
| bool | GEO::String::from_string (const char *s, Numeric::int8 &value) |
| Converts a string to a Numeric::int8 value. | |
| template<> | |
| bool | GEO::String::from_string (const char *s, Numeric::int16 &value) |
| Converts a string to a Numeric::int16 value. | |
| template<> | |
| bool | GEO::String::from_string (const char *s, Numeric::int32 &value) |
| Converts a string to a Numeric::int32 value. | |
| 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. | |
| template<> | |
| bool | GEO::String::from_string (const char *s, Numeric::uint8 &value) |
| Converts a string to a Numeric::uint8 value. | |
| template<> | |
| bool | GEO::String::from_string (const char *s, Numeric::uint16 &value) |
| Converts a string to a Numeric::uint16 value. | |
| template<> | |
| bool | GEO::String::from_string (const char *s, Numeric::uint32 &value) |
| Converts a string to a Numeric::uint32 value. | |
| 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. | |
| int | GEO::String::to_int (const std::string &s) |
| Converts a string to an int. | |
| unsigned int | GEO::String::to_uint (const std::string &s) |
| Converts a string to an unsigned int. | |
| double | GEO::String::to_double (const std::string &s) |
| Converts a string to a double. | |
| bool | GEO::String::to_bool (const std::string &s) |
| Converts a string to a boolean. | |
| std::string | GEO::String::wchar_to_UTF8 (const wchar_t *in) |
| Converts a wide char string into an UTF8 string. | |
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 |
| std::string GEO::String::format_time | ( | double | seconds, |
| bool | HMS_only = false |
||
| ) |
Converts a time in seconds into a human-readable string.
| [in] | HMS_only | if set, always returns a hh:mm:ss string, else returns the time in seconds and a (hh:mm:ss) if time is greater or equal to one minute. |
|
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 |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
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. |