Re: [Cppcms-users] Questions about decode UTF-8 to Unicode code point
Brought to you by:
artyom-beilis
|
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 > > |