uint32_t
ngx_utf8_decode(u_char **p, size_t n)
{
    size_t    len;
    uint32_t  u, i, valid;
    u = **p;
    if (u > 0xf0) {
        u &= 0x07;
        valid = 0xffff;
        len = 3;
    } else if (u > 0xe0) {
        u &= 0x0f;
        valid = 0x7ff;
        len = 2;
    } else if (u > 0xc0) {
        u &= 0x1f;
        valid = 0x7f;
        len = 1;
    } else {
        (*p)++;
        return 0xffffffff;
    }
    if (n - 1 < len) {
        return 0xfffffffe;
    }
    (*p)++;
    while (len) {
        i = *(*p)++;
        if (i < 0x80) {
            return 0xffffffff;
        }
        u = (u << 6) | (i & 0x3f);
        len--;
    }
    if (u > valid) {
        return u;
    }
    return 0xffffffff;
}
["u_char *\nngx_utf8_cpystrn(u_char *dst, u_char *src, size_t n, size_t len)\n{\n    u_char  c, *next;\n    if (n == 0) {\n        return dst;\n    }\n    while (--n) {\n        c = *src;\n        *dst = c;\n        if (c < 0x80) {\n            if (c != '\\0') {\n                dst++;\n                src++;\n                len--;\n                continue;\n            }\n            return dst;\n        }\n        next = src;\n        if (ngx_utf8_decode(&next, len) > 0x10ffff) {\n            break;\n        }\n        len--;\n        while (src < next) {\n            *++dst = *++src;\n            len--;\n        }\n    }\n    *dst = '\\0';\n    return dst;\n}", 'uint32_t\nngx_utf8_decode(u_char **p, size_t n)\n{\n    size_t    len;\n    uint32_t  u, i, valid;\n    u = **p;\n    if (u > 0xf0) {\n        u &= 0x07;\n        valid = 0xffff;\n        len = 3;\n    } else if (u > 0xe0) {\n        u &= 0x0f;\n        valid = 0x7ff;\n        len = 2;\n    } else if (u > 0xc0) {\n        u &= 0x1f;\n        valid = 0x7f;\n        len = 1;\n    } else {\n        (*p)++;\n        return 0xffffffff;\n    }\n    if (n - 1 < len) {\n        return 0xfffffffe;\n    }\n    (*p)++;\n    while (len) {\n        i = *(*p)++;\n        if (i < 0x80) {\n            return 0xffffffff;\n        }\n        u = (u << 6) | (i & 0x3f);\n        len--;\n    }\n    if (u > valid) {\n        return u;\n    }\n    return 0xffffffff;\n}']