40#ifndef GEOGRAM_BASIC_STRING
41#define GEOGRAM_BASIC_STRING
82 const std::string& in,
84 std::vector<std::string>& out,
85 bool skip_empty_fields =
true
100 const std::string& in,
101 const std::string& separator,
102 std::vector<std::string>& out,
103 bool skip_empty_fields =
true
120 const std::string& in,
136 const std::vector<std::string>& in,
150 const std::vector<std::string>& in,
151 const std::string& separator
179 return std::string(s);
191 const std::string& s,
char quotes =
'\"'
202 const std::string& haystack,
const std::string& needle
213 const std::string& haystack,
const std::string& needle
221 std::string GEOGRAM_API
format(
const char* format, ...)
223#ifdef GEO_COMPILER_GCC_FAMILY
227 __attribute__ ((__format__(printf, 1, 2)))
238 std::string GEOGRAM_API
format_time(
double seconds,
bool HMS_only=
false);
247 std::ostringstream out;
251 out << std::setprecision(17);
278 std::ostringstream out;
292 std::ostringstream out;
305 return value ?
"true" :
"false";
326 const char*
what() const GEO_NOEXCEPT override;
340 inline
bool from_string(const
char* s, T& value) {
341 std::istringstream in(s);
342 return (in >> value) && (in.eof() || ((in >> std::ws) && in.eof()));
371 value = strtod(s, &end);
372 return end != s && *end ==
'\0' && errno == 0;
382 template <
typename T>
392 end != s && *end ==
'\0' && errno == 0 &&
393 v >= std::numeric_limits<T>::min() &&
394 v <= std::numeric_limits<T>::max()
396 value =
static_cast<T
>(v);
438 value = _strtoi64(s, &end, 10);
440 value = strtoll(s, &end, 10);
442 return end != s && *end ==
'\0' && errno == 0;
452 template <
typename T>
462 end != s && *end ==
'\0' && errno == 0 &&
463 v <= std::numeric_limits<T>::max()
465 value =
static_cast<T
>(v);
507 value = _strtoui64(s, &end, 10);
509 value = strtoull(s, &end, 10);
511 return end != s && *end ==
'\0' && errno == 0;
526 if(strcmp(s,
"true") == 0 ||
527 strcmp(s,
"True") == 0 ||
533 if(strcmp(s,
"false") == 0 ||
534 strcmp(s,
"False") == 0 ||
552 inline int to_int(
const std::string& s) {
569 inline unsigned int to_uint(
const std::string& s) {
Common include file, providing basic definitions. Should be included before anything else by all head...
ConversionError(const std::string &s, const std::string &type)
Constructs a conversion exception.
const char * what() const GEO_NOEXCEPT override
Gets the string identifying the exception.
Global Vorpaline namespace.
Types and functions for numbers manipulation.
Functions for string manipulation.
std::string to_string(const T &value)
Converts a typed value to a string.
bool string_to_unsigned_integer(const char *s, T &value)
Converts a string to a unsigned integer value.
std::string wchar_to_UTF8(const wchar_t *in)
Converts a wide char string into an UTF8 string.
std::string to_uppercase(const std::string &s)
Converts a string to uppercase.
std::string char_to_string(char c)
Creates a one char string.
bool from_string(const char *s, T &value)
Converts a C string to a typed value.
void split_string(const std::string &in, char separator, std::vector< std::string > &out, bool skip_empty_fields=true)
Splits a string into parts.
int to_int(const std::string &s)
Converts a string to an int.
bool string_starts_with(const std::string &haystack, const std::string &needle)
Checks if a string starts with a substring.
bool string_ends_with(const std::string &haystack, const std::string &needle)
Checks if a string ends with a substring.
std::string format(const char *format,...)
Creates a string from a format string and additional arguments. Works like sprintf()
std::string format_time(double seconds, bool HMS_only=false)
Converts a time in seconds into a human-readable string.
std::string join_strings(const std::vector< std::string > &in, char separator)
Join multiple strings.
std::string quote(const std::string &s, char quotes='\"' )
Adds quotes to a string.
unsigned int to_uint(const std::string &s)
Converts a string to an unsigned int.
std::string to_lowercase(const std::string &s)
Converts a string to lowercase.
std::string to_display_string(const T &value)
Converts a typed value to a string for display.
bool to_bool(const std::string &s)
Converts a string to a boolean.
bool string_to_signed_integer(const char *s, T &value)
Converts a string to a signed integer value.
double to_double(const std::string &s)
Converts a string to a double.