Thread: [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
|
|
From: Artyom B. <art...@ya...> - 2013-02-05 16:20:59
|
First of all there is utf_to_utf functions and if sizeof(wchar_t) == 4 (which is on Linux/Unix) than all you need is to use them. About the error code_point c = utf_traits<char, sizeof(char)>::decode(str.begin(), str.end()); the first parameter is reference that is moved forward and std.begin() can't be changed so what you need to do is: std::string::const_iterator pos = std.begin(),end =str.end(); code_point c = utf_traits<char, sizeof(char)>::decode(pos,end ); See: http://www.boost.org/doc/libs/1_51_0/libs/locale/doc/html/structboost_1_1locale_1_1utf_1_1utf__traits.html#a65f0b0e1075dd000d2c2c15af30be372 Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ >________________________________ > From: 陈抒 <csf...@gm...> >To: cpp...@li... >Sent: Tuesday, February 5, 2013 5:32 PM >Subject: [Cppcms-users] Questions about decode UTF-8 to Unicode code point > > >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 >------------------------------------------------------------------------------ >Free Next-Gen Firewall Hardware Offer >Buy your Sophos next-gen firewall before the end March 2013 >and get the hardware for free! Learn more. >http://p.sf.net/sfu/sophos-d2d-feb >_______________________________________________ >Cppcms-users mailing list >Cpp...@li... >https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > |
|
From: 陈抒 <csf...@gm...> - 2013-06-08 15:53:08
|
Hello Artyom: I know the code_point type is uint32_t. In my app, I need to convert it into uint16_t. Which one of the following ways is portable and don't need to worry about the endianness(big-endian or little-endian), also can be used in both 32bit and 64bit platform. I am using GCC4.x above. Assume x is a code_point value 1. static_cast<uint16_t>(x) 2. x & 0xffff Correct me if I am wrong, thanks. Dean Chen Best regards http://blog.csdn.net/sheismylife On Wed, Feb 6, 2013 at 12:20 AM, Artyom Beilis <art...@ya...> wrote: > First of all there is utf_to_utf functions and if sizeof(wchar_t) == 4 > (which is on Linux/Unix) > than all you need is to use them. > > About the error > > code_point c = utf_traits<char, sizeof(char)>::decode(str.begin(), > str.end()); > > the first parameter is reference that is moved forward and std.begin() > can't be changed > so what you need to do is: > > std::string::const_iterator pos = std.begin(),end =str.end(); > code_point c = utf_traits<char, sizeof(char)>::decode(pos,end ); > > See: > http://www.boost.org/doc/libs/1_51_0/libs/locale/doc/html/structboost_1_1locale_1_1utf_1_1utf__traits.html#a65f0b0e1075dd000d2c2c15af30be372 > > Artyom Beilis > -------------- > CppCMS - C++ Web Framework: http://cppcms.com/ > CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ > > ------------------------------ > *From:* 陈抒 <csf...@gm...> > *To:* cpp...@li... > *Sent:* Tuesday, February 5, 2013 5:32 PM > *Subject:* [Cppcms-users] Questions about decode UTF-8 to Unicode code > point > > 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 > > > ------------------------------------------------------------------------------ > Free Next-Gen Firewall Hardware Offer > Buy your Sophos next-gen firewall before the end March 2013 > and get the hardware for free! Learn more. > http://p.sf.net/sfu/sophos-d2d-feb > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > > > ------------------------------------------------------------------------------ > Free Next-Gen Firewall Hardware Offer > Buy your Sophos next-gen firewall before the end March 2013 > and get the hardware for free! Learn more. > http://p.sf.net/sfu/sophos-d2d-feb > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > > |
|
From: Artyom B. <art...@ya...> - 2013-06-09 06:30:02
|
There is a set of functions: booster::locale::conv::utf_to_utf http://www.boost.org/doc/libs/1_53_0/libs/locale/doc/html/group__codepage.html#gaf0ad39959911b000706e0538ec059d44 All you need it to do is to convert UTF-32 to UTF-16 or UTF-8 to UTF-16. Also cast to uint16_t is INCORRECT is it would fail on characters outside of BMP - i.e. characters that are encoded as two units sequence in UTF-16 (so called surrogate pairs) Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ >________________________________ > From: 陈抒 <csf...@gm...> >To: Artyom Beilis <art...@ya...>; "cpp...@li..." <cpp...@li...> >Sent: Saturday, June 8, 2013 6:52 PM >Subject: Re: [Cppcms-users] Questions about decode UTF-8 to Unicode code point > > > >Hello Artyom: > I know the code_point type is uint32_t. In my app, I need to convert it into uint16_t. Which one of the following ways is portable and don't need to worry about the endianness(big-endian or little-endian), also can be used in both 32bit and 64bit platform. I am using GCC4.x above. >Assume x is a code_point value >1. static_cast<uint16_t>(x) >2. x & 0xffff > > >Correct me if I am wrong, thanks. > > > > >Dean Chen >Best regards >http://blog.csdn.net/sheismylife > > >On Wed, Feb 6, 2013 at 12:20 AM, Artyom Beilis <art...@ya...> wrote: > >First of all there is utf_to_utf functions and if sizeof(wchar_t) == 4 (which is on Linux/Unix) >>than all you need is to use them. >> >> >>About the error >> >> >>code_point c = utf_traits<char, sizeof(char)>::decode(str.begin(), str.end()); >> >> >> >>the first parameter is reference that is moved forward and std.begin() can't be changed >>so what you need to do is: >> >> >> >>std::string::const_iterator pos = std.begin(),end =str.end(); >>code_point c = utf_traits<char, sizeof(char)>::decode(pos,end ); >> >> >> >>See: http://www.boost.org/doc/libs/1_51_0/libs/locale/doc/html/structboost_1_1locale_1_1utf_1_1utf__traits.html#a65f0b0e1075dd000d2c2c15af30be372 >> >>Artyom Beilis >>-------------- >>CppCMS - C++ Web Framework: http://cppcms.com/ >>CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ >> >> >> >>>________________________________ >>> From: 陈抒 <csf...@gm...> >>>To: cpp...@li... >>>Sent: Tuesday, February 5, 2013 5:32 PM >>>Subject: [Cppcms-users] Questions about decode UTF-8 to Unicode code point >>> >>> >>> >>>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 >>>------------------------------------------------------------------------------ >>>Free Next-Gen Firewall Hardware Offer >>>Buy your Sophos next-gen firewall before the end March 2013 >>>and get the hardware for free! Learn more. >>>http://p.sf.net/sfu/sophos-d2d-feb >>>_______________________________________________ >>>Cppcms-users mailing list >>>Cpp...@li... >>>https://lists.sourceforge.net/lists/listinfo/cppcms-users >>> >>> >>> >>------------------------------------------------------------------------------ >>Free Next-Gen Firewall Hardware Offer >>Buy your Sophos next-gen firewall before the end March 2013 >>and get the hardware for free! Learn more. >>http://p.sf.net/sfu/sophos-d2d-feb >>_______________________________________________ >>Cppcms-users mailing list >>Cpp...@li... >>https://lists.sourceforge.net/lists/listinfo/cppcms-users >> >> > > > |
|
From: 陈抒 <csf...@gm...> - 2013-06-12 13:56:18
|
Thank you, Artyom. In my application, we just need to handle the characters in BMP. So I think casting it to uint16_t is okay. And what I want to get is just code point, not another encoding format, i.e. UTF-16 or others. After read the UTF-16, I know the value of it is equal to code point, but its width is 1 or 2 bytes. I will try your suggested way later. Another question, when looking into the codes of utf.hpp, I find the following codes for case 3, 2, 1 are identical, why? 00213 code_point <http://www.boost.org/doc/libs/1_53_0/libs/locale/doc/html/namespaceboost_1_1locale_1_1utf.html#a068111a6b9d6d465a63893ed5c05e2f8> c = lead & ((1<<(6-trail_size))-1);00214 00215 // Read the rest00216 unsigned char tmp;00217 switch(trail_size) {00218 case 3:00219 if(BOOST_LOCALE_UNLIKELY(p==e))00220 return incomplete <http://www.boost.org/doc/libs/1_53_0/libs/locale/doc/html/namespaceboost_1_1locale_1_1utf.html#a20dbe458fd18229a0e6c09888d031b38>;00221 tmp = *p++;00222 if (!is_trail <http://www.boost.org/doc/libs/1_53_0/libs/locale/doc/html/structboost_1_1locale_1_1utf_1_1utf__traits.html#ae2cb78fcb8a58bed3e0ce1d6528a719a>(tmp))00223 return illegal <http://www.boost.org/doc/libs/1_53_0/libs/locale/doc/html/namespaceboost_1_1locale_1_1utf.html#a30010000878c7732340bda8956b844fb>;00224 c = (c << 6) | ( tmp & 0x3F);00225 case 2:00226 if(BOOST_LOCALE_UNLIKELY(p==e))00227 return incomplete <http://www.boost.org/doc/libs/1_53_0/libs/locale/doc/html/namespaceboost_1_1locale_1_1utf.html#a20dbe458fd18229a0e6c09888d031b38>;00228 tmp = *p++;00229 if (!is_trail <http://www.boost.org/doc/libs/1_53_0/libs/locale/doc/html/structboost_1_1locale_1_1utf_1_1utf__traits.html#ae2cb78fcb8a58bed3e0ce1d6528a719a>(tmp))00230 return illegal <http://www.boost.org/doc/libs/1_53_0/libs/locale/doc/html/namespaceboost_1_1locale_1_1utf.html#a30010000878c7732340bda8956b844fb>;00231 c = (c << 6) | ( tmp & 0x3F);00232 case 1:00233 if(BOOST_LOCALE_UNLIKELY(p==e))00234 return incomplete <http://www.boost.org/doc/libs/1_53_0/libs/locale/doc/html/namespaceboost_1_1locale_1_1utf.html#a20dbe458fd18229a0e6c09888d031b38>;00235 tmp = *p++;00236 if (!is_trail <http://www.boost.org/doc/libs/1_53_0/libs/locale/doc/html/structboost_1_1locale_1_1utf_1_1utf__traits.html#ae2cb78fcb8a58bed3e0ce1d6528a719a>(tmp))00237 return illegal <http://www.boost.org/doc/libs/1_53_0/libs/locale/doc/html/namespaceboost_1_1locale_1_1utf.html#a30010000878c7732340bda8956b844fb>;00238 c = (c << 6) | ( tmp & 0x3F);00239 } Dean Chen Best regards http://blog.csdn.net/sheismylife On Sun, Jun 9, 2013 at 2:29 PM, Artyom Beilis <art...@ya...> wrote: > There is a set of functions: booster::locale::conv::utf_to_utf > > > http://www.boost.org/doc/libs/1_53_0/libs/locale/doc/html/group__codepage.html#gaf0ad39959911b000706e0538ec059d44 > > All you need it to do is to convert UTF-32 to UTF-16 or UTF-8 to UTF-16. > > Also cast to uint16_t is INCORRECT is it would fail on characters outside > of BMP - i.e. characters that are encoded > as two units sequence in UTF-16 (so called surrogate pairs) > > Artyom Beilis > -------------- > CppCMS - C++ Web Framework: http://cppcms.com/ > CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ > > ------------------------------ > *From:* 陈抒 <csf...@gm...> > *To:* Artyom Beilis <art...@ya...>; " > cpp...@li..." <cpp...@li...> > *Sent:* Saturday, June 8, 2013 6:52 PM > *Subject:* Re: [Cppcms-users] Questions about decode UTF-8 to Unicode > code point > > Hello Artyom: > I know the code_point type is uint32_t. In my app, I need to convert it > into uint16_t. Which one of the following ways is portable and don't need > to worry about the endianness(big-endian or little-endian), also can be > used in both 32bit and 64bit platform. I am using GCC4.x above. > Assume x is a code_point value > 1. static_cast<uint16_t>(x) > 2. x & 0xffff > > Correct me if I am wrong, thanks. > > > Dean Chen > Best regards > http://blog.csdn.net/sheismylife > > > On Wed, Feb 6, 2013 at 12:20 AM, Artyom Beilis <art...@ya...>wrote: > > First of all there is utf_to_utf functions and if sizeof(wchar_t) == 4 > (which is on Linux/Unix) > than all you need is to use them. > > About the error > > code_point c = utf_traits<char, sizeof(char)>::decode(str.begin(), > str.end()); > > the first parameter is reference that is moved forward and std.begin() > can't be changed > so what you need to do is: > > std::string::const_iterator pos = std.begin(),end =str.end(); > code_point c = utf_traits<char, sizeof(char)>::decode(pos,end ); > > See: > http://www.boost.org/doc/libs/1_51_0/libs/locale/doc/html/structboost_1_1locale_1_1utf_1_1utf__traits.html#a65f0b0e1075dd000d2c2c15af30be372 > > Artyom Beilis > -------------- > CppCMS - C++ Web Framework: http://cppcms.com/ > CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ > > ------------------------------ > *From:* 陈抒 <csf...@gm...> > *To:* cpp...@li... > *Sent:* Tuesday, February 5, 2013 5:32 PM > *Subject:* [Cppcms-users] Questions about decode UTF-8 to Unicode code > point > > 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 > > > ------------------------------------------------------------------------------ > Free Next-Gen Firewall Hardware Offer > Buy your Sophos next-gen firewall before the end March 2013 > and get the hardware for free! Learn more. > http://p.sf.net/sfu/sophos-d2d-feb > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > > > ------------------------------------------------------------------------------ > Free Next-Gen Firewall Hardware Offer > Buy your Sophos next-gen firewall before the end March 2013 > and get the hardware for free! Learn more. > http://p.sf.net/sfu/sophos-d2d-feb > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > > > > > ------------------------------------------------------------------------------ > How ServiceNow helps IT people transform IT departments: > 1. A cloud service to automate IT design, transition and operations > 2. Dashboards that offer high-level views of enterprise services > 3. A single system of record for all IT processes > http://p.sf.net/sfu/servicenow-d2d-j > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > > |
|
From: 陈抒 <csf...@gm...> - 2013-06-13 03:14:06
|
Thanks. It's one of switch statments, I learned it but never used this way - 'without break'. http://msdn.microsoft.com/en-us/library/k0t5wee3.aspx Dean Chen Best regards http://blog.csdn.net/sheismylife On Thu, Jun 13, 2013 at 3:12 AM, Marcel Hellwig <ke...@co...> wrote: > On 12.06.2013 15:55, 陈抒 wrote: > > Another question, when looking into the codes of utf.hpp, I find the > following codes for case 3, 2, 1 are identical, why? > > > 00213 code_point <http://www.boost.org/doc/libs/1_53_0/libs/locale/doc/html/namespaceboost_1_1locale_1_1utf.html#a068111a6b9d6d465a63893ed5c05e2f8> c = lead & ((1<<(6-trail_size))-1);00214 00215 // Read the rest00216 unsigned char tmp;00217 switch(trail_size) {00218 case 3:00219 if(BOOST_LOCALE_UNLIKELY(p==e))00220 return incomplete <http://www.boost.org/doc/libs/1_53_0/libs/locale/doc/html/namespaceboost_1_1locale_1_1utf.html#a20dbe458fd18229a0e6c09888d031b38>;00221 tmp = *p++;00222 if (!is_trail <http://www.boost.org/doc/libs/1_53_0/libs/locale/doc/html/structboost_1_1locale_1_1utf_1_1utf__traits.html#ae2cb78fcb8a58bed3e0ce1d6528a719a>(tmp))00223 return illegal <http://www.boost.org/doc/libs/1_53_0/libs/locale/doc/html/namespaceboost_1_1locale_1_1utf.html#a30010000878c7732340bda8956b844fb>;00224 c = (c << 6) | ( tmp & 0x3F);00225 case 2:00226 if(BOOST_LOCALE_UNLIKELY(p==e))00227 return incomplete <http://www.boost.org/doc/libs/1_53_0/libs/locale/doc/html/namespaceboost_1_1locale_1_1utf.html#a20dbe458fd18229a0e6c09888d031b38>;00228 tmp = *p++;00229 if (!is_trail <http://www.boost.org/doc/libs/1_53_0/libs/locale/doc/html/structboost_1_1locale_1_1utf_1_1utf__traits.html#ae2cb78fcb8a58bed3e0ce1d6528a719a>(tmp))00230 return illegal <http://www.boost.org/doc/libs/1_53_0/libs/locale/doc/html/namespaceboost_1_1locale_1_1utf.html#a30010000878c7732340bda8956b844fb>;00231 c = (c << 6) | ( tmp & 0x3F);00232 case 1:00233 if(BOOST_LOCALE_UNLIKELY(p==e))00234 return incomplete <http://www.boost.org/doc/libs/1_53_0/libs/locale/doc/html/namespaceboost_1_1locale_1_1utf.html#a20dbe458fd18229a0e6c09888d031b38>;00235 tmp = *p++;00236 if (!is_trail <http://www.boost.org/doc/libs/1_53_0/libs/locale/doc/html/structboost_1_1locale_1_1utf_1_1utf__traits.html#ae2cb78fcb8a58bed3e0ce1d6528a719a>(tmp))00237 return illegal <http://www.boost.org/doc/libs/1_53_0/libs/locale/doc/html/namespaceboost_1_1locale_1_1utf.html#a30010000878c7732340bda8956b844fb>;00238 c = (c << 6) | ( tmp & 0x3F);00239 } > > > Please note, that there is no break after a case, but rather a > fallthrough. It's not optimal to produce the code three times, but its > valid. Maybe a for/while loop is better here. > > > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Windows: > > Build for Windows Store. > > http://p.sf.net/sfu/windows-dev2dev > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > > |