use nunicode for proper to_upper/to_lower string conversions
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user