diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2018-12-13 18:45:29 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2018-12-13 20:39:43 +0100 |
commit | 2049ff09c2b41a5ccff693a4a64e517d47a08e4a (patch) | |
tree | 25b8f9acdb5e1b6629293bcc6f014ea4bcb6d1a3 /platform/default/src/mbgl/util/string_stdlib.cpp | |
parent | b6b1067caf6ba911efbb4a64a43425ce2d729a1a (diff) | |
download | qtlocation-mapboxgl-upstream/build-changes.tar.gz |
[build] rework platform/default directory and add -files.txt for vendored libsupstream/build-changes
Diffstat (limited to 'platform/default/src/mbgl/util/string_stdlib.cpp')
-rw-r--r-- | platform/default/src/mbgl/util/string_stdlib.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/platform/default/src/mbgl/util/string_stdlib.cpp b/platform/default/src/mbgl/util/string_stdlib.cpp new file mode 100644 index 0000000000..103444df1c --- /dev/null +++ b/platform/default/src/mbgl/util/string_stdlib.cpp @@ -0,0 +1,74 @@ +#include <mbgl/util/platform.hpp> +#include <libnu/casemap.h> +#include <cstring> +#include <sstream> + +namespace mbgl { namespace platform { + +std::string uppercase(const std::string& str) +{ + std::stringstream output; + char const *itr = str.c_str(), *nitr; + char const *end = itr + str.length(); + char lo[5] = { 0 }; + + for (; itr < end; itr = nitr) + { + uint32_t code_point = 0; + char const* buf = nullptr; + + nitr = _nu_toupper(itr, end, nu_utf8_read, &code_point, &buf, nullptr); + if (buf != nullptr) + { + do + { + buf = NU_CASEMAP_DECODING_FUNCTION(buf, &code_point); + if (code_point == 0) break; + output.write(lo, nu_utf8_write(code_point, lo) - lo); + } + while (code_point != 0); + } + else + { + output.write(itr, nitr - itr); + } + } + + return output.str(); + +} + +std::string lowercase(const std::string& str) +{ + std::stringstream output; + char const *itr = str.c_str(), *nitr; + char const *end = itr + str.length(); + char lo[5] = { 0 }; + + for (; itr < end; itr = nitr) + { + uint32_t code_point = 0; + char const* buf = nullptr; + + nitr = _nu_tolower(itr, end, nu_utf8_read, &code_point, &buf, nullptr); + if (buf != nullptr) + { + do + { + buf = NU_CASEMAP_DECODING_FUNCTION(buf, &code_point); + if (code_point == 0) break; + output.write(lo, nu_utf8_write(code_point, lo) - lo); + } + while (code_point != 0); + } + else + { + output.write(itr, nitr - itr); + } + } + + return output.str(); +} + +} // namespace platform +} // namespace mbgl |