Merge pull request #530 from mapbox/nunicode

use nunicode for language aware to_upper/to_lower string conversions
This commit is contained in:
Artem Pavlenko
2014-11-03 12:38:06 +00:00
3 changed files with 67 additions and 27 deletions

35
configure vendored
View File

@@ -19,20 +19,21 @@ trap finish EXIT
case ${MASON_PLATFORM} in
'ios')
SQLITE_VERSION=system
LIBUV_VERSION=0.10.28
ZLIB_VERSION=system
BOOST_VERSION=system
;;
SQLITE_VERSION=system
LIBUV_VERSION=0.10.28
ZLIB_VERSION=system
BOOST_VERSION=system
;;
*)
GLFW_VERSION=a21f2377
SQLITE_VERSION=system
LIBPNG_VERSION=1.6.13
LIBCURL_VERSION=system
LIBUV_VERSION=0.10.28
ZLIB_VERSION=system
BOOST_VERSION=system
;;
GLFW_VERSION=a21f2377
SQLITE_VERSION=system
LIBPNG_VERSION=1.6.13
LIBCURL_VERSION=system
LIBUV_VERSION=0.10.28
ZLIB_VERSION=system
BOOST_VERSION=system
NUNICODE_VERSION=1.4
;;
esac
function abort { >&2 echo -e "\033[1m\033[31m$1\033[0m"; exit 1; }
@@ -111,6 +112,14 @@ if [ ! -z ${ZLIB_VERSION} ]; then
CONFIG+=" 'zlib_ldflags': $(quote_flags $(mason ldflags zlib ${ZLIB_VERSION})),"$LN
fi
if [ ! -z ${NUNICODE_VERSION} ]; then
mason install nunicode ${NUNICODE_VERSION}
CONFIG+=" 'nu_static_libs': $(quote_flags $(mason static_libs nunicode ${NUNICODE_VERSION})),"$LN
CONFIG+=" 'nu_cflags': $(quote_flags $(mason cflags nunicode ${NUNICODE_VERSION})),"$LN
CONFIG+=" 'nu_ldflags': $(quote_flags $(mason ldflags nunicode ${NUNICODE_VERSION})),"$LN
fi
CONFIG+=" }
}
"

View File

@@ -10,14 +10,17 @@
'<@(png_cflags)',
'<@(uv_cflags)',
'<@(curl_cflags)',
'<@(nu_cflags)',
],
'cflags': [
'<@(uv_cflags)',
'<@(nu_cflags)',
],
'ldflags': [
'<@(png_ldflags)',
'<@(uv_ldflags)',
'<@(curl_ldflags)',
'<@(nu_ldflags)',
],
},
'sources': [

View File

@@ -1,24 +1,52 @@
#include <mbgl/platform/platform.hpp>
#include <locale>
#include <mbgl/util/utf.hpp>
#define NU_WITH_TOUPPER
#define NU_WITH_TOLOWER
#define NU_WITH_UTF8_WRITER
#include <libnu/libnu.h>
#include <cstring>
namespace mbgl {
namespace platform {
std::string uppercase(const std::string& string) {
// TODO: Use a proper Unicode Special Casing-aware algorithm.
const auto &convert = std::use_facet<std::ctype<char>>(std::locale());
std::string converted = string;
convert.toupper(&converted[0], &converted[0] + converted.size());
return converted;
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)
{
char const* up = nu_toupper(*itr);
if (up != 0) output.append(up);
else
{
std::memset(buf, 0, 5);
nu_utf8_write(*itr, buf);
output.append(buf);
}
}
return output;
}
std::string lowercase(const std::string& string) {
// TODO: Use a proper Unicode Special Casing-aware algorithm.
const auto &convert = std::use_facet<std::ctype<char>>(std::locale());
std::string converted = string;
convert.tolower(&converted[0], &converted[0] + converted.size());
return converted;
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)
{
char const* lo = nu_tolower(*itr);
if (lo != 0) output.append(lo);
else
{
std::memset(buf, 0, 5);
nu_utf8_write(*itr, buf);
output.append(buf);
}
}
return output;
}
}