10#include <kernel/util/half.hpp>
21#ifdef FEAT_COMPILER_MICROSOFT
26#ifdef FEAT_HAVE_QUADMATH
75 return left.compare_no_case(right) < 0;
93 inline String(
const char* str, size_type count)
94 : std::string(str, count)
99 inline String(
const std::string& str)
127 inline String(
const std::string& str, size_type offset, size_type count = npos)
128 : std::string(str, offset, count)
134 : std::string(count, c)
139 String& operator=(
const std::string& str)
141 std::string::operator=(str);
146 String& operator=(std::string&& str)
148 std::string::operator=(str);
155 std::string::operator=(str);
162 std::string::operator=(str);
167 String& operator=(
const char* s)
169 std::string::operator=(s);
173 String& append(
const std::string& str)
175 std::string::append(str);
179 String& append(
const std::string& str, size_type pos, size_type n)
181 std::string::append(str, pos, n);
185 String& append(
const char* s, size_type n)
187 std::string::append(s, n);
191 String& append(
const char* s)
193 std::string::append(s);
197 String& append(size_type n,
char c)
199 std::string::append(n, c);
203 String& operator+=(
const std::string& str)
208 String& operator+=(
const char* s)
213 String substr(size_type pos = size_type(0), size_type n = npos)
const
215 return String(std::string::substr(pos, n));
224 return " \a\b\f\n\r\t\v";
235 insert(size_type(0), size_type(1),
value);
241 erase(size_type(0), size_type(1));
247 erase(size() - size_type(1), size_type(1));
264 size_type pos = find_first_not_of(charset);
296 size_type pos = find_last_not_of(charset);
300 return substr(size_type(0), pos + size_type(1));
360 return (*
this =
trim(charset));
372 return (*
this =
trim());
394 size_type l(length());
395 return (l < len) ?
String(len - l, c).append(*
this) : *
this;
417 size_type l(length());
418 return (l < len) ?
String(*this).append(len - l, c) : *
this;
432 return length() <= len ? *this : substr(length() - len);
446 return length() <= len ? *this : substr(size_type(0), len);
469 std::deque<String> words;
470 if(empty() || charset.empty())
476 size_type off1(find_first_not_of(charset));
487 size_type off2(find_first_of(charset, off1));
493 words.push_back(substr(off1));
499 words.push_back(substr(off1, (off2 == npos ? npos : off2 - off1)));
503 off1 = find_first_not_of(charset, off2);
541 std::deque<String> words;
542 if(empty() || delimiter.empty())
546 size_type off1(find(delimiter));
547 words.push_back(substr(0, off1));
552 const size_type del_len(delimiter.size());
559 size_type off2 = find(delimiter, off1);
563 words.push_back(substr(off1));
569 words.push_back(substr(off1, off2 - off1));
600 size_type flen(find_string.size());
601 size_type rlen(replace_string.size());
606 size_type pos(find(find_string));
607 size_type counter(size_type(0));
611 replace(pos, flen, replace_string);
617 pos = find(find_string, pos + rlen);
634 for(const_iterator it(begin()); it != end(); ++it)
636#ifdef FEAT_COMPILER_MICROSOFT
637 str.push_back(std::toupper(*it, std::locale::classic()));
640 str.push_back(std::toupper<char>(*it, loc));
656 for(const_iterator it(begin()); it != end(); ++it)
658#ifdef FEAT_COMPILER_MICROSOFT
659 str.push_back(std::tolower(*it, std::locale::classic()));
662 str.push_back(std::tolower<char>(*it, loc));
681#ifdef FEAT_COMPILER_MICROSOFT
683 return _stricmp(c_str(), other.c_str());
687 size_type n1 = size();
688 size_type n2 = other.size();
689 size_type n = std::min(n1, n2);
692 for(size_type i = 0; i < n; ++i)
694 int k = int(std::tolower<char>((*
this)[i], loc)) - int(std::tolower<char>(other[i], loc));
738 if(this->size() < head.size())
742 return (this->compare(std::size_t(0), head.size(), head) == 0);
761 if(this->size() < tail.size())
765 return (this->compare(this->size() - tail.size(), tail.size(), tail) == 0);
779 return (this->empty() ?
false : this->front() == head);
793 return (this->empty() ?
false : this->back() == tail);
814 for(
const auto& s : sset)
821 else if(this->compare(s) == 0)
836 template<
typename T_>
839 std::istringstream iss(
trim());
845 bool parse(
bool& b)
const
860 bool parse(std::string& s)
const
874 #ifdef FEAT_HAVE_HALFMATH
878 bool ret =
parse(tmp);
879 t = __float2half(tmp);
885#ifdef FEAT_HAVE_QUADMATH
886 bool parse(__float128& x)
const
891 const char* nptr(this->c_str());
892 char* endptr(
nullptr);
893 x = strtoflt128(nptr, &endptr);
897 return (nptr != endptr);
907 return String(a).append(b);
912 return String(a).append(b);
917 return String(a).append(b);
922 return String(a).append(String::size_type(1), c);
927 return String(String::size_type(1), c).append(b);
943 template<
typename T_>
946 std::ostringstream oss;
969 return String(item ?
"true" :
"false");
972#ifdef FEAT_HAVE_HALFMATH
985#ifdef FEAT_HAVE_QUADMATH
989 int len = ::quadmath_snprintf(
nullptr, 0,
"%Qg",
value);
991 std::vector<char> buffer(len+16);
993 quadmath_snprintf(buffer.data(), buffer.size(),
"%Qg",
value);
995 return String(buffer.data());
1016 template<
typename Iterator_>
1020 const String & delimiter =
"")
1025 Iterator_ it(first);
1028 for(++it; it != last; ++it)
1029 str.append(delimiter).append(
stringify(*it));
1049 template<
typename Container_>
1051 const Container_& container,
1052 const String & delimiter =
"")
1054 return stringify_join(container.cbegin(), container.cend(), delimiter);
1087 template<
typename DataType_>
1090 std::ostringstream oss;
1091 oss << std::scientific;
1093 oss << std::setprecision(precision);
1095 oss << std::setw(width);
1097 oss << std::showpos;
1102 #ifdef FEAT_HAVE_HALFMATH
1141 template<
typename DataType_>
1144 std::ostringstream oss;
1147 oss << std::setprecision(precision);
1149 oss << std::setw(width);
1151 oss << std::showpos;
1156 #ifdef FEAT_HAVE_HALFMATH
1166#ifdef FEAT_HAVE_QUADMATH
1179 format.append(
"Qe");
1181 int len = ::quadmath_snprintf(
nullptr, 0, format.c_str(),
value);
1183 std::vector<char> buffer(len+16);
1185 quadmath_snprintf(buffer.data(), buffer.size(), format.c_str(),
value);
1187 return String(buffer.data());
1202 format.append(
"Qf");
1204 int len = ::quadmath_snprintf(
nullptr, 0, format.c_str(),
value);
1206 std::vector<char> buffer(len+16);
1208 quadmath_snprintf(buffer.data(), buffer.size(), format.c_str(),
value);
1210 return String(buffer.data());
1213 inline std::istream&
operator>>(std::istream& is, __float128& x)
1217 if(!(is >> buffer).fail())
1219 if(!buffer.parse(x))
1222 for(std::size_t i(0); i < buffer.size(); ++i)
1223 is.putback(buffer.at(i));
1226 is.setstate(std::ios_base::failbit);
1266 else if(bytes <= 1'022'976ull)
1267 return stringify_fp_fix(
double(bytes) / (1024.), precision, width) +
" KiB";
1268 else if(bytes <= 1'047'527'424ull)
1269 return stringify_fp_fix(
double(bytes) / (1048576.), precision, width) +
" MiB";
1270 else if(bytes <= 1'072'668'082'176ull)
1271 return stringify_fp_fix(
double(bytes) / (1073741824.), precision, width) +
" GiB";
1272 else if(bytes <= 1'098'412'116'148'224ull)
1273 return stringify_fp_fix(
double(bytes) / (1099511627776.), precision, width) +
" TiB";
1275 return stringify_fp_fix(
double(bytes) / (1125899906842624.), precision, width) +
" PiB";
1282#ifdef FEAT_HAVE_QUADMATH
1285 inline std::ostream& operator<<(std::ostream& os, __float128 x)
A class providing case-insensitive String comparison.
bool operator()(const String &left, const String &right) const
Compares two Strings without regard to case.
String class implementation.
String trunc_front(size_type len) const
Truncates the front of the string to a given maximum length.
void pop_front()
Removes the first character from the string.
String trim() const
Trims the string of all white-spaces.
bool parse(T_ &t) const
Parses the string and stores its value in the provided variable.
String trim_back(const String &charset) const
Trims the back of the string.
String & trim_me()
Trims this string of all white-spaces.
std::deque< String > split_by_string(const String &delimiter) const
Splits the string by a delimiter substring.
String trim_front() const
Trims the front of the string of all white-spaces.
String trim_back() const
Trims the back of the string of all white-spaces.
String trunc_back(size_type len) const
Truncates the back of the string to a given maximum length.
String(std::string &&str)
CTOR.
String(const String &str)
copy CTOR
static const char * whitespaces()
Returns a null-terminated char string containing all white-space characters.
String(const char *str, size_type count)
CTOR.
std::deque< String > split_by_whitespaces() const
Splits the string by white-spaces.
int compare_no_case(const String &other) const
Compares two strings without regard to case.
bool ends_with(const char tail) const
Checks whether this string ends with a specified character.
String trim_front(const String &charset) const
Trims the front of the string.
bool starts_with(const char head) const
Checks whether this string starts with a specified character.
String pad_back(size_type len, char c=' ') const
Pads the back of the string up to a desired length.
bool ends_with(const String &tail) const
Checks whether this string ends with another string.
std::deque< String > split_by_charset(const String &charset) const
Splits the string by a delimiter charset.
String & trim_me(const String &charset)
Trims this string.
void pop_back()
Removes the last character from the string.
bool starts_with(const String &head) const
Checks whether this string starts with another string.
String(const char *str)
CTOR.
String(const std::string &str)
CTOR.
String()
default constructor
String(String &&str)
move CTOR
String(const std::string &str, size_type offset, size_type count=npos)
CTOR.
String pad_front(size_type len, char c=' ') const
Pads the front of the string up to a desired length.
size_type replace_all(const String &find_string, const String &replace_string)
Replaces all occurrences of a substring by another substring.
String trim(const String &charset) const
Trims the string.
void push_front(char value)
Inserts a character at the front of the string.
String upper() const
Converts the string to upper case.
String(size_type count, char c)
CTOR.
bool is_one_of(const String &set, const String &sep=" ", bool case_insensitive=false) const
Checks whether this string is equal to one in a set of strings.
String lower() const
Converts the string to lower case.
std::istream & operator>>(std::istream &is, Pack::Type &t)
stream input operator for Pack::Type
CUDA_HOST_DEVICE Vector< T_, n_ > operator+(const Vector< T_, n_, sa_ > &a, const Vector< T_, n_, sb_ > &b)
vector addition operator
String stringify_fp_fix(DataType_ value, int precision=0, int width=0, bool sign=false)
Prints a floating point value to a string in fixed-point notation.
String stringify(const T_ &item)
Converts an item into a String.
String stringify_join(Iterator_ first, Iterator_ last, const String &delimiter="")
Joins a sequence of strings.
__half Half
Half data type.
String stringify_bytes(std::uint64_t bytes, int precision=3, int width=7)
Prints a byte size to a string using the common units Bytes, KiB, MiB, Gib, TiB or PiB.
String stringify_fp_sci(DataType_ value, int precision=0, int width=0, bool sign=false)
Prints a floating point value to a string in scientific notation.
@ value
specifies whether the space should supply basis function values