comparison src/core/ngx_string.c @ 2125:8e4b9d2acde8

rename ngx_utf_...() to ngx_utf8_...()
author Igor Sysoev <igor@sysoev.ru>
date Tue, 29 Jul 2008 14:41:34 +0000
parents 2f2052fdd882
children 8c6521eedf84
comparison
equal deleted inserted replaced
2124:e0b424b98f24 2125:8e4b9d2acde8
950 return NGX_OK; 950 return NGX_OK;
951 } 951 }
952 952
953 953
954 /* 954 /*
955 * ngx_utf_decode() decodes two and more bytes UTF sequences only 955 * ngx_utf8_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 * 0x110000 - 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
964 ngx_utf_decode(u_char **p, size_t n) 964 ngx_utf8_decode(u_char **p, size_t n)
965 { 965 {
966 size_t len; 966 size_t len;
967 uint32_t u, i, valid; 967 uint32_t u, i, valid;
968 968
969 u = **p; 969 u = **p;
1016 return 0xffffffff; 1016 return 0xffffffff;
1017 } 1017 }
1018 1018
1019 1019
1020 size_t 1020 size_t
1021 ngx_utf_length(u_char *p, size_t n) 1021 ngx_utf8_length(u_char *p, size_t n)
1022 { 1022 {
1023 u_char c, *last; 1023 u_char c, *last;
1024 size_t len; 1024 size_t len;
1025 1025
1026 last = p + n; 1026 last = p + n;
1032 if (c < 0x80) { 1032 if (c < 0x80) {
1033 p++; 1033 p++;
1034 continue; 1034 continue;
1035 } 1035 }
1036 1036
1037 if (ngx_utf_decode(&p, n) > 0x10ffff) { 1037 if (ngx_utf8_decode(&p, n) > 0x10ffff) {
1038 /* invalid utf */ 1038 /* invalid UTF-8 */
1039 return n; 1039 return n;
1040 } 1040 }
1041 } 1041 }
1042 1042
1043 return len; 1043 return len;
1044 } 1044 }
1045 1045
1046 1046
1047 u_char * 1047 u_char *
1048 ngx_utf_cpystrn(u_char *dst, u_char *src, size_t n, size_t len) 1048 ngx_utf8_cpystrn(u_char *dst, u_char *src, size_t n, size_t len)
1049 { 1049 {
1050 u_char c, *next; 1050 u_char c, *next;
1051 1051
1052 if (n == 0) { 1052 if (n == 0) {
1053 return dst; 1053 return dst;
1071 return dst; 1071 return dst;
1072 } 1072 }
1073 1073
1074 next = src; 1074 next = src;
1075 1075
1076 if (ngx_utf_decode(&next, len) > 0x10ffff) { 1076 if (ngx_utf8_decode(&next, len) > 0x10ffff) {
1077 /* invalid utf */ 1077 /* invalid UTF-8 */
1078 break; 1078 break;
1079 } 1079 }
1080 1080
1081 len--; 1081 len--;
1082 1082