Mercurial > hg > nginx-quic
comparison src/core/ngx_string.c @ 2120:2f2052fdd882
fix utf-8 names in autoindex
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 25 Jul 2008 14:29:05 +0000 |
parents | 2a92804f4109 |
children | 8e4b9d2acde8 |
comparison
equal
deleted
inserted
replaced
2119:0799703985ef | 2120:2f2052fdd882 |
---|---|
953 | 953 |
954 /* | 954 /* |
955 * ngx_utf_decode() decodes two and more bytes UTF sequences only | 955 * ngx_utf_decode() decodes two and more bytes UTF sequences only |
956 * the return values: | 956 * the return values: |
957 * 0x80 - 0x10ffff valid character | 957 * 0x80 - 0x10ffff valid character |
958 * 0x10ffff - 0xfffffffd invalid sequence | 958 * 0x110000 - 0xfffffffd invalid sequence |
959 * 0xfffffffe incomplete sequence | 959 * 0xfffffffe incomplete sequence |
960 * 0xffffffff error | 960 * 0xffffffff error |
961 */ | 961 */ |
962 | 962 |
963 uint32_t | 963 uint32_t |
1018 | 1018 |
1019 | 1019 |
1020 size_t | 1020 size_t |
1021 ngx_utf_length(u_char *p, size_t n) | 1021 ngx_utf_length(u_char *p, size_t n) |
1022 { | 1022 { |
1023 u_char c; | 1023 u_char c, *last; |
1024 size_t len; | 1024 size_t len; |
1025 ngx_uint_t i; | 1025 |
1026 | 1026 last = p + n; |
1027 for (len = 0, i = 0; i < n; len++, i++) { | 1027 |
1028 | 1028 for (len = 0; p < last; len++) { |
1029 c = p[i]; | 1029 |
1030 c = *p; | |
1030 | 1031 |
1031 if (c < 0x80) { | 1032 if (c < 0x80) { |
1033 p++; | |
1032 continue; | 1034 continue; |
1033 } | 1035 } |
1034 | 1036 |
1035 if (c >= 0xc0) { | 1037 if (ngx_utf_decode(&p, n) > 0x10ffff) { |
1036 for (c <<= 1; c & 0x80; c <<= 1) { | 1038 /* invalid utf */ |
1037 i++; | 1039 return n; |
1038 } | 1040 } |
1039 | |
1040 continue; | |
1041 } | |
1042 | |
1043 /* invalid utf */ | |
1044 | |
1045 return n; | |
1046 } | 1041 } |
1047 | 1042 |
1048 return len; | 1043 return len; |
1049 } | 1044 } |
1050 | 1045 |
1051 | 1046 |
1052 u_char * | 1047 u_char * |
1053 ngx_utf_cpystrn(u_char *dst, u_char *src, size_t n) | 1048 ngx_utf_cpystrn(u_char *dst, u_char *src, size_t n, size_t len) |
1054 { | 1049 { |
1055 u_char c; | 1050 u_char c, *next; |
1056 | 1051 |
1057 if (n == 0) { | 1052 if (n == 0) { |
1058 return dst; | 1053 return dst; |
1059 } | 1054 } |
1060 | 1055 |
1061 for ( /* void */ ; --n; dst++, src++) { | 1056 while (--n) { |
1062 | 1057 |
1063 c = *src; | 1058 c = *src; |
1064 *dst = c; | 1059 *dst = c; |
1065 | 1060 |
1066 if (c < 0x80) { | 1061 if (c < 0x80) { |
1067 if (*dst != '\0') { | 1062 |
1063 if (c != '\0') { | |
1064 dst++; | |
1065 src++; | |
1066 len--; | |
1067 | |
1068 continue; | 1068 continue; |
1069 } | 1069 } |
1070 | 1070 |
1071 return dst; | 1071 return dst; |
1072 } | 1072 } |
1073 | 1073 |
1074 if (c >= 0xc0) { | 1074 next = src; |
1075 for (c <<= 1; c & 0x80; c <<= 1) { | 1075 |
1076 *++dst = *++src; | 1076 if (ngx_utf_decode(&next, len) > 0x10ffff) { |
1077 } | 1077 /* invalid utf */ |
1078 | 1078 break; |
1079 continue; | 1079 } |
1080 } | 1080 |
1081 | 1081 len--; |
1082 /* invalid utf */ | 1082 |
1083 while (src < next) { | |
1084 *++dst = *++src; | |
1085 len--; | |
1086 } | |
1083 } | 1087 } |
1084 | 1088 |
1085 *dst = '\0'; | 1089 *dst = '\0'; |
1086 | 1090 |
1087 return dst; | 1091 return dst; |