[Cppcms-users] Questions about decode UTF-8 to Unicode code point
Brought to you by:
artyom-beilis
|
From: 陈抒 <csf...@gm...> - 2013-02-05 15:33:21
|
Hello Artyom:
I am using the boost.locale library contributed by you to decode UTF-8.
The following codes works fine:
char const * p = "一"; // one Chinese character here
code_point c = utf_traits<char, sizeof(char)>::decode(p, p + 3);
cout << "code point: 0x" << std::hex << c << " binary format:B" <<
PrintIntAsBinaryString(c) << endl;
My Print.. function prints it as what I expect.
code point: 0x4e00 binary format:B00000000000000000100111000000000
But don't know how to apply the decode function to std::string. when using
iterator of string object, got some compilation error:
string str = "一";
code_point c = utf_traits<char, sizeof(char)>::decode(str.begin(),
str.end());
/home/chenshu/work/asio_echo/codes/main/test/main.cc:18:65: error: no
matching function for call to
‘boost::locale::utf::utf_traits<char>::decode(std::basic_string<char>::iterator,
std::basic_string<char>::iterator)’
/home/chenshu/work/asio_echo/codes/main/test/main.cc:18:65: note: candidate
is:
/usr/include/boost/locale/utf.hpp:193:27: note: static
boost::locale::utf::code_point boost::locale::utf::utf_traits<CharType,
1>::decode(Iterator&, Iterator) [with Iterator =
__gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, CharType =
char, boost::locale::utf::code_point = unsigned int]
/usr/include/boost/locale/utf.hpp:193:27: note: no known conversion for
argument 1 from ‘std::basic_string<char>::iterator {aka
__gnu_cxx::__normal_iterator<char*, std::basic_string<char> >}’ to
‘__gnu_cxx::__normal_iterator<char*, std::basic_string<char> >&’
make[2]: *** [test_bin/CMakeFiles/util_test.dir/main.cc.o] Error 1
make[1]: *** [test_bin/CMakeFiles/util_test.dir/all] Error 2
make: *** [all] Error 2
The above is my first question, that's about converting one single Unicode
character.
Another question is how to decode all Unicode code points from string
object?
陈抒
Best regards
http://blog.csdn.net/sheismylife
|