17# define vsnprintf _vsnprintf
37 if (
str.size() > 65536) {
42 str.resize(
str.size() * 2, 0);
45 else if (result >= (
int)
str.size()) {
47 str.resize(result + 1, 0);
51 return string(&
str[0]);
57 if (a.size() ==
b.size()) {
58 for (
size_t i = 0; i < a.size(); i++) {
59 if (toupper(a[i]) != toupper(
b[i])) {
72 const string &separators,
73 bool skip_empty_tokens)
75 size_t token_start = 0, token_length = 0;
76 for (
size_t i = 0; i <
str.size(); ++i) {
77 const char ch =
str[i];
78 if (separators.find(ch) == string::npos) {
88 if (!skip_empty_tokens || token_length > 0) {
89 string token =
str.substr(token_start, token_length);
90 tokens.push_back(token);
98 string token =
str.substr(token_start, token_length);
99 tokens.push_back(token);
105 const size_t len = start.size();
107 if (
len > s.size()) {
111 return strncmp(s.c_str(), start.data(),
len) == 0;
116 const size_t len = end.size();
118 if (
len > s.size()) {
122 return strncmp(s.c_str() + s.size() -
len, end.data(),
len) == 0;
128 result.erase(0, result.find_first_not_of(
' '));
129 result.erase(result.find_last_not_of(
' ') + 1);
136 while ((index = haystack.find(needle, i)) != string::npos) {
137 haystack.replace(index, needle.size(), other);
138 i = index + other.size();
144 assert(needle.size() == other.size());
146 while (
pos != string::npos) {
147 pos = haystack.find(needle,
pos);
148 if (
pos != string::npos) {
149 memcpy(haystack.data() +
pos, other.data(), other.size());
193 std::transform(r.begin(), r.end(), r.begin(), [](
char c) { return std::tolower(c); });
201wstring string_to_wstring(
const string &
str)
203 const int length_wc = MultiByteToWideChar(CP_UTF8, 0,
str.c_str(),
str.length(),
NULL, 0);
204 wstring str_wc(length_wc, 0);
205 MultiByteToWideChar(CP_UTF8, 0,
str.c_str(),
str.length(), &str_wc[0], length_wc);
209string string_from_wstring(
const wstring &
str)
211 int length_mb = WideCharToMultiByte(CP_UTF8, 0,
str.c_str(),
str.size(),
NULL, 0,
NULL,
NULL);
212 string str_mb(length_mb, 0);
213 WideCharToMultiByte(CP_UTF8, 0,
str.c_str(),
str.size(), &str_mb[0], length_mb,
NULL,
NULL);
217string string_to_ansi(
const string &
str)
219 const int length_wc = MultiByteToWideChar(CP_UTF8, 0,
str.c_str(),
str.length(),
NULL, 0);
220 wstring str_wc(length_wc, 0);
221 MultiByteToWideChar(CP_UTF8, 0,
str.c_str(),
str.length(), &str_wc[0], length_wc);
223 int length_mb = WideCharToMultiByte(
224 CP_ACP, 0, str_wc.c_str(), str_wc.size(),
NULL, 0,
NULL,
NULL);
226 string str_mb(length_mb, 0);
227 WideCharToMultiByte(CP_ACP, 0, str_wc.c_str(), str_wc.size(), &str_mb[0], length_mb,
NULL,
NULL);
236 static const char suffixes[] =
"BKMGTPEZY";
238 const char *suffix = suffixes;
241 while (size >= 1024) {
247 if (*suffix !=
'B') {
248 return string_printf(
"%.2f%c",
double(size * 1024 + r) / 1024.0, *suffix);
269 if (++i && i % 3 == 0) {
273 *(--p) =
'0' + (num % 10);
ATTR_WARN_UNUSED_RESULT const BMVert * v
local_group_size(16, 16) .push_constant(Type b
#define CCL_NAMESPACE_END
string string_remove_trademark(const string &s)
string string_from_bool(bool var)
string string_human_readable_size(size_t size)
bool string_iequals(const string &a, const string &b)
string string_strip(const string &s)
string to_string(const char *str)
string string_human_readable_number(size_t num)
bool string_startswith(const string_view s, const string_view start)
CCL_NAMESPACE_BEGIN string string_printf(const char *format,...)
void string_replace_same_length(string &haystack, const string &needle, const string &other)
void string_split(vector< string > &tokens, const string &str, const string &separators, bool skip_empty_tokens)
void string_replace(string &haystack, const string &needle, const string &other)
bool string_endswith(const string_view s, const string_view end)
string string_to_lower(const string &s)