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 rest
> 00216 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.
|