| 1 | #cxx . . $ `<file>/conversion/stringconversion.h`/ifndef CONVERSION_UTILITIES_STRINGCONVERSION_H |
| 2 | #define CONVERSION_UTILITIES_STRINGCONVERSION_Hcxx . . $ `conversion/stringconversion.h:2:9`! |
| 3 | |
| 4 | #include "./binaryconversion.h"cxx . . $ `<file>/conversion/binaryconversion.h`/ |
| 5 | #include "./conversionexception.h"cxx . . $ `<file>/conversion/conversionexception.h`/ |
| 6 | |
| 7 | #include "../misc/traits.h"cxx . . $ `<file>/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 <vector> |
| 19 | |
| 20 | #ifdef PLATFORM_WINDOWS |
| 21 | #include <system_error> |
| 22 | #endif |
| 23 | |
| 24 | // configure use of ranges and concepts |
| 25 | #if __cpluspluscxx . . $ `<built-in>:472:9`! >= 201709 |
| 26 | #include <version> |
| 27 | #endif |
| 28 | #if __cpluspluscxx . . $ `<built-in>:472:9`! >= 201709 && defined(__cpp_lib_ranges) && !defined(REFLECTIVE_RAPIDJSON_GENERATOR) |
| 29 | #ifndef CPP_UTILITIES_USE_RANGES |
| 30 | #define CPP_UTILITIES_USE_RANGES |
| 31 | #endif |
| 32 | #include <ranges> |
| 33 | #endif |
| 34 | #if __cpluspluscxx . . $ `<built-in>:472:9`! >= 201709 && defined(__cpp_concepts) |
| 35 | #ifndef CPP_UTILITIES_USE_REQUIRES |
| 36 | #define CPP_UTILITIES_USE_REQUIRES |
| 37 | #endif |
| 38 | #endif |
| 39 | |
| 40 | namespace CppUtilitiescxx . . $ CppUtilities/ { |
| 41 | |
| 42 | // clang-format off |
| 43 | /*! |
| 44 | * \brief The StringDataDeleter struct deletes the data of a StringData instance. |
| 45 | */ |
| 46 | struct CPP_UTILITIES_EXPORTcxx . . $ `global.h:11:9`! StringDataDeletercxx . . $ CppUtilities/StringDataDeleter#{ /*! |
| 47 | * \brief Deletes the specified \a stringData with std::free(), because the memory has been |
| 48 | * allocated using std::malloc()/std::realloc(). |
| 49 | */ |
| 50 | void operatorcxx . . $ CppUtilities/StringDataDeleter#`operator()`(fda57c8427c60377).()(char *stringData){ stdcxx . . $ std/::free(stringData); } |
| 51 | }; |
| 52 | // clang-format on |
| 53 | |
| 54 | /*! |
| 55 | * \brief Type used to return string encoding conversion result. |
| 56 | */ |
| 57 | using StringDatacxx . . $ CppUtilities/StringData# = stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<char[], StringDataDeletercxx . . $ CppUtilities/StringDataDeleter#>, stdcxx . . $ std/::size_tcxx . . $ std/size_t#>; |
| 58 | //using StringData = std::pair<std::unique_ptr<char>, std::size_t>; // might work too |
| 59 | |
| 60 | #ifndef CPP_UTILITIES_NO_ICONV |
| 61 | CPP_UTILITIES_EXPORTcxx . . $ `global.h:11:9`! StringDatacxx . . $ CppUtilities/StringData# convertStringcxx . . $ CppUtilities/convertString(6db75fa61320dee9).( |
| 62 | const char *fromCharset, const char *toCharset, const char *inputBuffer, stdcxx . . $ std/::size_tcxx . . $ std/size_t# inputBufferSize, float outputBufferSizeFactor = 1.0f); |
| 63 | CPP_UTILITIES_EXPORTcxx . . $ `global.h:11:9`! StringDatacxx . . $ CppUtilities/StringData# convertUtf8ToUtf16LEcxx . . $ CppUtilities/convertUtf8ToUtf16LE(c808ac3c7ba7226b).(const char *inputBuffer, stdcxx . . $ std/::size_tcxx . . $ std/size_t# inputBufferSize); |
| 64 | CPP_UTILITIES_EXPORTcxx . . $ `global.h:11:9`! StringDatacxx . . $ CppUtilities/StringData# convertUtf16LEToUtf8cxx . . $ CppUtilities/convertUtf16LEToUtf8(c808ac3c7ba7226b).(const char *inputBuffer, stdcxx . . $ std/::size_tcxx . . $ std/size_t# inputBufferSize); |
| 65 | CPP_UTILITIES_EXPORTcxx . . $ `global.h:11:9`! StringDatacxx . . $ CppUtilities/StringData# convertUtf8ToUtf16BEcxx . . $ CppUtilities/convertUtf8ToUtf16BE(c808ac3c7ba7226b).(const char *inputBuffer, stdcxx . . $ std/::size_tcxx . . $ std/size_t# inputBufferSize); |
| 66 | CPP_UTILITIES_EXPORTcxx . . $ `global.h:11:9`! StringDatacxx . . $ CppUtilities/StringData# convertUtf16BEToUtf8cxx . . $ CppUtilities/convertUtf16BEToUtf8(c808ac3c7ba7226b).(const char *inputBuffer, stdcxx . . $ std/::size_tcxx . . $ std/size_t# inputBufferSize); |
| 67 | CPP_UTILITIES_EXPORTcxx . . $ `global.h:11:9`! StringDatacxx . . $ CppUtilities/StringData# convertLatin1ToUtf8cxx . . $ CppUtilities/convertLatin1ToUtf8(c808ac3c7ba7226b).(const char *inputBuffer, stdcxx . . $ std/::size_tcxx . . $ std/size_t# inputBufferSize); |
| 68 | CPP_UTILITIES_EXPORTcxx . . $ `global.h:11:9`! StringDatacxx . . $ CppUtilities/StringData# convertUtf8ToLatin1cxx . . $ CppUtilities/convertUtf8ToLatin1(c808ac3c7ba7226b).(const char *inputBuffer, stdcxx . . $ std/::size_tcxx . . $ std/size_t# inputBufferSize); |
| 69 | #endif |
| 70 | |
| 71 | #ifdef PLATFORM_WINDOWS |
| 72 | using WideStringData = std::pair<std::unique_ptr<wchar_t[]>, int>; |
| 73 | CPP_UTILITIES_EXPORT std::wstring convertMultiByteToWide(std::error_code &ec, std::string_view inputBuffer); |
| 74 | CPP_UTILITIES_EXPORT WideStringData convertMultiByteToWide(std::error_code &ec, const char *inputBuffer, int inputBufferSize = -1); |
| 75 | CPP_UTILITIES_EXPORT WideStringData convertMultiByteToWide(std::error_code &ec, const std::string &inputBuffer); |
| 76 | CPP_UTILITIES_EXPORT WideStringData convertMultiByteToWide(const char *inputBuffer, int inputBufferSize = -1); |
| 77 | CPP_UTILITIES_EXPORT WideStringData convertMultiByteToWide(const std::string &inputBuffer); |
| 78 | #endif |
| 79 | |
| 80 | CPP_UTILITIES_EXPORTcxx . . $ `global.h:11:9`! void truncateStringcxx . . $ CppUtilities/truncateString(21193be99a1fe6f1).(stdcxx . . $ std/::stringcxx . . $ std/string# &str, char terminationChar = '\0'); |
| 81 | |
| 82 | /// \cond |
| 83 | namespace Detailcxx . . $ CppUtilities/Detail/ { |
| 84 | #ifdef CPP_UTILITIES_USE_RANGES |
| 85 | template <class Container> |
| 86 | using ContainerValueType = typename std::conditional_t<std::ranges::range<Container>, |
| 87 | std::iterator_traits<std::remove_cvref_t<std::ranges::iterator_t<Container>>>, Container>::value_type; |
| 88 | #else |
| 89 | template <class Container> using ContainerValueTypecxx . . $ CppUtilities/Detail/ContainerValueType# = typename Container::value_type; |
| 90 | #endif |
| 91 | template <class Container> using DefaultReturnTypeForContainercxx . . $ CppUtilities/Detail/DefaultReturnTypeForContainer# = ContainerValueTypecxx . . $ CppUtilities/Detail/ContainerValueType#<Container>; |
| 92 | template <class Container> using StringParamForContainercxx . . $ CppUtilities/Detail/StringParamForContainer# = stdcxx . . $ std/::basic_string_viewcxx . . $ std/basic_string_view#<typename ContainerValueTypecxx . . $ CppUtilities/Detail/ContainerValueType#<Container>::value_type>; |
| 93 | } // namespace Detail |
| 94 | /// \endcond |
| 95 | |
| 96 | /*! |
| 97 | * \brief Joins the given \a strings using the specified \a delimiter. |
| 98 | * |
| 99 | * The strings will be enclosed using the provided closures \a leftClosure and \a rightClosure. |
| 100 | * |
| 101 | * \param strings The string parts to be joined. |
| 102 | * \param delimiter Specifies a delimiter to be used (empty string by default). |
| 103 | * \param omitEmpty Indicates whether empty part should be omitted. |
| 104 | * \param leftClosure Specifies a string to be inserted before each string (empty string by default). |
| 105 | * \param rightClosure Specifies a string to be appended after each string (empty string by default). |
| 106 | * \tparam Container Container The STL-container used to provide the \a strings. |
| 107 | * \tparam ReturnType Type to store the result; defaults to the container's element type. |
| 108 | * \returns Returns the joined string. |
| 109 | */ |
| 110 | template <class Container = stdcxx . . $ std/::initializer_listcxx . . $ std/initializer_list#<stdcxx . . $ std/::stringcxx . . $ std/string#>, class ReturnType = Detailcxx . . $ CppUtilities/Detail/::DefaultReturnTypeForContainercxx . . $ CppUtilities/Detail/DefaultReturnTypeForContainer#<Container>> |
| 111 | ReturnType joinStringscxx . . $ CppUtilities/joinStrings(27d6fdf6f9f61b56).(const Container &strings, Detailcxx . . $ CppUtilities/Detail/::StringParamForContainercxx . . $ CppUtilities/Detail/StringParamForContainer#<Container> delimiter = Detailcxx . . $ CppUtilities/Detail/::StringParamForContainercxx . . $ CppUtilities/Detail/StringParamForContainer#<Container>(), |
| 112 | bool omitEmpty = false, Detailcxx . . $ CppUtilities/Detail/::StringParamForContainercxx . . $ CppUtilities/Detail/StringParamForContainer#<Container> leftClosure = Detailcxx . . $ CppUtilities/Detail/::StringParamForContainercxx . . $ CppUtilities/Detail/StringParamForContainer#<Container>(), |
| 113 | Detailcxx . . $ CppUtilities/Detail/::StringParamForContainercxx . . $ CppUtilities/Detail/StringParamForContainer#<Container> rightClosure = Detailcxx . . $ CppUtilities/Detail/::StringParamForContainercxx . . $ CppUtilities/Detail/StringParamForContainer#<Container>()) |
| 114 | { |
| 115 | ReturnType res; |
| 116 | if (!strings.size()) { |
| 117 | return res; |
| 118 | } |
| 119 | stdcxx . . $ std/::size_tcxx . . $ std/size_t# entries = 0, size = 0; |
| 120 | for (const auto &str : strings) { |
| 121 | if (omitEmpty &&cxx . . $ CppUtilities/`operator&&`(780fb9bd2d2dda6f). str.empty()) { |
| 122 | continue; |
| 123 | } |
| 124 | size +=cxx . . $ CppUtilities/`operator+=`(5671dc112b6671d4). str.size(); |
| 125 | ++entries; |
| 126 | } |
| 127 | if (!entries) { |
| 128 | return res; |
| 129 | } |
| 130 | size +=cxx . . $ CppUtilities/`operator+=`(5671dc112b6671d4). (entries * leftClosure.sizecxx . . $ std/basic_string_view#size(c9b1e749b64d5edc).()) + (entries * rightClosure.sizecxx . . $ std/basic_string_view#size(c9b1e749b64d5edc).()) + ((entries - 1) * delimiter.sizecxx . . $ std/basic_string_view#size(c9b1e749b64d5edc).()); |
| 131 | res.reserve(size); |
| 132 | for (const auto &str : strings) { |
| 133 | if (omitEmpty &&cxx . . $ CppUtilities/`operator&&`(780fb9bd2d2dda6f). str.empty()) { |
| 134 | continue; |
| 135 | } |
| 136 | if (!res.empty()) { |
| 137 | res.append(delimiter); |
| 138 | } |
| 139 | res.append(leftClosure); |
| 140 | res.append(str); |
| 141 | res.append(rightClosure); |
| 142 | } |
| 143 | return res; |
| 144 | } |
| 145 | |
| 146 | /*! |
| 147 | * \brief Converts the specified \a arrayOfLines to a multiline string. |
| 148 | */ |
| 149 | template <class Container = stdcxx . . $ std/::initializer_listcxx . . $ std/initializer_list#<stdcxx . . $ std/::stringcxx . . $ std/string#>> inline auto toMultilinecxx . . $ CppUtilities/toMultiline(1816565887c3e1da).(const Container &arrayOfLines) |
| 150 | { |
| 151 | return joinStringscxx . . $ CppUtilities/joinStrings(27d6fdf6f9f61b56).(arrayOfLines, "\n", false); |
| 152 | } |
| 153 | |
| 154 | /*! |
| 155 | * \brief Specifies the role of empty parts when splitting strings. |
| 156 | */ |
| 157 | enum class EmptyPartsTreatcxx . . $ CppUtilities/EmptyPartsTreat# { |
| 158 | Keepcxx . . $ CppUtilities/EmptyPartsTreat#Keep., /**< empty parts are kept */ |
| 159 | Omitcxx . . $ CppUtilities/EmptyPartsTreat#Omit., /**< empty parts are omitted */ |
| 160 | Mergecxx . . $ CppUtilities/EmptyPartsTreat#Merge. /**< empty parts are omitted but cause the adjacent parts being joined using the delimiter */ |
| 161 | }; |
| 162 | |
| 163 | /*! |
| 164 | * \brief Splits the given \a string at the specified \a delimiter. |
| 165 | * \param string The string to be split. |
| 166 | * \param delimiter Specifies the delimiter which must not be empty. |
| 167 | * \param emptyPartsRole Specifies the treatment of empty parts. |
| 168 | * \param maxParts Specifies the maximal number of parts. Values less or equal zero indicate an unlimited number of parts. |
| 169 | * \tparam Container The STL-container used to return the parts. |
| 170 | * \returns Returns the parts. |
| 171 | */ |
| 172 | template <class Container = stdcxx . . $ std/::listcxx . . $ std/__cxx11/list#<stdcxx . . $ std/::stringcxx . . $ std/string#>> |
| 173 | Container splitStringcxx . . $ CppUtilities/splitString(1ed638e56031d731).(Detailcxx . . $ CppUtilities/Detail/::StringParamForContainercxx . . $ CppUtilities/Detail/StringParamForContainer#<Container> string, Detailcxx . . $ CppUtilities/Detail/::StringParamForContainercxx . . $ CppUtilities/Detail/StringParamForContainer#<Container> delimiter, |
| 174 | EmptyPartsTreatcxx . . $ CppUtilities/EmptyPartsTreat# emptyPartsRole = EmptyPartsTreatcxx . . $ CppUtilities/EmptyPartsTreat#::Keepcxx . . $ CppUtilities/EmptyPartsTreat#Keep., int maxParts = -1) |
| 175 | { |
| 176 | --maxParts; |
| 177 | Container res; |
| 178 | typename Container::value_type *last = nullptr; |
| 179 | bool merge = false; |
| 180 | typename Container::value_type::size_type i = 0, end = string.sizecxx . . $ std/basic_string_view#size(c9b1e749b64d5edc).(); |
| 181 | for (typename Container::value_type::size_type delimPos; i < end; i = delimPos + delimiter.sizecxx . . $ std/basic_string_view#size(c9b1e749b64d5edc).()) { |
| 182 | delimPos = string.findcxx . . $ std/basic_string_view#find(214b8b5b4ec4b696).(delimiter, i); |
| 183 | if (!merge && maxParts >= 0 &&cxx . . $ CppUtilities/`operator&&`(780fb9bd2d2dda6f). res.size() == static_cast<typename Container::value_type::size_type>(maxParts)) { |
| 184 | if (delimPos == i &&cxx . . $ CppUtilities/`operator&&`(780fb9bd2d2dda6f). emptyPartsRole == EmptyPartsTreatcxx . . $ CppUtilities/EmptyPartsTreat#::Mergecxx . . $ CppUtilities/EmptyPartsTreat#Merge.) { |
| 185 | if (last) { |
| 186 | merge = true; |
| 187 | continue; |
| 188 | } |
| 189 | } |
| 190 | delimPos = Container::value_type::npos; |
| 191 | } |
| 192 | if (delimPos == Container::value_type::npos) { |
| 193 | delimPos = string.sizecxx . . $ std/basic_string_view#size(c9b1e749b64d5edc).(); |
| 194 | } |
| 195 | if (emptyPartsRole == EmptyPartsTreatcxx . . $ CppUtilities/EmptyPartsTreat#::Keepcxx . . $ CppUtilities/EmptyPartsTreat#Keep. || i != delimPos) { |
| 196 | if (merge) { |
| 197 | last->append(delimiter); |
| 198 | last->append(string, i, delimPos - i); |
| 199 | merge = false; |
| 200 | } else { |
| 201 | last = &cxx . . $ CppUtilities/`operator&`(f80f7d6260b3ee3a).res.emplace_back(string, i, delimPos - i); |
| 202 | } |
| 203 | } else if (emptyPartsRole == EmptyPartsTreatcxx . . $ CppUtilities/EmptyPartsTreat#::Mergecxx . . $ CppUtilities/EmptyPartsTreat#Merge.) { |
| 204 | if (last) { |
| 205 | merge = true; |
| 206 | } |
| 207 | } |
| 208 | } |
| 209 | if (i == end &&cxx . . $ CppUtilities/`operator&&`(780fb9bd2d2dda6f). emptyPartsRole == EmptyPartsTreatcxx . . $ CppUtilities/EmptyPartsTreat#::Keepcxx . . $ CppUtilities/EmptyPartsTreat#Keep.) { |
| 210 | res.emplace_back(); |
| 211 | } |
| 212 | return res; |
| 213 | } |
| 214 | |
| 215 | /*! |
| 216 | * \brief Splits the given \a string (which might also be a string view) at the specified \a delimiter. |
| 217 | * \param string The string to be split. |
| 218 | * \param delimiter Specifies the delimiter which must not be empty. |
| 219 | * \param maxParts Specifies the maximal number of parts. Values less or equal zero indicate an unlimited number of parts. |
| 220 | * \tparam Container The STL-container used to return the parts. |
| 221 | * \returns Returns the parts. |
| 222 | * \remarks This is a simplified version of splitString() where emptyPartsRole is always EmptyPartsTreat::Keep. |
| 223 | */ |
| 224 | template <class Container = stdcxx . . $ std/::listcxx . . $ std/__cxx11/list#<stdcxx . . $ std/::stringcxx . . $ std/string#>> |
| 225 | Container splitStringSimplecxx . . $ CppUtilities/splitStringSimple(31ac5907b7ebe93f).( |
| 226 | Detailcxx . . $ CppUtilities/Detail/::StringParamForContainercxx . . $ CppUtilities/Detail/StringParamForContainer#<Container> string, Detailcxx . . $ CppUtilities/Detail/::StringParamForContainercxx . . $ CppUtilities/Detail/StringParamForContainer#<Container> delimiter, int maxParts = -1) |
| 227 | { |
| 228 | --maxParts; |
| 229 | Container res; |
| 230 | typename Container::value_type::size_type i = 0, end = string.sizecxx . . $ std/basic_string_view#size(c9b1e749b64d5edc).(); |
| 231 | for (typename Container::value_type::size_type delimPos; i < end; i = delimPos + delimiter.sizecxx . . $ std/basic_string_view#size(c9b1e749b64d5edc).()) { |
| 232 | delimPos = string.findcxx . . $ std/basic_string_view#find(36b1ea5aa9fdc150).(delimiter, i); |
| 233 | if (maxParts >= 0 &&cxx . . $ CppUtilities/`operator&&`(780fb9bd2d2dda6f). res.size() == static_cast<typename Container::value_type::size_type>(maxParts)) { |
| 234 | delimPos = Container::value_type::npos; |
| 235 | } |
| 236 | if (delimPos == Container::value_type::npos) { |
| 237 | delimPos = string.sizecxx . . $ std/basic_string_view#size(c9b1e749b64d5edc).(); |
| 238 | } |
| 239 | #ifdef CPP_UTILITIES_USE_REQUIRES |
| 240 | if constexpr (requires { res.emplace_back(string); }) { |
| 241 | #endif |
| 242 | res.emplace_back(string.datacxx . . $ std/basic_string_view#data(8e614c7de0b1573e).() + i, delimPos - i); |
| 243 | #ifdef CPP_UTILITIES_USE_REQUIRES |
| 244 | } else { |
| 245 | res.emplace(string.data() + i, delimPos - i); |
| 246 | } |
| 247 | #endif |
| 248 | } |
| 249 | if (i == end) { |
| 250 | #ifdef CPP_UTILITIES_USE_REQUIRES |
| 251 | if constexpr (requires { res.emplace_back(); }) { |
| 252 | #endif |
| 253 | res.emplace_back(); |
| 254 | #ifdef CPP_UTILITIES_USE_REQUIRES |
| 255 | } else { |
| 256 | res.emplace(); |
| 257 | } |
| 258 | #endif |
| 259 | } |
| 260 | return res; |
| 261 | } |
| 262 | |
| 263 | /*! |
| 264 | * \brief Converts the specified \a multilineString to an array of lines. |
| 265 | */ |
| 266 | template <class Container = stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#>> inline auto toArrayOfLinescxx . . $ CppUtilities/toArrayOfLines(f1c9e758bb08f09f).(const stdcxx . . $ std/::stringcxx . . $ std/string# &multilineString) |
| 267 | { |
| 268 | return splitStringcxx . . $ CppUtilities/splitString(1ed638e56031d731).<Container>(multilineString, "\n", EmptyPartsTreatcxx . . $ CppUtilities/EmptyPartsTreat#::Keepcxx . . $ CppUtilities/EmptyPartsTreat#Keep.); |
| 269 | } |
| 270 | |
| 271 | /*! |
| 272 | * \brief Returns whether \a str starts with \a phrase. |
| 273 | */ |
| 274 | template <typename StringType> bool startsWithcxx . . $ CppUtilities/startsWith(9c67b3b6cbcd0cef).(const StringType &str, const StringType &phrase) |
| 275 | { |
| 276 | if (str.size() < phrase.size()) { |
| 277 | return false; |
| 278 | } |
| 279 | for (auto stri = str.cbegin(), strend = str.cend(), phrasei = phrase.cbegin(), phraseend = phrase.cend();; ++stri, ++phrasei) { |
| 280 | if (phrasei == phraseend) { |
| 281 | return true; |
| 282 | } else if (stri == strend) { |
| 283 | return false; |
| 284 | } else if (*stri != *phrasei) { |
| 285 | return false; |
| 286 | } |
| 287 | } |
| 288 | return false; |
| 289 | } |
| 290 | |
| 291 | /*! |
| 292 | * \brief Returns whether \a str starts with \a phrase. |
| 293 | */ |
| 294 | template <typename StringType> bool startsWithcxx . . $ CppUtilities/startsWith(6639d4c1a3a6e0a5).(const StringType &str, const typename StringType::value_type *phrase) |
| 295 | { |
| 296 | for (auto stri = str.cbegin(), strend = str.cend();; ++stri, ++phrase) { |
| 297 | if (!*phrase) { |
| 298 | return true; |
| 299 | } else if (stri == strend) { |
| 300 | return false; |
| 301 | } else if (*stri != *phrase) { |
| 302 | return false; |
| 303 | } |
| 304 | } |
| 305 | return false; |
| 306 | } |
| 307 | |
| 308 | /*! |
| 309 | * \brief Returns whether \a str ends with \a phrase. |
| 310 | */ |
| 311 | template <typename StringType> bool endsWithcxx . . $ CppUtilities/endsWith(9c67b3b6cbcd0cef).(const StringType &str, const StringType &phrase) |
| 312 | { |
| 313 | if (str.size() < phrase.size()) { |
| 314 | return false; |
| 315 | } |
| 316 | for (auto stri = str.cend() - static_cast<typename StringType::difference_type>(phrase.size()), strend = str.cend(), phrasei = phrase.cbegin(); |
| 317 | stri != strend; ++stri, ++phrasei) { |
| 318 | if (*stri != *phrasei) { |
| 319 | return false; |
| 320 | } |
| 321 | } |
| 322 | return true; |
| 323 | } |
| 324 | |
| 325 | /*! |
| 326 | * \brief Returns whether \a str ends with \a phrase. |
| 327 | */ |
| 328 | template <typename StringType> bool endsWithcxx . . $ CppUtilities/endsWith(6639d4c1a3a6e0a5).(const StringType &str, const typename StringType::value_type *phrase) |
| 329 | { |
| 330 | const auto phraseSize = stdcxx . . $ std/::strlen(phrase); |
| 331 | if (str.size() < phraseSize) { |
| 332 | return false; |
| 333 | } |
| 334 | for (auto stri = str.cend() - static_cast<typename StringType::difference_type>(phraseSize), strend = str.cend(); stri != strend; |
| 335 | ++stri, ++phrase) { |
| 336 | if (*stri != *phrase) { |
| 337 | return false; |
| 338 | } |
| 339 | } |
| 340 | return true; |
| 341 | } |
| 342 | |
| 343 | /*! |
| 344 | * \brief Returns whether \a str contains the specified \a substrings. |
| 345 | * \remarks The \a substrings must occur in the specified order. |
| 346 | */ |
| 347 | template <typename StringType> bool containsSubstringscxx . . $ CppUtilities/containsSubstrings(2d42295ca04526f).(const StringType &str, stdcxx . . $ std/::initializer_listcxx . . $ std/initializer_list#<StringType> substrings) |
| 348 | { |
| 349 | typename StringType::size_type currentPos = 0; |
| 350 | for (const auto &substr : substrings) { |
| 351 | if ((currentPos = str.find(substr, currentPos)) == StringType::npos) { |
| 352 | return false; |
| 353 | } |
| 354 | currentPos +=cxx . . $ CppUtilities/`operator+=`(5671dc112b6671d4). substr.size(); |
| 355 | } |
| 356 | return true; |
| 357 | } |
| 358 | |
| 359 | /*! |
| 360 | * \brief Returns whether \a str contains the specified \a substrings. |
| 361 | * \remarks The \a substrings must occur in the specified order. |
| 362 | */ |
| 363 | template <typename StringType> |
| 364 | bool containsSubstringscxx . . $ CppUtilities/containsSubstrings(4f9bc4d17c3a1c06).(const StringType &str, stdcxx . . $ std/::initializer_listcxx . . $ std/initializer_list#<const typename StringType::value_type *> substrings) |
| 365 | { |
| 366 | typename StringType::size_type currentPos = 0; |
| 367 | for (const auto *substr : substrings) { |
| 368 | if ((currentPos = str.find(substr, currentPos)) == StringType::npos) { |
| 369 | return false; |
| 370 | } |
| 371 | currentPos +=cxx . . $ CppUtilities/`operator+=`(5671dc112b6671d4). stdcxx . . $ std/::strlen(substr); |
| 372 | } |
| 373 | return true; |
| 374 | } |
| 375 | |
| 376 | /*! |
| 377 | * \brief Replaces all occurrences of \a find with \a relpace in the specified \a str. |
| 378 | */ |
| 379 | template <typename StringType1, typename StringType2, typename StringType3> |
| 380 | void findAndReplacecxx . . $ CppUtilities/findAndReplace(24c06d9c65e079c1).(StringType1 &str, const StringType2 &find, const StringType3 &replace) |
| 381 | { |
| 382 | for (typename StringType1::size_type i = 0; (i = str.find(find, i)) != StringType1::npos; i +=cxx . . $ CppUtilities/`operator+=`(5671dc112b6671d4). replace.size()) { |
| 383 | str.replace(i, find.size(), replace); |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | /*! |
| 388 | * \brief Replaces all occurrences of \a find with \a relpace in the specified \a str. |
| 389 | */ |
| 390 | template <typename StringType> |
| 391 | inline void findAndReplacecxx . . $ CppUtilities/findAndReplace(8e57d7adc94c9c31).(StringType &str, const typename StringType::value_type *find, const typename StringType::value_type *replace) |
| 392 | { |
| 393 | findAndReplacecxx . . $ CppUtilities/findAndReplace(8e57d7adc94c9c31).( |
| 394 | str, stdcxx . . $ std/::basic_string_viewcxx . . $ std/basic_string_view#<typename StringType::value_type>(find), stdcxx . . $ std/::basic_string_viewcxx . . $ std/basic_string_view#<typename StringType::value_type>(replace)); |
| 395 | } |
| 396 | |
| 397 | /*! |
| 398 | * \brief Replaces all occurrences of \a find with \a relpace in the specified \a str. |
| 399 | */ |
| 400 | template <typename StringType1, typename StringType2> |
| 401 | inline void findAndReplacecxx . . $ CppUtilities/findAndReplace(430d168ae052ce73).(StringType1 &str, const StringType2 &find, const typename StringType1::value_type *replace) |
| 402 | { |
| 403 | findAndReplacecxx . . $ CppUtilities/findAndReplace(24c06d9c65e079c1).(str, find, stdcxx . . $ std/::basic_string_viewcxx . . $ std/basic_string_view#<typename StringType1::value_type>(replace)); |
| 404 | } |
| 405 | |
| 406 | /*! |
| 407 | * \brief Replaces all occurrences of \a find with \a relpace in the specified \a str. |
| 408 | */ |
| 409 | template <typename StringType1, typename StringType2> |
| 410 | inline void findAndReplacecxx . . $ CppUtilities/findAndReplace(975e9e79d312474).(StringType1 &str, const typename StringType1::value_type *find, const StringType2 &replace) |
| 411 | { |
| 412 | findAndReplacecxx . . $ CppUtilities/findAndReplace(975e9e79d312474).(str, stdcxx . . $ std/::basic_string_viewcxx . . $ std/basic_string_view#<typename StringType1::value_type>(find), replace); |
| 413 | } |
| 414 | |
| 415 | /*! |
| 416 | * \brief Returns the character representation of the specified \a digit. |
| 417 | * \remarks |
| 418 | * - Uses capital letters. |
| 419 | * - Valid values for \a digit: 0 <= \a digit <= 35 |
| 420 | */ |
| 421 | template <typename CharType> constexpr CharType digitToCharcxx . . $ CppUtilities/digitToChar(ada6a8422704cf8a).(CharType digit) |
| 422 | { |
| 423 | return digit <= 9 ? (digit + '0') : (digit + 'A' - 10); |
| 424 | } |
| 425 | |
| 426 | /*! |
| 427 | * \brief Converts the given \a number to its equivalent string representation using the specified \a base. |
| 428 | * \tparam IntegralType The data type of the given number. |
| 429 | * \tparam StringType The string type (should be an instantiation of the basic_string class template). |
| 430 | * \sa stringToNumber() |
| 431 | */ |
| 432 | template <typename IntegralType, class StringType = stdcxx . . $ std/::stringcxx . . $ std/string#, typename BaseType = IntegralType, |
| 433 | CppUtilitiescxx . . $ CppUtilities/::Traitscxx . . $ CppUtilities/Traits/::EnableIfcxx . . $ CppUtilities/Traits/EnableIf#<stdcxx . . $ std/::is_integral<IntegralType>, stdcxx . . $ std/::is_unsigned<IntegralType>> * = nullptr> |
| 434 | StringType numberToStringcxx . . $ CppUtilities/numberToString(8fb462f70009e066).(IntegralType number, BaseType base = 10) |
| 435 | { |
| 436 | auto resSize = stdcxx . . $ std/::size_tcxx . . $ std/size_t#(); |
| 437 | auto n = number; |
| 438 | do { |
| 439 | n /= static_cast<IntegralType>(base), ++resSize; |
| 440 | } while (n); |
| 441 | auto res = StringType(resSize, typename StringType::value_type()); |
| 442 | auto resIter = res.end(); |
| 443 | do { |
| 444 | *(--resIter) |
| 445 | = digitToCharcxx . . $ CppUtilities/digitToChar(ada6a8422704cf8a).<typename StringType::value_type>(static_cast<typename StringType::value_type>(number % static_cast<IntegralType>(base))); |
| 446 | number /= static_cast<IntegralType>(base); |
| 447 | } while (number); |
| 448 | return res; |
| 449 | } |
| 450 | |
| 451 | /*! |
| 452 | * \brief Converts the given \a number to its equivalent string representation using the specified \a base. |
| 453 | * \tparam IntegralType The data type of the given number. |
| 454 | * \tparam StringType The string type (should be an instantiation of the basic_string class template). |
| 455 | * \sa stringToNumber() |
| 456 | */ |
| 457 | template <typename IntegralType, class StringType = stdcxx . . $ std/::stringcxx . . $ std/string#, typename BaseType = IntegralType, |
| 458 | Traitscxx . . $ CppUtilities/Traits/::EnableIfcxx . . $ CppUtilities/Traits/EnableIf#<stdcxx . . $ std/::is_integral<IntegralType>, stdcxx . . $ std/::is_signed<IntegralType>> * = nullptr> |
| 459 | StringType numberToStringcxx . . $ CppUtilities/numberToString(8fb462f70009e066).(IntegralType number, BaseType base = 10) |
| 460 | { |
| 461 | const auto negative = number < 0; |
| 462 | auto resSize = stdcxx . . $ std/::size_tcxx . . $ std/size_t#(); |
| 463 | if (negative) { |
| 464 | number = -number, resSize = 1; |
| 465 | } |
| 466 | auto n = number; |
| 467 | do { |
| 468 | n /= static_cast<IntegralType>(base), ++resSize; |
| 469 | } while (n); |
| 470 | auto res = StringType(resSize, typename StringType::value_type()); |
| 471 | auto resIter = res.end(); |
| 472 | do { |
| 473 | *(--resIter) |
| 474 | = digitToCharcxx . . $ CppUtilities/digitToChar(ada6a8422704cf8a).<typename StringType::value_type>(static_cast<typename StringType::value_type>(number % static_cast<IntegralType>(base))); |
| 475 | number /= static_cast<IntegralType>(base); |
| 476 | } while (number); |
| 477 | if (negative) { |
| 478 | *(--resIter) = '-'; |
| 479 | } |
| 480 | return res; |
| 481 | } |
| 482 | |
| 483 | /*! |
| 484 | * \brief Converts the given \a number to its equivalent string representation using the specified \a base. |
| 485 | * \tparam FloatingType The data type of the given number. |
| 486 | * \tparam StringType The string type (should be an instantiation of the basic_string class template). |
| 487 | * \remarks This function is using std::basic_stringstream internally and hence also has its limitations (eg. regarding |
| 488 | * \a base and types). |
| 489 | * \sa stringToNumber(), bufferToNumber() |
| 490 | */ |
| 491 | template <typename FloatingType, class StringType = stdcxx . . $ std/::stringcxx . . $ std/string#, Traitscxx . . $ CppUtilities/Traits/::EnableIfcxx . . $ CppUtilities/Traits/EnableIf#<stdcxx . . $ std/::is_floating_point<FloatingType>> * = nullptr> |
| 492 | StringType numberToStringcxx . . $ CppUtilities/numberToString(ec4d3bb249ff1650).(FloatingType number, int base = 10) |
| 493 | { |
| 494 | stdcxx . . $ std/::basic_stringstreamcxx . . $ std/__cxx11/basic_stringstream#<typename StringType::value_type> ss; |
| 495 | ss << stdcxx . . $ std/::setbasecxx . . $ std/setbase(c8f16a5d056b4979).(base) << number; |
| 496 | return ss.strcxx . . $ std/__cxx11/basic_stringstream#str(f82a3577bf86cf38).(); |
| 497 | } |
| 498 | |
| 499 | /*! |
| 500 | * \brief Returns number/digit of the specified \a character representation using the specified \a base. |
| 501 | * \throws A ConversionException will be thrown if the provided \a character does not represent a valid digit for the specified \a base. |
| 502 | */ |
| 503 | template <typename CharType> CharType charToDigitcxx . . $ CppUtilities/charToDigit(f80f7d6260b3ee3a).(CharType character, CharType base) |
| 504 | { |
| 505 | auto res = base; |
| 506 | if (character >= '0' &&cxx . . $ CppUtilities/`operator&&`(780fb9bd2d2dda6f). character <= '9') { |
| 507 | res = character - '0'; |
| 508 | } else if (character >= 'a' &&cxx . . $ CppUtilities/`operator&&`(780fb9bd2d2dda6f). character <= 'z') { |
| 509 | res = character - 'a' + 10; |
| 510 | } else if (character >= 'A' &&cxx . . $ CppUtilities/`operator&&`(780fb9bd2d2dda6f). character <= 'Z') { |
| 511 | res = character - 'A' + 10; |
| 512 | } |
| 513 | if (res < base) { |
| 514 | return res; |
| 515 | } |
| 516 | constexpr auto msgBegin = stdcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).::string_viewcxx . . $ std/string_view#("The character \""); |
| 517 | constexpr auto msgEnd = stdcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).::string_viewcxx . . $ std/string_view#("\" is no valid digit."); |
| 518 | auto errorMsg = stdcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).::stringcxx . . $ std/string#(); |
| 519 | errorMsg.reservecxx . . $ std/__cxx11/basic_string#reserve(9dac5f4bebd06212).(msgBegin.sizecxx . . $ std/basic_string_view#size(c9b1e749b64d5edc).() + msgEnd.sizecxx . . $ std/basic_string_view#size(c9b1e749b64d5edc).() + 2); |
| 520 | errorMsg +=cxx . . $ std/__cxx11/basic_string#`operator+=`(d07e3dd77f70328a). msgBegin; |
| 521 | errorMsg +=cxx . . $ CppUtilities/`operator+=`(5671dc112b6671d4). character >= ' ' &&cxx . . $ CppUtilities/`operator&&`(780fb9bd2d2dda6f). character <= '~' ? static_cast<stdcxx . . $ std/::stringcxx . . $ std/string#::value_typecxx . . $ std/__cxx11/basic_string#value_type#>(character) : '?'; |
| 522 | errorMsg +=cxx . . $ std/__cxx11/basic_string#`operator+=`(d07e3dd77f70328a). msgEnd; |
| 523 | throw ConversionExceptioncxx . . $ CppUtilities/ConversionException#ConversionException(36024da72fa271e1).(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(errorMsg)); |
| 524 | } |
| 525 | |
| 526 | /// \cond |
| 527 | namespace Detailcxx . . $ CppUtilities/Detail/ { |
| 528 | template <typename IntegralType, typename CharType, typename BaseType = IntegralType> |
| 529 | void raiseAndAddcxx . . $ CppUtilities/Detail/raiseAndAdd(ee4f409ca4beb690).(IntegralType &result, BaseType base, CharType character) |
| 530 | { |
| 531 | if (character == ' ') { |
| 532 | return; |
| 533 | } |
| 534 | #ifdef __GNUC__cxx . . $ `<built-in>:8:9`! // overflow detection only supported on GCC and Clang |
| 535 | if (__builtin_mul_overflow(result, base, &cxx . . $ CppUtilities/`operator&`(f80f7d6260b3ee3a).result) |
| 536 | || __builtin_add_overflow(result, charToDigitcxx . . $ CppUtilities/charToDigit(f80f7d6260b3ee3a).(character, static_cast<CharType>(base)), &cxx . . $ CppUtilities/`operator&`(f80f7d6260b3ee3a).result)) { |
| 537 | throw ConversionExceptioncxx . . $ CppUtilities/ConversionException#("Number exceeds limit."); |
| 538 | } |
| 539 | #else |
| 540 | result *= static_cast<IntegralType>(base); |
| 541 | result += static_cast<IntegralType>(charToDigit<CharType>(character, static_cast<CharType>(base))); |
| 542 | #endif |
| 543 | } |
| 544 | } // namespace Detail |
| 545 | /// \endcond |
| 546 | |
| 547 | /*! |
| 548 | * \brief Converts the given \a string of \a size characters to an unsigned numeric value using the specified \a base. |
| 549 | * \tparam IntegralType The data type used to store the converted value. |
| 550 | * \tparam CharType The character type. |
| 551 | * \throws A ConversionException will be thrown if the provided \a string is not a valid number. |
| 552 | * \sa numberToString(), stringToNumber() |
| 553 | */ |
| 554 | template <typename IntegralType, class CharType, typename BaseType = IntegralType, |
| 555 | Traitscxx . . $ CppUtilities/Traits/::EnableIfcxx . . $ CppUtilities/Traits/EnableIf#<stdcxx . . $ std/::is_integral<IntegralType>, stdcxx . . $ std/::is_unsigned<IntegralType>> * = nullptr> |
| 556 | IntegralType bufferToNumbercxx . . $ CppUtilities/bufferToNumber(7db6543ec3119d2c).(const CharType *string, stdcxx . . $ std/::size_tcxx . . $ std/size_t# size, BaseType base = 10) |
| 557 | { |
| 558 | IntegralType result = 0; |
| 559 | for (const CharType *end = string + size; string != end; ++string) { |
| 560 | Detailcxx . . $ CppUtilities/Detail/::raiseAndAddcxx . . $ CppUtilities/Detail/raiseAndAdd(ee4f409ca4beb690).(result, base, *string); |
| 561 | } |
| 562 | return result; |
| 563 | } |
| 564 | |
| 565 | /*! |
| 566 | * \brief Converts the given \a string of \a size characters to a signed numeric value using the specified \a base. |
| 567 | * \tparam IntegralType The data type used to store the converted value. |
| 568 | * \tparam CharType The character type. |
| 569 | * \throws A ConversionException will be thrown if the provided \a string is not a valid number. |
| 570 | * \sa numberToString(), stringToNumber() |
| 571 | */ |
| 572 | template <typename IntegralType, typename CharType, typename BaseType = IntegralType, |
| 573 | Traitscxx . . $ CppUtilities/Traits/::EnableIfcxx . . $ CppUtilities/Traits/EnableIf#<stdcxx . . $ std/::is_integral<IntegralType>, stdcxx . . $ std/::is_signed<IntegralType>> * = nullptr> |
| 574 | IntegralType bufferToNumbercxx . . $ CppUtilities/bufferToNumber(7db6543ec3119d2c).(const CharType *string, stdcxx . . $ std/::size_tcxx . . $ std/size_t# size, BaseType base = 10) |
| 575 | { |
| 576 | if (!size) { |
| 577 | return 0; |
| 578 | } |
| 579 | const CharType *end = string + size; |
| 580 | for (; string != end &&cxx . . $ CppUtilities/`operator&&`(780fb9bd2d2dda6f). *string == ' '; ++string) |
| 581 | ; |
| 582 | if (string == end) { |
| 583 | return 0; |
| 584 | } |
| 585 | const bool negative = (*string == '-'); |
| 586 | if (negative) { |
| 587 | ++string; |
| 588 | } |
| 589 | IntegralType result = 0; |
| 590 | for (; string != end; ++string) { |
| 591 | Detailcxx . . $ CppUtilities/Detail/::raiseAndAddcxx . . $ CppUtilities/Detail/raiseAndAdd(ee4f409ca4beb690).(result, base, *string); |
| 592 | } |
| 593 | return negative ? -result : result; |
| 594 | } |
| 595 | |
| 596 | /*! |
| 597 | * \brief Converts the given \a string to an unsigned/signed number assuming \a string uses the specified \a base. |
| 598 | * \tparam IntegralType The data type used to store the converted value. |
| 599 | * \tparam StringType The string type (should be an instantiation of the basic_string class template). |
| 600 | * \throws A ConversionException will be thrown if the provided \a string is not a valid number. |
| 601 | * \sa numberToString(), bufferToNumber() |
| 602 | */ |
| 603 | template <typename IntegralType, class StringType, typename BaseType = IntegralType, |
| 604 | Traitscxx . . $ CppUtilities/Traits/::EnableIfcxx . . $ CppUtilities/Traits/EnableIf#<stdcxx . . $ std/::is_integral<IntegralType>, Traitscxx . . $ CppUtilities/Traits/::Notcxx . . $ CppUtilities/Traits/Not#<stdcxx . . $ std/::is_scalar<stdcxx . . $ std/::decay_t<StringType>>>> * = nullptr> |
| 605 | IntegralType stringToNumbercxx . . $ CppUtilities/stringToNumber(478c46a825b2cbff).(const StringType &string, BaseType base = 10) |
| 606 | { |
| 607 | return bufferToNumbercxx . . $ CppUtilities/bufferToNumber(7db6543ec3119d2c).<IntegralType, typename StringType::value_type, BaseType>(string.data(), string.size(), base); |
| 608 | } |
| 609 | |
| 610 | /*! |
| 611 | * \brief Converts the given \a stringView to a number assuming \a stringView uses the specified \a base. |
| 612 | * \tparam FloatingType The data type used to store the converted value. |
| 613 | * \tparam StringViewType The string view type (must be an instantiation of the basic_string_view class template). |
| 614 | * \throws A ConversionException will be thrown if the provided \a string is not a valid number. |
| 615 | * \remarks This function is using std::basic_stringstream internally and hence also has its limitations (eg. regarding |
| 616 | * \a base and types). |
| 617 | * \sa numberToString(), bufferToNumber() |
| 618 | */ |
| 619 | template <typename FloatingType, class StringViewType, |
| 620 | Traitscxx . . $ CppUtilities/Traits/::EnableIfcxx . . $ CppUtilities/Traits/EnableIf#<stdcxx . . $ std/::is_floating_point<FloatingType>, Traitscxx . . $ CppUtilities/Traits/::IsSpecializationOfcxx . . $ CppUtilities/Traits/IsSpecializationOf#<StringViewType, stdcxx . . $ std/::basic_string_view>> * = nullptr> |
| 621 | FloatingType stringToNumbercxx . . $ CppUtilities/stringToNumber(ec310c037ec3e7b9).(StringViewType stringView, int base = 10) |
| 622 | { |
| 623 | stdcxx . . $ std/::basic_stringstreamcxx . . $ std/__cxx11/basic_stringstream#<typename StringViewType::value_type> ss; |
| 624 | ss << stdcxx . . $ std/::setbasecxx . . $ std/setbase(c8f16a5d056b4979).(base) << stringView; |
| 625 | FloatingType result; |
| 626 | if ((ss >> result) &&cxx . . $ CppUtilities/`operator&&`(780fb9bd2d2dda6f). ss.eofcxx . . $ std/basic_ios#eof(50ce9a9e25b4a850).()) { |
| 627 | return result; |
| 628 | } |
| 629 | stdcxx . . $ std/::stringcxx . . $ std/string# errorMsgcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).; |
| 630 | errorMsg.reservecxx . . $ std/__cxx11/basic_string#reserve(9dac5f4bebd06212).(48 + stringView.size()); |
| 631 | errorMsg +=cxx . . $ std/__cxx11/basic_string#`operator+=`(978ca1133b5f6e74). "The string \""; |
| 632 | errorMsg +=cxx . . $ CppUtilities/`operator+=`(5671dc112b6671d4). stringView; |
| 633 | errorMsg +=cxx . . $ std/__cxx11/basic_string#`operator+=`(978ca1133b5f6e74). "\" is no valid floating point number."; |
| 634 | throw ConversionExceptioncxx . . $ CppUtilities/ConversionException#ConversionException(36024da72fa271e1).(errorMsg); |
| 635 | } |
| 636 | |
| 637 | /*! |
| 638 | * \brief Converts the given \a string to a number assuming \a string uses the specified \a base. |
| 639 | * \tparam FloatingType The data type used to store the converted value. |
| 640 | * \tparam StringType The string type (should be an instantiation of the basic_string class template). |
| 641 | * \throws A ConversionException will be thrown if the provided \a string is not a valid number. |
| 642 | * \remarks This function is using std::basic_stringstream internally and hence also has its limitations (eg. regarding |
| 643 | * \a base and types). |
| 644 | * \sa numberToString(), bufferToNumber() |
| 645 | */ |
| 646 | template <typename FloatingType, class StringType, |
| 647 | Traitscxx . . $ CppUtilities/Traits/::EnableIfcxx . . $ CppUtilities/Traits/EnableIf#<stdcxx . . $ std/::is_floating_point<FloatingType>, Traitscxx . . $ CppUtilities/Traits/::Notcxx . . $ CppUtilities/Traits/Not#<stdcxx . . $ std/::is_scalar<stdcxx . . $ std/::decay_t<StringType>>>, |
| 648 | Traitscxx . . $ CppUtilities/Traits/::Notcxx . . $ CppUtilities/Traits/Not#<Traitscxx . . $ CppUtilities/Traits/::IsSpecializationOfcxx . . $ CppUtilities/Traits/IsSpecializationOf#<StringType, stdcxx . . $ std/::basic_string_view>>> * = nullptr> |
| 649 | FloatingType stringToNumbercxx . . $ CppUtilities/stringToNumber(3f0cdf043c811dec).(const StringType &string, int base = 10) |
| 650 | { |
| 651 | using StringViewTypecxx . . $ CppUtilities/stringToNumber(3f0cdf043c811dec).StringViewType# = stdcxx . . $ std/::basic_string_viewcxx . . $ std/basic_string_view#<typename StringType::value_type>; |
| 652 | return stringToNumbercxx . . $ CppUtilities/stringToNumber(3f0cdf043c811dec).<FloatingType, StringViewTypecxx . . $ CppUtilities/stringToNumber(3f0cdf043c811dec).StringViewType#>(StringViewTypecxx . . $ CppUtilities/stringToNumber(3f0cdf043c811dec).StringViewType#(string.data(), string.size()), base); |
| 653 | } |
| 654 | |
| 655 | /*! |
| 656 | * \brief Converts the given null-terminated \a string to an unsigned numeric value using the specified \a base. |
| 657 | * \tparam IntegralType The data type used to store the converted value. |
| 658 | * \tparam CharType The character type. |
| 659 | * \throws A ConversionException will be thrown if the provided \a string is not a valid number. |
| 660 | * \sa numberToString(), bufferToNumber() |
| 661 | */ |
| 662 | template <typename IntegralType, typename CharType, typename BaseType = IntegralType, |
| 663 | Traitscxx . . $ CppUtilities/Traits/::EnableIfcxx . . $ CppUtilities/Traits/EnableIf#<stdcxx . . $ std/::is_integral<IntegralType>, stdcxx . . $ std/::is_unsigned<IntegralType>> * = nullptr> |
| 664 | IntegralType stringToNumbercxx . . $ CppUtilities/stringToNumber(3e6807aaff63b24a).(const CharType *string, BaseType base = 10) |
| 665 | { |
| 666 | IntegralType result = 0; |
| 667 | for (; *string; ++string) { |
| 668 | Detailcxx . . $ CppUtilities/Detail/::raiseAndAddcxx . . $ CppUtilities/Detail/raiseAndAdd(ee4f409ca4beb690).(result, base, *string); |
| 669 | } |
| 670 | return result; |
| 671 | } |
| 672 | |
| 673 | /*! |
| 674 | * \brief Converts the given null-terminated \a string to a number assuming \a string uses the specified \a base. |
| 675 | * \tparam FloatingType The data type used to store the converted value. |
| 676 | * \tparam CharType The character type. |
| 677 | * \throws A ConversionException will be thrown if the provided \a string is not a valid number. |
| 678 | * \remarks This function is using std::basic_stringstream internally and hence also has its limitations (eg. regarding |
| 679 | * \a base and types). |
| 680 | * \sa numberToString(), bufferToNumber() |
| 681 | */ |
| 682 | template <typename FloatingType, class CharType, Traitscxx . . $ CppUtilities/Traits/::EnableIfcxx . . $ CppUtilities/Traits/EnableIf#<stdcxx . . $ std/::is_floating_point<FloatingType>> * = nullptr> |
| 683 | FloatingType stringToNumbercxx . . $ CppUtilities/stringToNumber(4447f5487656819e).(const CharType *string, int base = 10) |
| 684 | { |
| 685 | return stringToNumbercxx . . $ CppUtilities/stringToNumber(478c46a825b2cbff).<FloatingType, stdcxx . . $ std/::basic_string_viewcxx . . $ std/basic_string_view#<CharType>>(string, base); |
| 686 | } |
| 687 | |
| 688 | /*! |
| 689 | * \brief Converts the given null-terminated \a string to a signed numeric value using the specified \a base. |
| 690 | * \tparam IntegralType The data type used to store the converted value. |
| 691 | * \tparam CharType The character type. |
| 692 | * \throws A ConversionException will be thrown if the provided \a string is not a valid number. |
| 693 | * \sa numberToString(), bufferToNumber() |
| 694 | */ |
| 695 | template <typename IntegralType, typename CharType, typename BaseType = IntegralType, |
| 696 | Traitscxx . . $ CppUtilities/Traits/::EnableIfcxx . . $ CppUtilities/Traits/EnableIf#<stdcxx . . $ std/::is_integral<IntegralType>, stdcxx . . $ std/::is_signed<IntegralType>> * = nullptr> |
| 697 | IntegralType stringToNumbercxx . . $ CppUtilities/stringToNumber(495b91287a810dc5).(const CharType *string, IntegralType base = 10) |
| 698 | { |
| 699 | if (!*string) { |
| 700 | return 0; |
| 701 | } |
| 702 | for (; *string &&cxx . . $ CppUtilities/`operator&&`(780fb9bd2d2dda6f). *string == ' '; ++string) |
| 703 | ; |
| 704 | if (!*string) { |
| 705 | return 0; |
| 706 | } |
| 707 | const bool negative = (*string == '-'); |
| 708 | if (negative) { |
| 709 | ++string; |
| 710 | } |
| 711 | IntegralType result = 0; |
| 712 | for (; *string; ++string) { |
| 713 | Detailcxx . . $ CppUtilities/Detail/::raiseAndAddcxx . . $ CppUtilities/Detail/raiseAndAdd(ee4f409ca4beb690).(result, base, *string); |
| 714 | } |
| 715 | return negative ? -result : result; |
| 716 | } |
| 717 | |
| 718 | /*! |
| 719 | * \brief Interprets the given \a integer at the specified position as std::string using the specified byte order. |
| 720 | * |
| 721 | * Example: interpretation of ID3v2 frame IDs (stored as 32-bit integer) as string |
| 722 | * - 0x54495432/1414091826 will be interpreted as "TIT2". |
| 723 | * - 0x00545432/5526578 will be interpreted as "TT2" using start offset 1 to omit the first byte. |
| 724 | * |
| 725 | * \tparam T The data type of the integer to be interpreted. |
| 726 | */ |
| 727 | template <typename T> stdcxx . . $ std/::stringcxx . . $ std/string# interpretIntegerAsStringcxx . . $ CppUtilities/interpretIntegerAsString(9f38edc4b3b1607e).(T integer, int startOffset = 0) |
| 728 | { |
| 729 | char buffer[sizeof(T)]; |
| 730 | BEcxx . . $ CppUtilities/BE/::getBytescxx . . $ CppUtilities/BE/getBytes(b066d9ddbd24ee0b).(integer, buffer); |
| 731 | return stdcxx . . $ std/::stringcxx . . $ std/string#(buffer + startOffset, sizeof(T) - static_cast<stdcxx . . $ std/::size_tcxx . . $ std/size_t#>(startOffset)); |
| 732 | } |
| 733 | |
| 734 | CPP_UTILITIES_EXPORTcxx . . $ `global.h:11:9`! stdcxx . . $ std/::stringcxx . . $ std/string# dataSizeToStringcxx . . $ CppUtilities/dataSizeToString(6294d3b82760181d).(stdcxx . . $ std/::uint64_tcxx . . $ std/uint64_t# sizeInByte, bool includeByte = false); |
| 735 | CPP_UTILITIES_EXPORTcxx . . $ `global.h:11:9`! stdcxx . . $ std/::stringcxx . . $ std/string# bitrateToStringcxx . . $ CppUtilities/bitrateToString(47f9b21bd6629f82).(double speedInKbitsPerSecond, bool useByteInsteadOfBits = false); |
| 736 | CPP_UTILITIES_EXPORTcxx . . $ `global.h:11:9`! stdcxx . . $ std/::stringcxx . . $ std/string# encodeBase64cxx . . $ CppUtilities/encodeBase64(e95b56f114df2c56).(const stdcxx . . $ std/::uint8_tcxx . . $ std/uint8_t# *data, stdcxx . . $ std/::uint32_tcxx . . $ std/uint32_t# dataSize); |
| 737 | CPP_UTILITIES_EXPORTcxx . . $ `global.h:11:9`! stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<stdcxx . . $ std/::uint8_tcxx . . $ std/uint8_t#[]>, stdcxx . . $ std/::uint32_tcxx . . $ std/uint32_t#> decodeBase64cxx . . $ CppUtilities/decodeBase64(ae13223512d6be22).(const char *encodedStr, const stdcxx . . $ std/::uint32_tcxx . . $ std/uint32_t# strSize); |
| 738 | } // namespace CppUtilities |
| 739 | |
| 740 | #endif // CONVERSION_UTILITIES_STRINGCONVERSION_H |