use nunicode for proper to_upper/to_lower string conversions

This commit is contained in:
artemp
2014-10-31 14:43:46 -04:00
parent 15cf30652c
commit ea2416c7cf
3 changed files with 68 additions and 28 deletions

38
configure vendored
View File

@@ -37,21 +37,23 @@ alias mason='~/.mason/mason'
case $MASON_PLATFORM in
'ios')
SQLITE_VERSION=system
LIBPNG_VERSION=1.6.13
LIBUV_VERSION=0.10.28
ZLIB_VERSION=system
BOOST_VERSION=system
;;
SQLITE_VERSION=system
LIBPNG_VERSION=1.6.13
LIBUV_VERSION=0.10.28
ZLIB_VERSION=system
BOOST_VERSION=system
NUNICODE_VERSION=1.4
;;
*)
GLFW_VERSION=a21f2377
SQLITE_VERSION=system
LIBPNG_VERSION=system
LIBCURL_VERSION=system
LIBUV_VERSION=0.10.28
ZLIB_VERSION=system
BOOST_VERSION=system
;;
GLFW_VERSION=a21f2377
SQLITE_VERSION=system
LIBPNG_VERSION=system
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; }
@@ -138,6 +140,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

@@ -9,13 +9,16 @@
'cflags_cc': [
'<@(uv_cflags)',
'<@(curl_cflags)',
'<@(nu_cflags)',
],
'cflags': [
'<@(uv_cflags)',
'<@(nu_cflags)',
],
'ldflags': [
'<@(uv_ldflags)',
'<@(curl_ldflags)',
'<@(nu_ldflags)',
],
},
'sources': [

View File

@@ -1,24 +1,51 @@
#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>
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[4];
for (; itr!=end; ++itr)
{
char const* up = nu_toupper(*itr);
if (up != 0) output.append(up);
else
{
std::memset(buf, 0, 4);
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[4];
for (; itr!=end; ++itr)
{
char const* up = nu_tolower(*itr);
if (up != 0) output.append(up);
else
{
std::memset(buf, 0, 4);
nu_utf8_write(*itr, buf);
output.append(buf);
}
}
return output;
}
}