C++ Utilities 5.22.0
Useful C++ classes and routines such as argument parser, IO and conversion utilities
Loading...
Searching...
No Matches
stringconversion.h
Go to the documentation of this file.
1#ifndef CONVERSION_UTILITIES_STRINGCONVERSION_H
2#define CONVERSION_UTILITIES_STRINGCONVERSION_H
3
6
7#include "../misc/traits.h"
8
9#include <cstdlib>
10#include <cstring>
11#include <initializer_list>
12#include <iomanip>
13#include <list>
14#include <memory>
15#include <sstream>
16#include <string>
17#include <string_view>
18#include <system_error>
19#include <vector>
20
21#if __cplusplus >= 201709 && !defined(REFLECTIVE_RAPIDJSON_GENERATOR)
22#ifndef CPP_UTILITIES_USE_RANGES
23#define CPP_UTILITIES_USE_RANGES
24#endif
25#include <ranges>
26#endif
27
28namespace CppUtilities {
29
38 void operator()(char *stringData)
39 {
40 std::free(stringData);
41 }
42};
43
47using StringData = std::pair<std::unique_ptr<char[], StringDataDeleter>, std::size_t>;
48//using StringData = std::pair<std::unique_ptr<char>, std::size_t>; // might work too
49
51 const char *fromCharset, const char *toCharset, const char *inputBuffer, std::size_t inputBufferSize, float outputBufferSizeFactor = 1.0f);
52CPP_UTILITIES_EXPORT StringData convertUtf8ToUtf16LE(const char *inputBuffer, std::size_t inputBufferSize);
53CPP_UTILITIES_EXPORT StringData convertUtf16LEToUtf8(const char *inputBuffer, std::size_t inputBufferSize);
54CPP_UTILITIES_EXPORT StringData convertUtf8ToUtf16BE(const char *inputBuffer, std::size_t inputBufferSize);
55CPP_UTILITIES_EXPORT StringData convertUtf16BEToUtf8(const char *inputBuffer, std::size_t inputBufferSize);
56CPP_UTILITIES_EXPORT StringData convertLatin1ToUtf8(const char *inputBuffer, std::size_t inputBufferSize);
57CPP_UTILITIES_EXPORT StringData convertUtf8ToLatin1(const char *inputBuffer, std::size_t inputBufferSize);
58
59#ifdef PLATFORM_WINDOWS
60using WideStringData = std::pair<std::unique_ptr<wchar_t[]>, int>;
61CPP_UTILITIES_EXPORT std::wstring convertMultiByteToWide(std::error_code &ec, std::string_view inputBuffer);
62CPP_UTILITIES_EXPORT WideStringData convertMultiByteToWide(std::error_code &ec, const char *inputBuffer, int inputBufferSize = -1);
63CPP_UTILITIES_EXPORT WideStringData convertMultiByteToWide(std::error_code &ec, const std::string &inputBuffer);
64CPP_UTILITIES_EXPORT WideStringData convertMultiByteToWide(const char *inputBuffer, int inputBufferSize = -1);
65CPP_UTILITIES_EXPORT WideStringData convertMultiByteToWide(const std::string &inputBuffer);
66#endif
67
68CPP_UTILITIES_EXPORT void truncateString(std::string &str, char terminationChar = '\0');
69
71namespace Detail {
72#ifdef CPP_UTILITIES_USE_RANGES
73template <class Container>
74using ContainerValueType = typename std::conditional_t<std::ranges::range<Container>,
75 std::iterator_traits<std::remove_cvref_t<std::ranges::iterator_t<Container>>>, Container>::value_type;
76#else
77template <class Container> using ContainerValueType = typename Container::value_type;
78#endif
79template <class Container> using DefaultReturnTypeForContainer = ContainerValueType<Container>;
80template <class Container> using StringParamForContainer = std::basic_string_view<typename ContainerValueType<Container>::value_type>;
81} // namespace Detail
83
98template <class Container = std::initializer_list<std::string>, class ReturnType = Detail::DefaultReturnTypeForContainer<Container>>
99ReturnType joinStrings(const Container &strings, Detail::StringParamForContainer<Container> delimiter = Detail::StringParamForContainer<Container>(),
100 bool omitEmpty = false, Detail::StringParamForContainer<Container> leftClosure = Detail::StringParamForContainer<Container>(),
101 Detail::StringParamForContainer<Container> rightClosure = Detail::StringParamForContainer<Container>())
102{
103 ReturnType res;
104 if (!strings.size()) {
105 return res;
106 }
107 std::size_t entries = 0, size = 0;
108 for (const auto &str : strings) {
109 if (omitEmpty && str.empty()) {
110 continue;
111 }
112 size += str.size();
113 ++entries;
114 }
115 if (!entries) {
116 return res;
117 }
118 size += (entries * leftClosure.size()) + (entries * rightClosure.size()) + ((entries - 1) * delimiter.size());
119 res.reserve(size);
120 for (const auto &str : strings) {
121 if (omitEmpty && str.empty()) {
122 continue;
123 }
124 if (!res.empty()) {
125 res.append(delimiter);
126 }
127 res.append(leftClosure);
128 res.append(str);
129 res.append(rightClosure);
130 }
131 return res;
132}
133
137template <class Container = std::initializer_list<std::string>> inline auto toMultiline(const Container &arrayOfLines)
138{
139 return joinStrings(arrayOfLines, "\n", false);
140}
141
145enum class EmptyPartsTreat {
146 Keep,
147 Omit,
148 Merge
149};
150
160template <class Container = std::list<std::string>>
161Container splitString(Detail::StringParamForContainer<Container> string, Detail::StringParamForContainer<Container> delimiter,
162 EmptyPartsTreat emptyPartsRole = EmptyPartsTreat::Keep, int maxParts = -1)
163{
164 --maxParts;
165 Container res;
166 typename Container::value_type *last = nullptr;
167 bool merge = false;
168 typename Container::value_type::size_type i = 0, end = string.size();
169 for (typename Container::value_type::size_type delimPos; i < end; i = delimPos + delimiter.size()) {
170 delimPos = string.find(delimiter, i);
171 if (!merge && maxParts >= 0 && res.size() == static_cast<typename Container::value_type::size_type>(maxParts)) {
172 if (delimPos == i && emptyPartsRole == EmptyPartsTreat::Merge) {
173 if (last) {
174 merge = true;
175 continue;
176 }
177 }
178 delimPos = Container::value_type::npos;
179 }
180 if (delimPos == Container::value_type::npos) {
181 delimPos = string.size();
182 }
183 if (emptyPartsRole == EmptyPartsTreat::Keep || i != delimPos) {
184 if (merge) {
185 last->append(delimiter);
186 last->append(string, i, delimPos - i);
187 merge = false;
188 } else {
189 last = &res.emplace_back(string, i, delimPos - i);
190 }
191 } else if (emptyPartsRole == EmptyPartsTreat::Merge) {
192 if (last) {
193 merge = true;
194 }
195 }
196 }
197 if (i == end && emptyPartsRole == EmptyPartsTreat::Keep) {
198 res.emplace_back();
199 }
200 return res;
201}
202
212template <class Container = std::list<std::string>>
214 Detail::StringParamForContainer<Container> string, Detail::StringParamForContainer<Container> delimiter, int maxParts = -1)
215{
216 --maxParts;
217 Container res;
218 typename Container::value_type::size_type i = 0, end = string.size();
219 for (typename Container::value_type::size_type delimPos; i < end; i = delimPos + delimiter.size()) {
220 delimPos = string.find(delimiter, i);
221 if (maxParts >= 0 && res.size() == static_cast<typename Container::value_type::size_type>(maxParts)) {
222 delimPos = Container::value_type::npos;
223 }
224 if (delimPos == Container::value_type::npos) {
225 delimPos = string.size();
226 }
227#if __cplusplus >= 201709
228 if constexpr (requires { res.emplace_back(string); }) {
229#endif
230 res.emplace_back(string.data() + i, delimPos - i);
231#if __cplusplus >= 201709
232 } else {
233 res.emplace(string.data() + i, delimPos - i);
234 }
235#endif
236 }
237 if (i == end) {
238#if __cplusplus >= 201709
239 if constexpr (requires { res.emplace_back(); }) {
240#endif
241 res.emplace_back();
242#if __cplusplus >= 201709
243 } else {
244 res.emplace();
245 }
246#endif
247 }
248 return res;
249}
250
254template <class Container = std::vector<std::string>> inline auto toArrayOfLines(const std::string &multilineString)
255{
256 return splitString<Container>(multilineString, "\n", EmptyPartsTreat::Keep);
257}
258
262template <typename StringType> bool startsWith(const StringType &str, const StringType &phrase)
263{
264 if (str.size() < phrase.size()) {
265 return false;
266 }
267 for (auto stri = str.cbegin(), strend = str.cend(), phrasei = phrase.cbegin(), phraseend = phrase.cend();; ++stri, ++phrasei) {
268 if (phrasei == phraseend) {
269 return true;
270 } else if (stri == strend) {
271 return false;
272 } else if (*stri != *phrasei) {
273 return false;
274 }
275 }
276 return false;
277}
278
282template <typename StringType> bool startsWith(const StringType &str, const typename StringType::value_type *phrase)
283{
284 for (auto stri = str.cbegin(), strend = str.cend();; ++stri, ++phrase) {
285 if (!*phrase) {
286 return true;
287 } else if (stri == strend) {
288 return false;
289 } else if (*stri != *phrase) {
290 return false;
291 }
292 }
293 return false;
294}
295
299template <typename StringType> bool endsWith(const StringType &str, const StringType &phrase)
300{
301 if (str.size() < phrase.size()) {
302 return false;
303 }
304 for (auto stri = str.cend() - static_cast<typename StringType::difference_type>(phrase.size()), strend = str.cend(), phrasei = phrase.cbegin();
305 stri != strend; ++stri, ++phrasei) {
306 if (*stri != *phrasei) {
307 return false;
308 }
309 }
310 return true;
311}
312
316template <typename StringType> bool endsWith(const StringType &str, const typename StringType::value_type *phrase)
317{
318 const auto phraseSize = std::strlen(phrase);
319 if (str.size() < phraseSize) {
320 return false;
321 }
322 for (auto stri = str.cend() - static_cast<typename StringType::difference_type>(phraseSize), strend = str.cend(); stri != strend;
323 ++stri, ++phrase) {
324 if (*stri != *phrase) {
325 return false;
326 }
327 }
328 return true;
329}
330
335template <typename StringType> bool containsSubstrings(const StringType &str, std::initializer_list<StringType> substrings)
336{
337 typename StringType::size_type currentPos = 0;
338 for (const auto &substr : substrings) {
339 if ((currentPos = str.find(substr, currentPos)) == StringType::npos) {
340 return false;
341 }
342 currentPos += substr.size();
343 }
344 return true;
345}
346
351template <typename StringType>
352bool containsSubstrings(const StringType &str, std::initializer_list<const typename StringType::value_type *> substrings)
353{
354 typename StringType::size_type currentPos = 0;
355 for (const auto *substr : substrings) {
356 if ((currentPos = str.find(substr, currentPos)) == StringType::npos) {
357 return false;
358 }
359 currentPos += std::strlen(substr);
360 }
361 return true;
362}
363
367template <typename StringType1, typename StringType2, typename StringType3>
368void findAndReplace(StringType1 &str, const StringType2 &find, const StringType3 &replace)
369{
370 for (typename StringType1::size_type i = 0; (i = str.find(find, i)) != StringType1::npos; i += replace.size()) {
371 str.replace(i, find.size(), replace);
372 }
373}
374
378template <typename StringType>
379inline void findAndReplace(StringType &str, const typename StringType::value_type *find, const typename StringType::value_type *replace)
380{
382 str, std::basic_string_view<typename StringType::value_type>(find), std::basic_string_view<typename StringType::value_type>(replace));
383}
384
388template <typename StringType1, typename StringType2>
389inline void findAndReplace(StringType1 &str, const StringType2 &find, const typename StringType1::value_type *replace)
390{
391 findAndReplace(str, find, std::basic_string_view<typename StringType1::value_type>(replace));
392}
393
397template <typename StringType1, typename StringType2>
398inline void findAndReplace(StringType1 &str, const typename StringType1::value_type *find, const StringType2 &replace)
399{
400 findAndReplace(str, std::basic_string_view<typename StringType1::value_type>(find), replace);
401}
402
409template <typename CharType> constexpr CharType digitToChar(CharType digit)
410{
411 return digit <= 9 ? (digit + '0') : (digit + 'A' - 10);
412}
413
420template <typename IntegralType, class StringType = std::string, typename BaseType = IntegralType,
421 CppUtilities::Traits::EnableIf<std::is_integral<IntegralType>, std::is_unsigned<IntegralType>> * = nullptr>
422StringType numberToString(IntegralType number, BaseType base = 10)
423{
424 std::size_t resSize = 0;
425 for (auto n = number; n; n /= static_cast<IntegralType>(base), ++resSize)
426 ;
427 StringType res;
428 res.reserve(resSize);
429 do {
430 res.insert(res.begin(), digitToChar<typename StringType::value_type>(static_cast<typename StringType::value_type>(number % base)));
431 number /= static_cast<IntegralType>(base);
432 } while (number);
433 return res;
434}
435
442template <typename IntegralType, class StringType = std::string, typename BaseType = IntegralType,
443 Traits::EnableIf<std::is_integral<IntegralType>, std::is_signed<IntegralType>> * = nullptr>
444StringType numberToString(IntegralType number, BaseType base = 10)
445{
446 const bool negative = number < 0;
447 std::size_t resSize;
448 if (negative) {
449 number = -number, resSize = 1;
450 } else {
451 resSize = 0;
452 }
453 for (auto n = number; n; n /= static_cast<IntegralType>(base), ++resSize)
454 ;
455 StringType res;
456 res.reserve(resSize);
457 do {
458 res.insert(res.begin(),
459 digitToChar<typename StringType::value_type>(static_cast<typename StringType::value_type>(number % static_cast<IntegralType>(base))));
460 number /= static_cast<IntegralType>(base);
461 } while (number);
462 if (negative) {
463 res.insert(res.begin(), '-');
464 }
465 return res;
466}
467
476template <typename FloatingType, class StringType = std::string, Traits::EnableIf<std::is_floating_point<FloatingType>> * = nullptr>
477StringType numberToString(FloatingType number, int base = 10)
478{
479 std::basic_stringstream<typename StringType::value_type> ss;
480 ss << std::setbase(base) << number;
481 return ss.str();
482}
483
488template <typename CharType> CharType charToDigit(CharType character, CharType base)
489{
490 CharType res = base;
491 if (character >= '0' && character <= '9') {
492 res = character - '0';
493 } else if (character >= 'a' && character <= 'z') {
494 res = character - 'a' + 10;
495 } else if (character >= 'A' && character <= 'Z') {
496 res = character - 'A' + 10;
497 }
498 if (res < base) {
499 return res;
500 }
501 std::string errorMsg;
502 errorMsg.reserve(36);
503 errorMsg += "The character \"";
504 errorMsg += character >= ' ' && character <= '~' ? static_cast<std::string::value_type>(character) : '?';
505 errorMsg += "\" is no valid digit.";
506 throw ConversionException(std::move(errorMsg));
507}
508
510namespace Detail {
511template <typename IntegralType, typename CharType, typename BaseType = IntegralType>
512void raiseAndAdd(IntegralType &result, BaseType base, CharType character)
513{
514 if (character == ' ') {
515 return;
516 }
517#ifdef __GNUC__ // overflow detection only supported on GCC and Clang
518 if (__builtin_mul_overflow(result, base, &result)
519 || __builtin_add_overflow(result, charToDigit(character, static_cast<CharType>(base)), &result)) {
520 throw ConversionException("Number exceeds limit.");
521 }
522#else
523 result *= static_cast<IntegralType>(base);
524 result += static_cast<IntegralType>(charToDigit<CharType>(character, static_cast<CharType>(base)));
525#endif
526}
527} // namespace Detail
529
537template <typename IntegralType, class CharType, typename BaseType = IntegralType,
538 Traits::EnableIf<std::is_integral<IntegralType>, std::is_unsigned<IntegralType>> * = nullptr>
539IntegralType bufferToNumber(const CharType *string, std::size_t size, BaseType base = 10)
540{
541 IntegralType result = 0;
542 for (const CharType *end = string + size; string != end; ++string) {
543 Detail::raiseAndAdd(result, base, *string);
544 }
545 return result;
546}
547
555template <typename IntegralType, typename CharType, typename BaseType = IntegralType,
556 Traits::EnableIf<std::is_integral<IntegralType>, std::is_signed<IntegralType>> * = nullptr>
557IntegralType bufferToNumber(const CharType *string, std::size_t size, BaseType base = 10)
558{
559 if (!size) {
560 return 0;
561 }
562 const CharType *end = string + size;
563 for (; string != end && *string == ' '; ++string)
564 ;
565 if (string == end) {
566 return 0;
567 }
568 const bool negative = (*string == '-');
569 if (negative) {
570 ++string;
571 }
572 IntegralType result = 0;
573 for (; string != end; ++string) {
574 Detail::raiseAndAdd(result, base, *string);
575 }
576 return negative ? -result : result;
577}
578
586template <typename IntegralType, class StringType, typename BaseType = IntegralType,
587 Traits::EnableIf<std::is_integral<IntegralType>, Traits::Not<std::is_scalar<std::decay_t<StringType>>>> * = nullptr>
588IntegralType stringToNumber(const StringType &string, BaseType base = 10)
589{
590 return bufferToNumber<IntegralType, typename StringType::value_type, BaseType>(string.data(), string.size(), base);
591}
592
602template <typename FloatingType, class StringViewType,
603 Traits::EnableIf<std::is_floating_point<FloatingType>, Traits::IsSpecializationOf<StringViewType, std::basic_string_view>> * = nullptr>
604FloatingType stringToNumber(StringViewType stringView, int base = 10)
605{
606 std::basic_stringstream<typename StringViewType::value_type> ss;
607 ss << std::setbase(base) << stringView;
608 FloatingType result;
609 if ((ss >> result) && ss.eof()) {
610 return result;
611 }
612 std::string errorMsg;
613 errorMsg.reserve(48 + stringView.size());
614 errorMsg += "The string \"";
615 errorMsg += stringView;
616 errorMsg += "\" is no valid floating point number.";
617 throw ConversionException(errorMsg);
618}
619
629template <typename FloatingType, class StringType,
630 Traits::EnableIf<std::is_floating_point<FloatingType>, Traits::Not<std::is_scalar<std::decay_t<StringType>>>,
631 Traits::Not<Traits::IsSpecializationOf<StringType, std::basic_string_view>>> * = nullptr>
632FloatingType stringToNumber(const StringType &string, int base = 10)
633{
634 using StringViewType = std::basic_string_view<typename StringType::value_type>;
635 return stringToNumber<FloatingType, StringViewType>(StringViewType(string.data(), string.size()), base);
636}
637
645template <typename IntegralType, typename CharType, typename BaseType = IntegralType,
646 Traits::EnableIf<std::is_integral<IntegralType>, std::is_unsigned<IntegralType>> * = nullptr>
647IntegralType stringToNumber(const CharType *string, BaseType base = 10)
648{
649 IntegralType result = 0;
650 for (; *string; ++string) {
651 Detail::raiseAndAdd(result, base, *string);
652 }
653 return result;
654}
655
665template <typename FloatingType, class CharType, Traits::EnableIf<std::is_floating_point<FloatingType>> * = nullptr>
666FloatingType stringToNumber(const CharType *string, int base = 10)
667{
668 return stringToNumber<FloatingType, std::basic_string_view<CharType>>(string, base);
669}
670
678template <typename IntegralType, typename CharType, typename BaseType = IntegralType,
679 Traits::EnableIf<std::is_integral<IntegralType>, std::is_signed<IntegralType>> * = nullptr>
680IntegralType stringToNumber(const CharType *string, IntegralType base = 10)
681{
682 if (!*string) {
683 return 0;
684 }
685 for (; *string && *string == ' '; ++string)
686 ;
687 if (!*string) {
688 return 0;
689 }
690 const bool negative = (*string == '-');
691 if (negative) {
692 ++string;
693 }
694 IntegralType result = 0;
695 for (; *string; ++string) {
696 Detail::raiseAndAdd(result, base, *string);
697 }
698 return negative ? -result : result;
699}
700
710template <typename T> std::string interpretIntegerAsString(T integer, int startOffset = 0)
711{
712 char buffer[sizeof(T)];
713 BE::getBytes(integer, buffer);
714 return std::string(buffer + startOffset, sizeof(T) - static_cast<std::size_t>(startOffset));
715}
716
717CPP_UTILITIES_EXPORT std::string dataSizeToString(std::uint64_t sizeInByte, bool includeByte = false);
718CPP_UTILITIES_EXPORT std::string bitrateToString(double speedInKbitsPerSecond, bool useByteInsteadOfBits = false);
719CPP_UTILITIES_EXPORT std::string encodeBase64(const std::uint8_t *data, std::uint32_t dataSize);
720CPP_UTILITIES_EXPORT std::pair<std::unique_ptr<std::uint8_t[]>, std::uint32_t> decodeBase64(const char *encodedStr, const std::uint32_t strSize);
721} // namespace CppUtilities
722
723#endif // CONVERSION_UTILITIES_STRINGCONVERSION_H
The ConversionException class is thrown by the various conversion functions of this library when a co...
#define CPP_UTILITIES_EXPORT
Marks the symbol to be exported by the c++utilities library.
typename std::enable_if< All< Condition... >::value, Detail::Enabler >::type EnableIf
Shortcut for std::enable_if to omit ::value and ::type.
Definition: traits.h:44
Contains all utilities provides by the c++utilities library.
void findAndReplace(StringType1 &str, const StringType2 &find, const StringType3 &replace)
Replaces all occurrences of find with relpace in the specified str.
CPP_UTILITIES_EXPORT StringData convertUtf8ToUtf16BE(const char *inputBuffer, std::size_t inputBufferSize)
Converts the specified UTF-8 string to UTF-16 (big-endian).
CPP_UTILITIES_EXPORT StringData convertString(const char *fromCharset, const char *toCharset, const char *inputBuffer, std::size_t inputBufferSize, float outputBufferSizeFactor=1.0f)
Converts the specified string from one character set to another.
StringType numberToString(IntegralType number, BaseType base=10)
Converts the given number to its equivalent string representation using the specified base.
CPP_UTILITIES_EXPORT StringData convertLatin1ToUtf8(const char *inputBuffer, std::size_t inputBufferSize)
Converts the specified Latin-1 string to UTF-8.
CPP_UTILITIES_EXPORT StringData convertUtf16LEToUtf8(const char *inputBuffer, std::size_t inputBufferSize)
Converts the specified UTF-16 (little-endian) string to UTF-8.
EmptyPartsTreat
Specifies the role of empty parts when splitting strings.
CPP_UTILITIES_EXPORT std::pair< std::unique_ptr< std::uint8_t[]>, std::uint32_t > decodeBase64(const char *encodedStr, const std::uint32_t strSize)
Decodes the specified Base64 encoded string.
ReturnType joinStrings(const Container &strings, Detail::StringParamForContainer< Container > delimiter=Detail::StringParamForContainer< Container >(), bool omitEmpty=false, Detail::StringParamForContainer< Container > leftClosure=Detail::StringParamForContainer< Container >(), Detail::StringParamForContainer< Container > rightClosure=Detail::StringParamForContainer< Container >())
Joins the given strings using the specified delimiter.
bool startsWith(const StringType &str, const StringType &phrase)
Returns whether str starts with phrase.
IntegralType stringToNumber(const StringType &string, BaseType base=10)
Converts the given string to an unsigned/signed number assuming string uses the specified base.
CPP_UTILITIES_EXPORT void truncateString(std::string &str, char terminationChar='\0')
Truncates all characters after the first occurrence of the specified terminationChar and the terminat...
std::pair< std::unique_ptr< char[], StringDataDeleter >, std::size_t > StringData
Type used to return string encoding conversion result.
CPP_UTILITIES_EXPORT StringData convertUtf16BEToUtf8(const char *inputBuffer, std::size_t inputBufferSize)
Converts the specified UTF-16 (big-endian) string to UTF-8.
constexpr CharType digitToChar(CharType digit)
Returns the character representation of the specified digit.
Container splitStringSimple(Detail::StringParamForContainer< Container > string, Detail::StringParamForContainer< Container > delimiter, int maxParts=-1)
Splits the given string (which might also be a string view) at the specified delimiter.
auto toArrayOfLines(const std::string &multilineString)
Converts the specified multilineString to an array of lines.
bool containsSubstrings(const StringType &str, std::initializer_list< StringType > substrings)
Returns whether str contains the specified substrings.
CPP_UTILITIES_EXPORT StringData convertUtf8ToLatin1(const char *inputBuffer, std::size_t inputBufferSize)
Converts the specified UTF-8 string to Latin-1.
std::string interpretIntegerAsString(T integer, int startOffset=0)
Interprets the given integer at the specified position as std::string using the specified byte order.
bool endsWith(const StringType &str, const StringType &phrase)
Returns whether str ends with phrase.
auto toMultiline(const Container &arrayOfLines)
Converts the specified arrayOfLines to a multiline string.
CPP_UTILITIES_EXPORT StringData convertUtf8ToUtf16LE(const char *inputBuffer, std::size_t inputBufferSize)
Converts the specified UTF-8 string to UTF-16 (little-endian).
CPP_UTILITIES_EXPORT std::string bitrateToString(double speedInKbitsPerSecond, bool useByteInsteadOfBits=false)
Converts the specified bitrate in kbit/s to its equivalent std::string representation.
CharType charToDigit(CharType character, CharType base)
Returns number/digit of the specified character representation using the specified base.
CPP_UTILITIES_EXPORT std::string encodeBase64(const std::uint8_t *data, std::uint32_t dataSize)
Encodes the specified data to Base64.
CPP_UTILITIES_EXPORT std::string dataSizeToString(std::uint64_t sizeInByte, bool includeByte=false)
Converts the specified data size in byte to its equivalent std::string representation.
IntegralType bufferToNumber(const CharType *string, std::size_t size, BaseType base=10)
Converts the given string of size characters to an unsigned numeric value using the specified base.
Container splitString(Detail::StringParamForContainer< Container > string, Detail::StringParamForContainer< Container > delimiter, EmptyPartsTreat emptyPartsRole=EmptyPartsTreat::Keep, int maxParts=-1)
Splits the given string at the specified delimiter.
The StringDataDeleter struct deletes the data of a StringData instance.
void operator()(char *stringData)
Deletes the specified stringData with std::free(), because the memory has been allocated using std::m...
constexpr int i