parse 4 digit hexadecimal number */
| 475 | |
| 476 | /* parse 4 digit hexadecimal number */ |
| 477 | static unsigned parse_hex4(const unsigned char *str) |
| 478 | { |
| 479 | unsigned int h = 0; |
| 480 | size_t i = 0; |
| 481 | |
| 482 | for (i = 0; i < 4; i++) |
| 483 | { |
| 484 | /* parse digit */ |
| 485 | if ((*str >= '0') && (*str <= '9')) |
| 486 | { |
| 487 | h += (unsigned int) (*str) - '0'; |
| 488 | } |
| 489 | else if ((*str >= 'A') && (*str <= 'F')) |
| 490 | { |
| 491 | h += (unsigned int) 10 + (*str) - 'A'; |
| 492 | } |
| 493 | else if ((*str >= 'a') && (*str <= 'f')) |
| 494 | { |
| 495 | h += (unsigned int) 10 + (*str) - 'a'; |
| 496 | } |
| 497 | else /* invalid */ |
| 498 | { |
| 499 | return 0; |
| 500 | } |
| 501 | |
| 502 | if (i < 3) |
| 503 | { |
| 504 | /* shift left to make place for the next nibble */ |
| 505 | h = h << 4; |
| 506 | str++; |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | return h; |
| 511 | } |
| 512 | |
| 513 | /* first bytes of UTF8 encoding for a given length in bytes */ |
| 514 | static const unsigned char firstByteMark[5] = |