49 unsigned const char *p1;
51 unsigned int h_nbl, l_nbl;
53 size_t decoded_len, buf_size;
56 static unsigned int hexval_tbl[256] = {
57 64, 64, 64, 64, 64, 64, 64, 64, 64, 32, 16, 64, 64, 16, 64, 64,
58 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
59 32, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
60 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 64, 64, 64, 64, 64, 64,
61 64, 10, 11, 12, 13, 14, 15, 64, 64, 64, 64, 64, 64, 64, 64, 64,
62 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
63 64, 10, 11, 12, 13, 14, 15, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
65 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
66 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
67 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
68 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
69 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
70 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
71 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
72 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
75 if (replace_us_by_ws) {
76 replace_us_by_ws =
'_';
79 i = length, p1 = str; buf_size = length;
81 while (i > 1 && *p1 !=
'\0') {
91 retval = zend_string_alloc(buf_size, 0);
95 while (i > 0 && *p1 !=
'\0') {
98 if (i == 0 || *p1 ==
'\0') {
101 h_nbl = hexval_tbl[*p1];
104 if ((--i) == 0 || (l_nbl = hexval_tbl[*(++p1)]) >= 16) {
108 *(p2++) = (h_nbl << 4) | l_nbl, decoded_len++;
110 }
else if (h_nbl < 64) {
112 while (h_nbl == 32) {
113 if (--i == 0 || (h_nbl = hexval_tbl[*(++p1)]) == 64) {
118 if (p1[0] ==
'\r' && i >= 2 && p1[1] ==
'\n') {
127 *(p2++) = (replace_us_by_ws == *p1 ?
'\x20': *p1);
128 i--, p1++, decoded_len++;