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);
346 std::ostringstream out;
360 std::ostringstream out;
373 return value ?
"true" :
"false";
394 const char*
what() const GEO_NOEXCEPT override;
408 inline
bool from_string(const
char* s, T& value) {
409 std::istringstream in(s);
410 return (in >> value) && (in.eof() || ((in >> std::ws) && in.eof()));
439 value = strtod(s, &end);
440 return end != s && *end ==
'\0' && errno == 0;
450 template <
typename T>
460 end != s && *end ==
'\0' && errno == 0 &&
461 v >= std::numeric_limits<T>::min() &&
462 v <= std::numeric_limits<T>::max()
464 value =
static_cast<T
>(v);
506 value = _strtoi64(s, &end, 10);
508 value = strtoll(s, &end, 10);
510 return end != s && *end ==
'\0' && errno == 0;
520 template <
typename T>
530 end != s && *end ==
'\0' && errno == 0 &&
531 v <= std::numeric_limits<T>::max()
533 value =
static_cast<T
>(v);
575 value = _strtoui64(s, &end, 10);
577 value = strtoull(s, &end, 10);
579 return end != s && *end ==
'\0' && errno == 0;
594 if(strcmp(s,
"true") == 0 ||
595 strcmp(s,
"True") == 0 ||
601 if(strcmp(s,
"false") == 0 ||
602 strcmp(s,
"False") == 0 ||
620 inline int to_int(
const std::string& s) {
637 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.