summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorartemp <artem@mapnik.org>2014-11-17 18:15:48 +0100
committerartemp <artem@mapnik.org>2014-11-17 18:15:48 +0100
commitb9ebe1622420d628d85c2ce26abaac59701b99f4 (patch)
treec02862de8fdfb4fff52b51e4bbbbd6a08f5da74e
parent66d64c7c12648b3f15181eb9d64e55d1a23ade34 (diff)
downloadqtlocation-mapboxgl-b9ebe1622420d628d85c2ce26abaac59701b99f4.tar.gz
correct _nu_tolower/_nu_toupper usage
-rw-r--r--platform/default/string_stdlib.cpp80
1 files changed, 50 insertions, 30 deletions
diff --git a/platform/default/string_stdlib.cpp b/platform/default/string_stdlib.cpp
index 3b89a45043..ba55542208 100644
--- a/platform/default/string_stdlib.cpp
+++ b/platform/default/string_stdlib.cpp
@@ -6,51 +6,71 @@
#include <libnu/libnu.h>
#include <cstring>
-namespace mbgl {
-namespace platform {
+namespace mbgl { namespace platform {
-std::string uppercase(const std::string& str)
+std::string uppercase(std::string const& str)
{
- boost::u8_to_u32_iterator<std::string::const_iterator> itr(str.begin());
- boost::u8_to_u32_iterator<std::string::const_iterator> end(str.end());
- std::string output;
- char buf[5];
- for (; itr!=end; ++itr)
+ std::stringstream output;
+ char const *itr = str.c_str(), *nitr = itr;
+ char const *end = itr + str.length();
+ char lo[5] = { 0 };
+
+ for (; itr < end; itr = nitr)
{
- char const* up = nu_toupper(*itr);
- if (up != 0) output.append(up);
+ uint32_t code_point = 0;
+ char const* buf = 0;
+
+ nitr = _nu_toupper(itr, end, nu_utf8_read, &code_point, &buf, 0);
+ if (buf != 0)
+ {
+ 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
{
- std::memset(buf, 0, 5);
- nu_utf8_write(*itr, buf);
- output.append(buf);
+ output.write(itr, nitr - itr);
}
}
- return output;
+
+ return output.str();
+
}
-std::string lowercase(const std::string& str)
+std::string lowercase(std::string const& str)
{
- std::string output;
- char lo[5];
- char const* itr = str.c_str();
- char const* end = itr + str.length();
- char const* buf = 0;
- uint32_t code_point;
- for ( ; itr!=end;)
+ std::stringstream output;
+ char const *itr = str.c_str(), *nitr = itr;
+ char const *end = itr + str.length();
+ char lo[5] = { 0 };
+
+ for (; itr < end; itr = nitr)
{
+ uint32_t code_point = 0;
+ char const* buf = 0;
- itr = _nu_tolower(itr, end, nu_utf8_read, &code_point, &buf, 0);
- if (buf != 0) output.append(buf);
+ nitr = _nu_tolower(itr, end, nu_utf8_read, &code_point, &buf, 0);
+ if (buf != 0)
+ {
+ 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
{
- std::memset(lo, 0, 5);
- nu_utf8_write(code_point, lo);
- output.append(lo);
+ output.write(itr, nitr - itr);
}
}
- return output;
-}
+ return output.str();
}
-}
+
+}}