aboutsummaryrefslogtreecommitdiff
path: root/src/core/ngx_string.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/ngx_string.c')
-rw-r--r--src/core/ngx_string.c54
1 files changed, 48 insertions, 6 deletions
diff --git a/src/core/ngx_string.c b/src/core/ngx_string.c
index e21a9fcdd..575e60e84 100644
--- a/src/core/ngx_string.c
+++ b/src/core/ngx_string.c
@@ -753,20 +753,62 @@ ngx_utf_length(ngx_str_t *utf)
continue;
}
- if (c < 0xC0) {
- /* invalid utf */
- return utf->len;
- }
+ if (c >= 0xc0) {
+ for (c <<= 1; c & 0x80; c <<= 1) {
+ i++;
+ }
- for (c <<= 1; c & 0x80; c <<= 1) {
- i++;
+ continue;
}
+
+ /* invalid utf */
+
+ return utf->len;
}
return len;
}
+u_char *
+ngx_utf_cpystrn(u_char *dst, u_char *src, size_t n)
+{
+ u_char c;
+
+ if (n == 0) {
+ return dst;
+ }
+
+ for ( /* void */ ; --n; dst++, src++) {
+
+ c = *src;
+ *dst = c;
+
+ if (c < 0x80) {
+ if (*dst != '\0') {
+ continue;
+ }
+
+ return dst;
+ }
+
+ if (c >= 0xc0) {
+ for (c <<= 1; c & 0x80; c <<= 1) {
+ *++dst = *++src;
+ }
+
+ continue;
+ }
+
+ /* invalid utf */
+ }
+
+ *dst = '\0';
+
+ return dst;
+}
+
+
uintptr_t
ngx_escape_uri(u_char *dst, u_char *src, size_t size, ngx_uint_t type)
{