1. Си / Говнокод #25084

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    while (*str) {
          if (i >= n)
             return NULL;
          if (!(*str & 0x80))
             buffer[i++] = *str++;
          else if ((*str & 0xe0) == 0xc0) {
             if (*str < 0xc2) return NULL;
             c = (*str++ & 0x1f) << 6;
             if ((*str & 0xc0) != 0x80) return NULL;
             buffer[i++] = c + (*str++ & 0x3f);
          } else if ((*str & 0xf0) == 0xe0) {
             if (*str == 0xe0 && (str[1] < 0xa0 || str[1] > 0xbf)) return NULL;
             if (*str == 0xed && str[1] > 0x9f) return NULL; // str[1] < 0x80 is checked below
             c = (*str++ & 0x0f) << 12;
             if ((*str & 0xc0) != 0x80) return NULL;
             c += (*str++ & 0x3f) << 6;
             if ((*str & 0xc0) != 0x80) return NULL;
             buffer[i++] = c + (*str++ & 0x3f);
          } else if ((*str & 0xf8) == 0xf0) {
             if (*str > 0xf4) return NULL;
             if (*str == 0xf0 && (str[1] < 0x90 || str[1] > 0xbf)) return NULL;
             if (*str == 0xf4 && str[1] > 0x8f) return NULL; // str[1] < 0x80 is checked below
             c = (*str++ & 0x07) << 18;
             if ((*str & 0xc0) != 0x80) return NULL;
             c += (*str++ & 0x3f) << 12;
             if ((*str & 0xc0) != 0x80) return NULL;
             c += (*str++ & 0x3f) << 6;
             if ((*str & 0xc0) != 0x80) return NULL;
             c += (*str++ & 0x3f);
             // utf-8 encodings of values used in surrogate pairs are invalid
             if ((c & 0xFFFFF800) == 0xD800) return NULL;
             if (c >= 0x10000) {
                c -= 0x10000;
                if (i + 2 > n) return NULL;
                buffer[i++] = 0xD800 | (0x3ff & (c >> 10));
                buffer[i++] = 0xDC00 | (0x3ff & (c      ));
             }
          } else
             return NULL;
       }

    // Windows stupidly treats 8-bit filenames as some dopey code page,
    // rather than utf-8. If we want to use utf8 filenames, we have to
    // convert them to WCHAR explicitly and call WCHAR versions of the
    // file functions. So, ok, we do.

    Запостил: govnokod3r, 13 Ноября 2018

    Комментарии (8) RSS

    Добавить комментарий