File tree 1 file changed +15
-7
lines changed
1 file changed +15
-7
lines changed Original file line number Diff line number Diff line change @@ -314,34 +314,42 @@ inline bool parser5<string_t>::unicode::isHexDigit(u8char ch)
314
314
template <typename string_t >
315
315
inline uint64_t parser5<string_t >::unicode::toUnicode(u8char ch)
316
316
{
317
- std::stack<uint8_t > coded;
318
317
if (ch == 0 ) {
319
318
return ch;
320
319
}
320
+
321
+ std::stack<uint8_t > coded;
321
322
while (ch > 0 ) {
322
323
coded.push (ch & 0xff );
323
- ch = ch >> 8 ;
324
+ ch >>= 8 ;
324
325
}
326
+
325
327
u8char charcode = 0 ;
326
328
uint8_t t = coded.top ();
327
329
coded.pop ();
328
330
if (t < 128 ) {
329
331
return t;
330
332
}
331
- uint8_t high_bit_mask = (1 << 6 ) - 1 ;
333
+
334
+ uint8_t high_bit_mask = 0b00111111 ;
332
335
uint8_t high_bit_shift = 0 ;
333
336
int total_bits = 0 ;
334
337
const int other_bits = 6 ;
338
+
335
339
while ((t & 0xC0 ) == 0xC0 ) {
336
340
t <<= 1 ;
337
341
t &= 0xff ;
338
- total_bits += 6 ;
342
+ total_bits += other_bits ;
339
343
high_bit_mask >>= 1 ;
340
344
high_bit_shift++;
341
- charcode <<= other_bits;
342
- charcode |= coded.top () & ((1 << other_bits) - 1 );
343
- coded.pop ();
345
+
346
+ if (!coded.empty ()) {
347
+ charcode <<= other_bits;
348
+ charcode |= coded.top () & ((1 << other_bits) - 1 );
349
+ coded.pop ();
350
+ }
344
351
}
352
+
345
353
charcode |= static_cast <uint64_t >((t >> high_bit_shift) & high_bit_mask) << total_bits;
346
354
return charcode;
347
355
}
You can’t perform that action at this time.
0 commit comments