31 outStr.begin(), outStr.end(),
33 (int (*)(
int))tolower);
44 outStr.begin(), outStr.end(),
46 (int (*)(
int))toupper);
58 #define MASK2BYTES 0xC0
59 #define MASK3BYTES 0xE0
60 #define MASK4BYTES 0xF0
61 #define MASK5BYTES 0xF8
62 #define MASK6BYTES 0xFC
65 const std::vector<uint16_t>& input, std::string& output)
68 output.reserve(input.size());
69 for (
unsigned short i : input)
99 const std::string& input, std::vector<uint16_t>& output)
102 output.reserve(input.size());
103 for (
size_t i = 0; i < input.size();)
110 ch = ((input[i] & 0x0F) << 12) | ((input[i + 1] &
MASKBITS) << 6) |
117 ch = ((input[i] & 0x1F) << 6) | (input[i + 1] &
MASKBITS);
121 else if (uint8_t(input[i]) <
MASKBYTE)
126 output.push_back(ch);
137 const double val,
int nDecimalDigits,
bool middle_space)
141 const double aVal = std::abs(
val);
148 else if (aVal >= 1e9)
153 else if (aVal >= 1e6)
158 else if (aVal >= 1e3)
168 else if (aVal >= 1e-3)
173 else if (aVal >= 1e-6)
178 else if (aVal >= 1e-9)
190 middle_space ?
"%.*f %c" :
"%.*f%c", nDecimalDigits,
val * mult,
198 char* str,
const char* strDelimit,
char** context) noexcept
200 #if defined(_MSC_VER) && (_MSC_VER >= 1400)
202 return ::strtok_s(str, strDelimit, context);
206 return ::strtok_r(str, strDelimit, context);
214 template <
class CONTAINER>
216 const std::string& inString,
const std::string& inDelimiters,
217 CONTAINER& outTokens,
bool skipBlankTokens) noexcept
221 const size_t len = inString.size();
222 bool prev_was_delim =
true;
223 std::string cur_token;
224 for (
size_t pos = 0; pos <= len; pos++)
237 cur_is_delim = (inDelimiters.find(c) != string::npos);
243 if (!skipBlankTokens) outTokens.push_back(std::string());
247 outTokens.push_back(cur_token);
253 cur_token.push_back(c);
255 prev_was_delim = cur_is_delim;
260 template void mrpt::system::tokenize<std::deque<std::string>>(
261 const std::string& inString,
const std::string& inDelimiters,
262 std::deque<std::string>& outTokens,
bool skipBlankTokens) noexcept;
263 template void mrpt::system::tokenize<std::vector<std::string>>(
264 const std::string& inString,
const std::string& inDelimiters,
265 std::vector<std::string>& outTokens,
bool skipBlankTokens) noexcept;
274 return std::string();
278 size_t s = str.find_first_not_of(
" \t");
279 size_t e = str.find_last_not_of(
" \t");
280 if (s == std::string::npos || e == std::string::npos)
281 return std::string();
283 return str.substr(s, e - s + 1);
291 const std::string& str,
const size_t total_len,
bool truncate_if_larger)
294 if (r.size() < total_len || truncate_if_larger) r.resize(total_len,
' ');
315 s1.c_str(), s2.c_str(),
324 s1.c_str(), s2.c_str(),
328 template <
typename STRING_LIST>
330 const STRING_LIST& lst, std::string& outText,
const std::string& newline)
332 const size_t lenNL = newline.size();
335 size_t totalLen = lst.size() * lenNL;
336 for (
const auto& s : lst) totalLen += s.size();
338 outText.resize(totalLen);
342 for (
const auto& s : lst)
345 &outText[curPos], totalLen, s.c_str(), s.size());
347 for (
const auto& sNL : newline) outText[curPos++] = sNL;
352 const std::vector<std::string>& lst, std::string& outText,
353 const std::string& newLine)
359 const std::deque<std::string>& lst, std::string& outText,
360 const std::string& newLine)