Guest User

Untitled

a guest
Apr 25th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. static size_t BrotliParseAsUTF8(
  2. int* symbol, const uint8_t* input, size_t size) {
  3. /* ASCII */
  4. if ((input[0] & 0x80) == 0) {
  5. *symbol = input[0];
  6. if (*symbol > 0) {
  7. return 1;
  8. }
  9. }
  10. /* 2-byte UTF8 */
  11. if (size > 1u &&
  12. (input[0] & 0xE0) == 0xC0 &&
  13. (input[1] & 0xC0) == 0x80) {
  14. *symbol = (((input[0] & 0x1F) << 6) |
  15. (input[1] & 0x3F));
  16. if (*symbol > 0x7F) {
  17. return 2;
  18. }
  19. }
  20. /* 3-byte UFT8 */
  21. if (size > 2u &&
  22. (input[0] & 0xF0) == 0xE0 &&
  23. (input[1] & 0xC0) == 0x80 &&
  24. (input[2] & 0xC0) == 0x80) {
  25. *symbol = (((input[0] & 0x0F) << 12) |
  26. ((input[1] & 0x3F) << 6) |
  27. (input[2] & 0x3F));
  28. if (*symbol > 0x7FF) {
  29. return 3;
  30. }
  31. }
  32. /* 4-byte UFT8 */
  33. if (size > 3u &&
  34. (input[0] & 0xF8) == 0xF0 &&
  35. (input[1] & 0xC0) == 0x80 &&
  36. (input[2] & 0xC0) == 0x80 &&
  37. (input[3] & 0xC0) == 0x80) {
  38. *symbol = (((input[0] & 0x07) << 18) |
  39. ((input[1] & 0x3F) << 12) |
  40. ((input[2] & 0x3F) << 6) |
  41. (input[3] & 0x3F));
  42. if (*symbol > 0xFFFF && *symbol <= 0x10FFFF) {
  43. return 4;
  44. }
  45. }
  46. /* Not UTF8, emit a special symbol above the UTF8-code space */
  47. *symbol = 0x110000 | input[0];
  48. return 1;
  49. }
Add Comment
Please, Sign In to add comment