fix i18n issue

This commit is contained in:
Jinhao 2016-12-13 07:21:18 +08:00
parent 77ffb71369
commit 1d37c86e1c

View File

@ -41,7 +41,7 @@ namespace nana
class tokenizer class tokenizer
{ {
public: public:
tokenizer(const std::string& file) tokenizer(const std::string& file, bool utf8)
{ {
std::ifstream ifs(file.data(), std::ios::binary); std::ifstream ifs(file.data(), std::ios::binary);
if (ifs) if (ifs)
@ -54,6 +54,11 @@ namespace nana
data_.reset(new char[len]); data_.reset(new char[len]);
ifs.read(data_.get(), len); ifs.read(data_.get(), len);
read_ptr_ = data_.get(); read_ptr_ = data_.get();
if (utf8 && len > 3)
{
if (static_cast<unsigned char>(read_ptr_[0]) == 0xEF && static_cast<unsigned char>(read_ptr_[1]) == 0xBB && static_cast<unsigned char>(read_ptr_[2]) == 0xBF)
read_ptr_ += 3;
}
end_ptr_ = read_ptr_ + len; end_ptr_ = read_ptr_ + len;
} }
} }
@ -205,7 +210,7 @@ namespace nana
{ {
auto impl = std::make_shared<data>(); auto impl = std::make_shared<data>();
tokenizer tknizer(file); tokenizer tknizer(file, utf8);
while (true) while (true)
{ {
if (token::msgid != tknizer.read()) if (token::msgid != tknizer.read())
@ -226,9 +231,9 @@ namespace nana
std::string str; std::string str;
if (utf8) if (utf8)
str = nana::charset(std::move(tknizer.get_str()), nana::unicode::utf8); str = tknizer.get_str();
else else
str = nana::charset(std::move(tknizer.get_str())); str = nana::charset(std::move(tknizer.get_str())).to_bytes(nana::unicode::utf8);
std::string::size_type pos = 0; std::string::size_type pos = 0;
while (true) while (true)