summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtem Pavlenko <artemp@users.noreply.github.com>2014-11-27 18:24:08 +0100
committerArtem Pavlenko <artemp@users.noreply.github.com>2014-11-27 18:24:08 +0100
commitd5fee5d71655d5d272c512c1157e42a8f391a665 (patch)
tree18386b86bbc2f864ea4176e18373e7cd4038d147
parent79017060947c1a11f4124ab837bd171b748806de (diff)
parent2586cfb9e305ce2da39fb06af62d71a911fbfba4 (diff)
downloadqtlocation-mapboxgl-d5fee5d71655d5d272c512c1157e42a8f391a665.tar.gz
Merge pull request #657 from mapbox/nunicode
Nunicode
-rwxr-xr-xconfigure2
-rw-r--r--platform/default/string_stdlib.cpp75
-rw-r--r--test/text_conversions.cpp4
3 files changed, 51 insertions, 30 deletions
diff --git a/configure b/configure
index b0a5e5332c..08b972b056 100755
--- a/configure
+++ b/configure
@@ -33,7 +33,7 @@ case ${MASON_PLATFORM} in
LIBUV_VERSION=0.10.28
ZLIB_VERSION=system
BOOST_VERSION=system
- NUNICODE_VERSION=1.4
+ NUNICODE_VERSION=1.5-dev
;;
esac
diff --git a/platform/default/string_stdlib.cpp b/platform/default/string_stdlib.cpp
index 9639cd7b99..ac4c26234c 100644
--- a/platform/default/string_stdlib.cpp
+++ b/platform/default/string_stdlib.cpp
@@ -6,48 +6,71 @@
#include <libnu/libnu.h>
#include <cstring>
-namespace mbgl {
-namespace platform {
+namespace mbgl { namespace platform {
std::string uppercase(const std::string& 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)
{
- 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* lo = nu_tolower(*itr);
- if (lo != 0) output.append(lo);
+ uint32_t code_point = 0;
+ char const* buf = 0;
+
+ 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(buf, 0, 5);
- nu_utf8_write(*itr, buf);
- output.append(buf);
+ output.write(itr, nitr - itr);
}
}
- return output;
-}
+ return output.str();
}
-}
+
+}}
diff --git a/test/text_conversions.cpp b/test/text_conversions.cpp
index 4f71d6a61d..756bc4db1f 100644
--- a/test/text_conversions.cpp
+++ b/test/text_conversions.cpp
@@ -30,8 +30,6 @@ TEST(TextConversions, to_lower) {
EXPECT_EQ(std::string("weisskopfseeadler"), platform::lowercase("weiSSkopfseeadler")); // DE
EXPECT_EQ(std::string("azərbaycan"), platform::lowercase("AZƏRBAYCAN")); // AZ
-
- //EXPECT_EQ(std::string("ὀδυσσεύσ"), platform::lowercase("ὈΔΥΣΣΕΎΣ")); // GR
- // nunicode can't map last Σ to word-ending ς
+ EXPECT_EQ(std::string("ὀδυσσεύς"), platform::lowercase("ὈΔΥΣΣΕΎΣ")); // GR
}