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,
141 const std::string& in,
142 const std::string& separator,
157 const std::vector<std::string>& in,
171 const std::vector<std::string>& in,
172 const std::string& separator
200 return std::string(s);
212 const std::string& s,
char quotes =
'\"'
223 const std::string& haystack,
const std::string& needle
234 const std::string& haystack,
const std::string& needle
245 const std::string& s,
const std::string& prefix
248 return s.substr(prefix.length());
261 const std::string& s,
const std::string& suffix
264 return s.substr(0, s.length() - suffix.length());
275 GEO_NODISCARD
inline std::string
trim_spaces(
const std::string& s) {
276 size_t first = s.find_first_not_of(
' ');
277 if (first == std::string::npos) {
280 size_t last = s.find_last_not_of(
' ');
281 return s.substr(first, (last - first + 1));
289 std::string GEOGRAM_API
format(
const char* format, ...)
291#ifdef GEO_COMPILER_GCC_FAMILY
295 __attribute__ ((__format__(printf, 1, 2)))
306 std::string GEOGRAM_API
format_time(
double seconds,
bool HMS_only=
false);
315 std::ostringstream out;
319 out << std::setprecision(17);
332 inline std::string
to_string(
const unsigned char& value) {
333 std::ostringstream out;
339 inline std::string to_string(
const signed char& value) {
340 std::ostringstream out;
368 std::ostringstream out;
382 std::ostringstream out;
395 return value ?
"true" :
"false";
416 const char*
what() const GEO_NOEXCEPT override;
430 inline
bool from_string(const
char* s, T& value) {
431 std::istringstream in(s);
432 return (in >> value) && (in.eof() || ((in >> std::ws) && in.eof()));
461 value = strtod(s, &end);
462 return end != s && *end ==
'\0' && errno == 0;
472 template <
typename T>
482 end != s && *end ==
'\0' && errno == 0 &&
483 v >= std::numeric_limits<T>::min() &&
484 v <= std::numeric_limits<T>::max()
486 value =
static_cast<T
>(v);
528 value = _strtoi64(s, &end, 10);
530 value = strtoll(s, &end, 10);
532 return end != s && *end ==
'\0' && errno == 0;
542 template <
typename T>
552 end != s && *end ==
'\0' && errno == 0 &&
553 v <= std::numeric_limits<T>::max()
555 value =
static_cast<T
>(v);
597 value = _strtoui64(s, &end, 10);
599 value = strtoull(s, &end, 10);
601 return end != s && *end ==
'\0' && errno == 0;
616 if(strcmp(s,
"true") == 0 ||
617 strcmp(s,
"True") == 0 ||
623 if(strcmp(s,
"false") == 0 ||
624 strcmp(s,
"False") == 0 ||
642 inline int to_int(
const std::string& s) {
659 inline unsigned int to_uint(
const std::string& s) {
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.
Common include file, providing basic definitions. Should be included before anything else by all head...
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.
GEO_NODISCARD std::string remove_suffix(const std::string &s, const std::string &suffix)
Removes a suffix from a string.
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.
GEO_NODISCARD std::string trim_spaces(const std::string &s)
Removes the leading and trailing spaces from a string.
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.
GEO_NODISCARD std::string remove_prefix(const std::string &s, const std::string &prefix)
Removes a prefix from a string.