From: Igor Sysoev Date: Fri, 15 Apr 2016 15:01:19 +0000 (+0300) Subject: String.toLowerCase(). X-Git-Tag: 0.1.0~32 X-Git-Url: http://git.kaiwu.me/postgresql/log/contrib/postgres_fdw/static/gitweb.js?a=commitdiff_plain;h=91ce3dcc64df7618d3f21ff7cc4d065c1b5260ca;p=njs.git String.toLowerCase(). --- diff --git a/njs/njs_string.c b/njs/njs_string.c index d7e853c6..67c269a8 100644 --- a/njs/njs_string.c +++ b/njs/njs_string.c @@ -1291,6 +1291,58 @@ njs_string_index(njs_string_prop_t *string, uint32_t offset) } +/* + * String.toLowerCase(). + * The method supports only simple folding. For example, Turkish "İ" + * folding "\u0130" to "\u0069\u0307" is not supported. + */ + +static njs_ret_t +njs_string_prototype_to_lower_case(njs_vm_t *vm, njs_value_t *args, + nxt_uint_t nargs, njs_index_t unused) +{ + size_t size; + u_char *p, *start; + const u_char *s, *end; + njs_string_prop_t string; + + (void) njs_string_prop(&string, &args[0]); + + start = njs_string_alloc(vm, &vm->retval, string.size, string.length); + if (nxt_slow_path(start == NULL)) { + return NXT_ERROR; + } + + p = start; + s = string.start; + size = string.size; + + if (string.length == 0 || string.length == size) { + /* Byte or ASCII string. */ + + while (size != 0) { + *p++ = nxt_lower_case(*s++); + size--; + } + + } else { + /* UTF-8 string. */ + end = s + size; + + while (size != 0) { + p = nxt_utf8_encode(p, nxt_utf8_lower_case(&s, end)); + size--; + } + + if (string.length >= NJS_STRING_MAP_OFFSET) { + njs_string_offset_map_init(start, string.size); + } + } + + return NXT_OK; +} + + static njs_ret_t njs_string_prototype_search(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused) @@ -1752,6 +1804,13 @@ static const njs_object_prop_t njs_string_prototype_properties[] = NJS_STRING_OBJECT_ARG, NJS_STRING_ARG, NJS_INTEGER_ARG), }, + { + .type = NJS_METHOD, + .name = njs_string("toLowerCase"), + .value = njs_native_function(njs_string_prototype_to_lower_case, 0, + NJS_STRING_OBJECT_ARG, NJS_REGEXP_ARG), + }, + { .type = NJS_METHOD, .name = njs_string("search"), diff --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index 80d1ac1f..76da19b8 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -2745,6 +2745,15 @@ static njs_unit_test_t njs_test[] = { nxt_string("'abc abc abc abc'.lastIndexOf('abc', 0)"), nxt_string("-1") }, + { nxt_string("'ABC'.toLowerCase()"), + nxt_string("abc") }, + + { nxt_string("'ΑΒΓ'.toLowerCase()"), + nxt_string("αβγ") }, + + { nxt_string("'АБВ'.toLowerCase()"), + nxt_string("абв") }, + { nxt_string("'abcdefgh'.search()"), nxt_string("0") }, diff --git a/nxt/Makefile b/nxt/Makefile index 7f9fb31d..98f3e2de 100644 --- a/nxt/Makefile +++ b/nxt/Makefile @@ -47,6 +47,7 @@ $(NXT_BUILDDIR)/nxt_utf8.o: \ $(NXT_LIB)/nxt_types.h \ $(NXT_LIB)/nxt_clang.h \ $(NXT_LIB)/nxt_utf8.h \ + $(NXT_LIB)/nxt_unicode_lower_case.h \ $(NXT_LIB)/nxt_utf8.c \ $(NXT_CC) -c -o $(NXT_BUILDDIR)/nxt_utf8.o $(NXT_CFLAGS) \ diff --git a/nxt/nxt_djb_hash.c b/nxt/nxt_djb_hash.c index 0541094e..3c6838a0 100644 --- a/nxt/nxt_djb_hash.c +++ b/nxt/nxt_djb_hash.c @@ -31,7 +31,6 @@ nxt_djb_hash(const void *data, size_t len) uint32_t nxt_djb_hash_lowcase(const void *data, size_t len) { - u_char c; uint32_t hash; const u_char *p; @@ -39,8 +38,7 @@ nxt_djb_hash_lowcase(const void *data, size_t len) hash = NXT_DJB_HASH_INIT; while (len != 0) { - c = *p++; - hash = nxt_djb_hash_add(hash, nxt_lowcase(c)); + hash = nxt_djb_hash_add(hash, nxt_lower_case(*p++)); len--; } diff --git a/nxt/nxt_stub.h b/nxt/nxt_stub.h index 138cd04c..05ebbef2 100644 --- a/nxt/nxt_stub.h +++ b/nxt/nxt_stub.h @@ -14,8 +14,13 @@ #define nxt_min(val1, val2) \ ((val1 < val2) ? (val1) : (val2)) -#define nxt_lowcase(c) \ - (u_char) ((c >= 'A' && c <= 'Z') ? c | 0x20 : c) + +nxt_inline u_char +nxt_lower_case(u_char c) +{ + return (u_char) ((c >= 'A' && c <= 'Z') ? c | 0x20 : c); +} + #define nxt_strstr_eq(s1, s2) \ (((s1)->len == (s2)->len) \ diff --git a/nxt/nxt_unicode_lowcase.h b/nxt/nxt_unicode_lower_case.h similarity index 90% rename from nxt/nxt_unicode_lowcase.h rename to nxt/nxt_unicode_lower_case.h index c868ad19..2bfef709 100644 --- a/nxt/nxt_unicode_lowcase.h +++ b/nxt/nxt_unicode_lower_case.h @@ -4,12 +4,12 @@ * 14920 bytes on 32-bit platforms, 17000 bytes on 64-bit platforms. */ -#define NXT_UNICODE_MAX_LOWCASE 0x10427 +#define NXT_UNICODE_MAX_LOWER_CASE 0x10427 -#define NXT_UNICODE_BLOCK_SIZE 128 +#define NXT_UNICODE_BLOCK_SIZE 128 -static const uint32_t nxt_unicode_block_000[128] nxt_aligned(64) = { +static const uint32_t nxt_unicode_lower_case_block_000[128] nxt_aligned(64) = { 0x00000, 0x00001, 0x00002, 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a, 0x0000b, 0x0000c, 0x0000d, 0x0000e, 0x0000f, 0x00010, 0x00011, 0x00012, 0x00013, 0x00014, 0x00015, 0x00016, 0x00017, @@ -29,14 +29,14 @@ static const uint32_t nxt_unicode_block_000[128] nxt_aligned(64) = { }; -static const uint32_t nxt_unicode_block_001[128] nxt_aligned(64) = { +static const uint32_t nxt_unicode_lower_case_block_001[128] nxt_aligned(64) = { 0x00080, 0x00081, 0x00082, 0x00083, 0x00084, 0x00085, 0x00086, 0x00087, 0x00088, 0x00089, 0x0008a, 0x0008b, 0x0008c, 0x0008d, 0x0008e, 0x0008f, 0x00090, 0x00091, 0x00092, 0x00093, 0x00094, 0x00095, 0x00096, 0x00097, 0x00098, 0x00099, 0x0009a, 0x0009b, 0x0009c, 0x0009d, 0x0009e, 0x0009f, 0x000a0, 0x000a1, 0x000a2, 0x000a3, 0x000a4, 0x000a5, 0x000a6, 0x000a7, 0x000a8, 0x000a9, 0x000aa, 0x000ab, 0x000ac, 0x000ad, 0x000ae, 0x000af, - 0x000b0, 0x000b1, 0x000b2, 0x000b3, 0x000b4, 0x003bc, 0x000b6, 0x000b7, + 0x000b0, 0x000b1, 0x000b2, 0x000b3, 0x000b4, 0x000b5, 0x000b6, 0x000b7, 0x000b8, 0x000b9, 0x000ba, 0x000bb, 0x000bc, 0x000bd, 0x000be, 0x000bf, 0x000e0, 0x000e1, 0x000e2, 0x000e3, 0x000e4, 0x000e5, 0x000e6, 0x000e7, 0x000e8, 0x000e9, 0x000ea, 0x000eb, 0x000ec, 0x000ed, 0x000ee, 0x000ef, @@ -49,14 +49,14 @@ static const uint32_t nxt_unicode_block_001[128] nxt_aligned(64) = { }; -static const uint32_t nxt_unicode_block_002[128] nxt_aligned(64) = { +static const uint32_t nxt_unicode_lower_case_block_002[128] nxt_aligned(64) = { 0x00101, 0x00101, 0x00103, 0x00103, 0x00105, 0x00105, 0x00107, 0x00107, 0x00109, 0x00109, 0x0010b, 0x0010b, 0x0010d, 0x0010d, 0x0010f, 0x0010f, 0x00111, 0x00111, 0x00113, 0x00113, 0x00115, 0x00115, 0x00117, 0x00117, 0x00119, 0x00119, 0x0011b, 0x0011b, 0x0011d, 0x0011d, 0x0011f, 0x0011f, 0x00121, 0x00121, 0x00123, 0x00123, 0x00125, 0x00125, 0x00127, 0x00127, 0x00129, 0x00129, 0x0012b, 0x0012b, 0x0012d, 0x0012d, 0x0012f, 0x0012f, - 0x00130, 0x00131, 0x00133, 0x00133, 0x00135, 0x00135, 0x00137, 0x00137, + 0x00069, 0x00131, 0x00133, 0x00133, 0x00135, 0x00135, 0x00137, 0x00137, 0x00138, 0x0013a, 0x0013a, 0x0013c, 0x0013c, 0x0013e, 0x0013e, 0x00140, 0x00140, 0x00142, 0x00142, 0x00144, 0x00144, 0x00146, 0x00146, 0x00148, 0x00148, 0x00149, 0x0014b, 0x0014b, 0x0014d, 0x0014d, 0x0014f, 0x0014f, @@ -65,11 +65,11 @@ static const uint32_t nxt_unicode_block_002[128] nxt_aligned(64) = { 0x00161, 0x00161, 0x00163, 0x00163, 0x00165, 0x00165, 0x00167, 0x00167, 0x00169, 0x00169, 0x0016b, 0x0016b, 0x0016d, 0x0016d, 0x0016f, 0x0016f, 0x00171, 0x00171, 0x00173, 0x00173, 0x00175, 0x00175, 0x00177, 0x00177, - 0x000ff, 0x0017a, 0x0017a, 0x0017c, 0x0017c, 0x0017e, 0x0017e, 0x00073, + 0x000ff, 0x0017a, 0x0017a, 0x0017c, 0x0017c, 0x0017e, 0x0017e, 0x0017f, }; -static const uint32_t nxt_unicode_block_003[128] nxt_aligned(64) = { +static const uint32_t nxt_unicode_lower_case_block_003[128] nxt_aligned(64) = { 0x00180, 0x00253, 0x00183, 0x00183, 0x00185, 0x00185, 0x00254, 0x00188, 0x00188, 0x00256, 0x00257, 0x0018c, 0x0018c, 0x0018d, 0x001dd, 0x00259, 0x0025b, 0x00192, 0x00192, 0x00260, 0x00263, 0x00195, 0x00269, 0x00268, @@ -89,7 +89,7 @@ static const uint32_t nxt_unicode_block_003[128] nxt_aligned(64) = { }; -static const uint32_t nxt_unicode_block_004[128] nxt_aligned(64) = { +static const uint32_t nxt_unicode_lower_case_block_004[128] nxt_aligned(64) = { 0x00201, 0x00201, 0x00203, 0x00203, 0x00205, 0x00205, 0x00207, 0x00207, 0x00209, 0x00209, 0x0020b, 0x0020b, 0x0020d, 0x0020d, 0x0020f, 0x0020f, 0x00211, 0x00211, 0x00213, 0x00213, 0x00215, 0x00215, 0x00217, 0x00217, @@ -109,7 +109,7 @@ static const uint32_t nxt_unicode_block_004[128] nxt_aligned(64) = { }; -static const uint32_t nxt_unicode_block_006[128] nxt_aligned(64) = { +static const uint32_t nxt_unicode_lower_case_block_006[128] nxt_aligned(64) = { 0x00300, 0x00301, 0x00302, 0x00303, 0x00304, 0x00305, 0x00306, 0x00307, 0x00308, 0x00309, 0x0030a, 0x0030b, 0x0030c, 0x0030d, 0x0030e, 0x0030f, 0x00310, 0x00311, 0x00312, 0x00313, 0x00314, 0x00315, 0x00316, 0x00317, @@ -118,7 +118,7 @@ static const uint32_t nxt_unicode_block_006[128] nxt_aligned(64) = { 0x00328, 0x00329, 0x0032a, 0x0032b, 0x0032c, 0x0032d, 0x0032e, 0x0032f, 0x00330, 0x00331, 0x00332, 0x00333, 0x00334, 0x00335, 0x00336, 0x00337, 0x00338, 0x00339, 0x0033a, 0x0033b, 0x0033c, 0x0033d, 0x0033e, 0x0033f, - 0x00340, 0x00341, 0x00342, 0x00343, 0x00344, 0x003b9, 0x00346, 0x00347, + 0x00340, 0x00341, 0x00342, 0x00343, 0x00344, 0x00345, 0x00346, 0x00347, 0x00348, 0x00349, 0x0034a, 0x0034b, 0x0034c, 0x0034d, 0x0034e, 0x0034f, 0x00350, 0x00351, 0x00352, 0x00353, 0x00354, 0x00355, 0x00356, 0x00357, 0x00358, 0x00359, 0x0035a, 0x0035b, 0x0035c, 0x0035d, 0x0035e, 0x0035f, @@ -129,7 +129,7 @@ static const uint32_t nxt_unicode_block_006[128] nxt_aligned(64) = { }; -static const uint32_t nxt_unicode_block_007[128] nxt_aligned(64) = { +static const uint32_t nxt_unicode_lower_case_block_007[128] nxt_aligned(64) = { 0x00380, 0x00381, 0x00382, 0x00383, 0x00384, 0x00385, 0x003ac, 0x00387, 0x003ad, 0x003ae, 0x003af, 0x0038b, 0x003cc, 0x0038d, 0x003cd, 0x003ce, 0x00390, 0x003b1, 0x003b2, 0x003b3, 0x003b4, 0x003b5, 0x003b6, 0x003b7, @@ -138,18 +138,18 @@ static const uint32_t nxt_unicode_block_007[128] nxt_aligned(64) = { 0x003c8, 0x003c9, 0x003ca, 0x003cb, 0x003ac, 0x003ad, 0x003ae, 0x003af, 0x003b0, 0x003b1, 0x003b2, 0x003b3, 0x003b4, 0x003b5, 0x003b6, 0x003b7, 0x003b8, 0x003b9, 0x003ba, 0x003bb, 0x003bc, 0x003bd, 0x003be, 0x003bf, - 0x003c0, 0x003c1, 0x003c3, 0x003c3, 0x003c4, 0x003c5, 0x003c6, 0x003c7, + 0x003c0, 0x003c1, 0x003c2, 0x003c3, 0x003c4, 0x003c5, 0x003c6, 0x003c7, 0x003c8, 0x003c9, 0x003ca, 0x003cb, 0x003cc, 0x003cd, 0x003ce, 0x003d7, - 0x003b2, 0x003b8, 0x003d2, 0x003d3, 0x003d4, 0x003c6, 0x003c0, 0x003d7, + 0x003d0, 0x003d1, 0x003d2, 0x003d3, 0x003d4, 0x003d5, 0x003d6, 0x003d7, 0x003d9, 0x003d9, 0x003db, 0x003db, 0x003dd, 0x003dd, 0x003df, 0x003df, 0x003e1, 0x003e1, 0x003e3, 0x003e3, 0x003e5, 0x003e5, 0x003e7, 0x003e7, 0x003e9, 0x003e9, 0x003eb, 0x003eb, 0x003ed, 0x003ed, 0x003ef, 0x003ef, - 0x003ba, 0x003c1, 0x003f2, 0x003f3, 0x003b8, 0x003b5, 0x003f6, 0x003f8, + 0x003f0, 0x003f1, 0x003f2, 0x003f3, 0x003b8, 0x003f5, 0x003f6, 0x003f8, 0x003f8, 0x003f2, 0x003fb, 0x003fb, 0x003fc, 0x0037b, 0x0037c, 0x0037d, }; -static const uint32_t nxt_unicode_block_008[128] nxt_aligned(64) = { +static const uint32_t nxt_unicode_lower_case_block_008[128] nxt_aligned(64) = { 0x00450, 0x00451, 0x00452, 0x00453, 0x00454, 0x00455, 0x00456, 0x00457, 0x00458, 0x00459, 0x0045a, 0x0045b, 0x0045c, 0x0045d, 0x0045e, 0x0045f, 0x00430, 0x00431, 0x00432, 0x00433, 0x00434, 0x00435, 0x00436, 0x00437, @@ -169,7 +169,7 @@ static const uint32_t nxt_unicode_block_008[128] nxt_aligned(64) = { }; -static const uint32_t nxt_unicode_block_009[128] nxt_aligned(64) = { +static const uint32_t nxt_unicode_lower_case_block_009[128] nxt_aligned(64) = { 0x00481, 0x00481, 0x00482, 0x00483, 0x00484, 0x00485, 0x00486, 0x00487, 0x00488, 0x00489, 0x0048b, 0x0048b, 0x0048d, 0x0048d, 0x0048f, 0x0048f, 0x00491, 0x00491, 0x00493, 0x00493, 0x00495, 0x00495, 0x00497, 0x00497, @@ -189,7 +189,7 @@ static const uint32_t nxt_unicode_block_009[128] nxt_aligned(64) = { }; -static const uint32_t nxt_unicode_block_00a[128] nxt_aligned(64) = { +static const uint32_t nxt_unicode_lower_case_block_00a[128] nxt_aligned(64) = { 0x00501, 0x00501, 0x00503, 0x00503, 0x00505, 0x00505, 0x00507, 0x00507, 0x00509, 0x00509, 0x0050b, 0x0050b, 0x0050d, 0x0050d, 0x0050f, 0x0050f, 0x00511, 0x00511, 0x00513, 0x00513, 0x00515, 0x00515, 0x00517, 0x00517, @@ -209,7 +209,7 @@ static const uint32_t nxt_unicode_block_00a[128] nxt_aligned(64) = { }; -static const uint32_t nxt_unicode_block_021[128] nxt_aligned(64) = { +static const uint32_t nxt_unicode_lower_case_block_021[128] nxt_aligned(64) = { 0x01080, 0x01081, 0x01082, 0x01083, 0x01084, 0x01085, 0x01086, 0x01087, 0x01088, 0x01089, 0x0108a, 0x0108b, 0x0108c, 0x0108d, 0x0108e, 0x0108f, 0x01090, 0x01091, 0x01092, 0x01093, 0x01094, 0x01095, 0x01096, 0x01097, @@ -229,7 +229,7 @@ static const uint32_t nxt_unicode_block_021[128] nxt_aligned(64) = { }; -static const uint32_t nxt_unicode_block_03c[128] nxt_aligned(64) = { +static const uint32_t nxt_unicode_lower_case_block_03c[128] nxt_aligned(64) = { 0x01e01, 0x01e01, 0x01e03, 0x01e03, 0x01e05, 0x01e05, 0x01e07, 0x01e07, 0x01e09, 0x01e09, 0x01e0b, 0x01e0b, 0x01e0d, 0x01e0d, 0x01e0f, 0x01e0f, 0x01e11, 0x01e11, 0x01e13, 0x01e13, 0x01e15, 0x01e15, 0x01e17, 0x01e17, @@ -249,11 +249,11 @@ static const uint32_t nxt_unicode_block_03c[128] nxt_aligned(64) = { }; -static const uint32_t nxt_unicode_block_03d[128] nxt_aligned(64) = { +static const uint32_t nxt_unicode_lower_case_block_03d[128] nxt_aligned(64) = { 0x01e81, 0x01e81, 0x01e83, 0x01e83, 0x01e85, 0x01e85, 0x01e87, 0x01e87, 0x01e89, 0x01e89, 0x01e8b, 0x01e8b, 0x01e8d, 0x01e8d, 0x01e8f, 0x01e8f, 0x01e91, 0x01e91, 0x01e93, 0x01e93, 0x01e95, 0x01e95, 0x01e96, 0x01e97, - 0x01e98, 0x01e99, 0x01e9a, 0x01e61, 0x01e9c, 0x01e9d, 0x000df, 0x01e9f, + 0x01e98, 0x01e99, 0x01e9a, 0x01e9b, 0x01e9c, 0x01e9d, 0x000df, 0x01e9f, 0x01ea1, 0x01ea1, 0x01ea3, 0x01ea3, 0x01ea5, 0x01ea5, 0x01ea7, 0x01ea7, 0x01ea9, 0x01ea9, 0x01eab, 0x01eab, 0x01ead, 0x01ead, 0x01eaf, 0x01eaf, 0x01eb1, 0x01eb1, 0x01eb3, 0x01eb3, 0x01eb5, 0x01eb5, 0x01eb7, 0x01eb7, @@ -269,7 +269,7 @@ static const uint32_t nxt_unicode_block_03d[128] nxt_aligned(64) = { }; -static const uint32_t nxt_unicode_block_03e[128] nxt_aligned(64) = { +static const uint32_t nxt_unicode_lower_case_block_03e[128] nxt_aligned(64) = { 0x01f00, 0x01f01, 0x01f02, 0x01f03, 0x01f04, 0x01f05, 0x01f06, 0x01f07, 0x01f00, 0x01f01, 0x01f02, 0x01f03, 0x01f04, 0x01f05, 0x01f06, 0x01f07, 0x01f10, 0x01f11, 0x01f12, 0x01f13, 0x01f14, 0x01f15, 0x01f16, 0x01f17, @@ -289,7 +289,7 @@ static const uint32_t nxt_unicode_block_03e[128] nxt_aligned(64) = { }; -static const uint32_t nxt_unicode_block_03f[128] nxt_aligned(64) = { +static const uint32_t nxt_unicode_lower_case_block_03f[128] nxt_aligned(64) = { 0x01f80, 0x01f81, 0x01f82, 0x01f83, 0x01f84, 0x01f85, 0x01f86, 0x01f87, 0x01f80, 0x01f81, 0x01f82, 0x01f83, 0x01f84, 0x01f85, 0x01f86, 0x01f87, 0x01f90, 0x01f91, 0x01f92, 0x01f93, 0x01f94, 0x01f95, 0x01f96, 0x01f97, @@ -297,7 +297,7 @@ static const uint32_t nxt_unicode_block_03f[128] nxt_aligned(64) = { 0x01fa0, 0x01fa1, 0x01fa2, 0x01fa3, 0x01fa4, 0x01fa5, 0x01fa6, 0x01fa7, 0x01fa0, 0x01fa1, 0x01fa2, 0x01fa3, 0x01fa4, 0x01fa5, 0x01fa6, 0x01fa7, 0x01fb0, 0x01fb1, 0x01fb2, 0x01fb3, 0x01fb4, 0x01fb5, 0x01fb6, 0x01fb7, - 0x01fb0, 0x01fb1, 0x01f70, 0x01f71, 0x01fb3, 0x01fbd, 0x003b9, 0x01fbf, + 0x01fb0, 0x01fb1, 0x01f70, 0x01f71, 0x01fb3, 0x01fbd, 0x01fbe, 0x01fbf, 0x01fc0, 0x01fc1, 0x01fc2, 0x01fc3, 0x01fc4, 0x01fc5, 0x01fc6, 0x01fc7, 0x01f72, 0x01f73, 0x01f74, 0x01f75, 0x01fc3, 0x01fcd, 0x01fce, 0x01fcf, 0x01fd0, 0x01fd1, 0x01fd2, 0x01fd3, 0x01fd4, 0x01fd5, 0x01fd6, 0x01fd7, @@ -309,7 +309,7 @@ static const uint32_t nxt_unicode_block_03f[128] nxt_aligned(64) = { }; -static const uint32_t nxt_unicode_block_042[128] nxt_aligned(64) = { +static const uint32_t nxt_unicode_lower_case_block_042[128] nxt_aligned(64) = { 0x02100, 0x02101, 0x02102, 0x02103, 0x02104, 0x02105, 0x02106, 0x02107, 0x02108, 0x02109, 0x0210a, 0x0210b, 0x0210c, 0x0210d, 0x0210e, 0x0210f, 0x02110, 0x02111, 0x02112, 0x02113, 0x02114, 0x02115, 0x02116, 0x02117, @@ -329,7 +329,7 @@ static const uint32_t nxt_unicode_block_042[128] nxt_aligned(64) = { }; -static const uint32_t nxt_unicode_block_043[128] nxt_aligned(64) = { +static const uint32_t nxt_unicode_lower_case_block_043[128] nxt_aligned(64) = { 0x02180, 0x02181, 0x02182, 0x02184, 0x02184, 0x02185, 0x02186, 0x02187, 0x02188, 0x02189, 0x0218a, 0x0218b, 0x0218c, 0x0218d, 0x0218e, 0x0218f, 0x02190, 0x02191, 0x02192, 0x02193, 0x02194, 0x02195, 0x02196, 0x02197, @@ -349,7 +349,7 @@ static const uint32_t nxt_unicode_block_043[128] nxt_aligned(64) = { }; -static const uint32_t nxt_unicode_block_049[128] nxt_aligned(64) = { +static const uint32_t nxt_unicode_lower_case_block_049[128] nxt_aligned(64) = { 0x02480, 0x02481, 0x02482, 0x02483, 0x02484, 0x02485, 0x02486, 0x02487, 0x02488, 0x02489, 0x0248a, 0x0248b, 0x0248c, 0x0248d, 0x0248e, 0x0248f, 0x02490, 0x02491, 0x02492, 0x02493, 0x02494, 0x02495, 0x02496, 0x02497, @@ -369,7 +369,7 @@ static const uint32_t nxt_unicode_block_049[128] nxt_aligned(64) = { }; -static const uint32_t nxt_unicode_block_058[128] nxt_aligned(64) = { +static const uint32_t nxt_unicode_lower_case_block_058[128] nxt_aligned(64) = { 0x02c30, 0x02c31, 0x02c32, 0x02c33, 0x02c34, 0x02c35, 0x02c36, 0x02c37, 0x02c38, 0x02c39, 0x02c3a, 0x02c3b, 0x02c3c, 0x02c3d, 0x02c3e, 0x02c3f, 0x02c40, 0x02c41, 0x02c42, 0x02c43, 0x02c44, 0x02c45, 0x02c46, 0x02c47, @@ -389,7 +389,7 @@ static const uint32_t nxt_unicode_block_058[128] nxt_aligned(64) = { }; -static const uint32_t nxt_unicode_block_059[128] nxt_aligned(64) = { +static const uint32_t nxt_unicode_lower_case_block_059[128] nxt_aligned(64) = { 0x02c81, 0x02c81, 0x02c83, 0x02c83, 0x02c85, 0x02c85, 0x02c87, 0x02c87, 0x02c89, 0x02c89, 0x02c8b, 0x02c8b, 0x02c8d, 0x02c8d, 0x02c8f, 0x02c8f, 0x02c91, 0x02c91, 0x02c93, 0x02c93, 0x02c95, 0x02c95, 0x02c97, 0x02c97, @@ -409,7 +409,7 @@ static const uint32_t nxt_unicode_block_059[128] nxt_aligned(64) = { }; -static const uint32_t nxt_unicode_block_14c[128] nxt_aligned(64) = { +static const uint32_t nxt_unicode_lower_case_block_14c[128] nxt_aligned(64) = { 0x0a600, 0x0a601, 0x0a602, 0x0a603, 0x0a604, 0x0a605, 0x0a606, 0x0a607, 0x0a608, 0x0a609, 0x0a60a, 0x0a60b, 0x0a60c, 0x0a60d, 0x0a60e, 0x0a60f, 0x0a610, 0x0a611, 0x0a612, 0x0a613, 0x0a614, 0x0a615, 0x0a616, 0x0a617, @@ -429,7 +429,7 @@ static const uint32_t nxt_unicode_block_14c[128] nxt_aligned(64) = { }; -static const uint32_t nxt_unicode_block_14d[128] nxt_aligned(64) = { +static const uint32_t nxt_unicode_lower_case_block_14d[128] nxt_aligned(64) = { 0x0a681, 0x0a681, 0x0a683, 0x0a683, 0x0a685, 0x0a685, 0x0a687, 0x0a687, 0x0a689, 0x0a689, 0x0a68b, 0x0a68b, 0x0a68d, 0x0a68d, 0x0a68f, 0x0a68f, 0x0a691, 0x0a691, 0x0a693, 0x0a693, 0x0a695, 0x0a695, 0x0a697, 0x0a697, @@ -449,7 +449,7 @@ static const uint32_t nxt_unicode_block_14d[128] nxt_aligned(64) = { }; -static const uint32_t nxt_unicode_block_14e[128] nxt_aligned(64) = { +static const uint32_t nxt_unicode_lower_case_block_14e[128] nxt_aligned(64) = { 0x0a700, 0x0a701, 0x0a702, 0x0a703, 0x0a704, 0x0a705, 0x0a706, 0x0a707, 0x0a708, 0x0a709, 0x0a70a, 0x0a70b, 0x0a70c, 0x0a70d, 0x0a70e, 0x0a70f, 0x0a710, 0x0a711, 0x0a712, 0x0a713, 0x0a714, 0x0a715, 0x0a716, 0x0a717, @@ -469,7 +469,7 @@ static const uint32_t nxt_unicode_block_14e[128] nxt_aligned(64) = { }; -static const uint32_t nxt_unicode_block_14f[128] nxt_aligned(64) = { +static const uint32_t nxt_unicode_lower_case_block_14f[128] nxt_aligned(64) = { 0x0a781, 0x0a781, 0x0a783, 0x0a783, 0x0a785, 0x0a785, 0x0a787, 0x0a787, 0x0a788, 0x0a789, 0x0a78a, 0x0a78c, 0x0a78c, 0x00265, 0x0a78e, 0x0a78f, 0x0a791, 0x0a791, 0x0a793, 0x0a793, 0x0a794, 0x0a795, 0x0a796, 0x0a797, @@ -489,7 +489,7 @@ static const uint32_t nxt_unicode_block_14f[128] nxt_aligned(64) = { }; -static const uint32_t nxt_unicode_block_1fe[128] nxt_aligned(64) = { +static const uint32_t nxt_unicode_lower_case_block_1fe[128] nxt_aligned(64) = { 0x0ff00, 0x0ff01, 0x0ff02, 0x0ff03, 0x0ff04, 0x0ff05, 0x0ff06, 0x0ff07, 0x0ff08, 0x0ff09, 0x0ff0a, 0x0ff0b, 0x0ff0c, 0x0ff0d, 0x0ff0e, 0x0ff0f, 0x0ff10, 0x0ff11, 0x0ff12, 0x0ff13, 0x0ff14, 0x0ff15, 0x0ff16, 0x0ff17, @@ -509,7 +509,7 @@ static const uint32_t nxt_unicode_block_1fe[128] nxt_aligned(64) = { }; -static const uint32_t nxt_unicode_block_208[40] nxt_aligned(64) = { +static const uint32_t nxt_unicode_lower_case_block_208[40] nxt_aligned(64) = { 0x10428, 0x10429, 0x1042a, 0x1042b, 0x1042c, 0x1042d, 0x1042e, 0x1042f, 0x10430, 0x10431, 0x10432, 0x10433, 0x10434, 0x10435, 0x10436, 0x10437, 0x10438, 0x10439, 0x1043a, 0x1043b, 0x1043c, 0x1043d, 0x1043e, 0x1043f, @@ -518,18 +518,18 @@ static const uint32_t nxt_unicode_block_208[40] nxt_aligned(64) = { }; -static const uint32_t *nxt_unicode_blocks[] nxt_aligned(64) = { - nxt_unicode_block_000, - nxt_unicode_block_001, - nxt_unicode_block_002, - nxt_unicode_block_003, - nxt_unicode_block_004, +static const uint32_t *nxt_unicode_lower_case_blocks[] nxt_aligned(64) = { + nxt_unicode_lower_case_block_000, + nxt_unicode_lower_case_block_001, + nxt_unicode_lower_case_block_002, + nxt_unicode_lower_case_block_003, + nxt_unicode_lower_case_block_004, NULL, - nxt_unicode_block_006, - nxt_unicode_block_007, - nxt_unicode_block_008, - nxt_unicode_block_009, - nxt_unicode_block_00a, + nxt_unicode_lower_case_block_006, + nxt_unicode_lower_case_block_007, + nxt_unicode_lower_case_block_008, + nxt_unicode_lower_case_block_009, + nxt_unicode_lower_case_block_00a, NULL, NULL, NULL, @@ -552,7 +552,7 @@ static const uint32_t *nxt_unicode_blocks[] nxt_aligned(64) = { NULL, NULL, NULL, - nxt_unicode_block_021, + nxt_unicode_lower_case_block_021, NULL, NULL, NULL, @@ -579,20 +579,20 @@ static const uint32_t *nxt_unicode_blocks[] nxt_aligned(64) = { NULL, NULL, NULL, - nxt_unicode_block_03c, - nxt_unicode_block_03d, - nxt_unicode_block_03e, - nxt_unicode_block_03f, + nxt_unicode_lower_case_block_03c, + nxt_unicode_lower_case_block_03d, + nxt_unicode_lower_case_block_03e, + nxt_unicode_lower_case_block_03f, NULL, NULL, - nxt_unicode_block_042, - nxt_unicode_block_043, + nxt_unicode_lower_case_block_042, + nxt_unicode_lower_case_block_043, NULL, NULL, NULL, NULL, NULL, - nxt_unicode_block_049, + nxt_unicode_lower_case_block_049, NULL, NULL, NULL, @@ -607,8 +607,8 @@ static const uint32_t *nxt_unicode_blocks[] nxt_aligned(64) = { NULL, NULL, NULL, - nxt_unicode_block_058, - nxt_unicode_block_059, + nxt_unicode_lower_case_block_058, + nxt_unicode_lower_case_block_059, NULL, NULL, NULL, @@ -851,10 +851,10 @@ static const uint32_t *nxt_unicode_blocks[] nxt_aligned(64) = { NULL, NULL, NULL, - nxt_unicode_block_14c, - nxt_unicode_block_14d, - nxt_unicode_block_14e, - nxt_unicode_block_14f, + nxt_unicode_lower_case_block_14c, + nxt_unicode_lower_case_block_14d, + nxt_unicode_lower_case_block_14e, + nxt_unicode_lower_case_block_14f, NULL, NULL, NULL, @@ -1029,7 +1029,7 @@ static const uint32_t *nxt_unicode_blocks[] nxt_aligned(64) = { NULL, NULL, NULL, - nxt_unicode_block_1fe, + nxt_unicode_lower_case_block_1fe, NULL, NULL, NULL, @@ -1039,5 +1039,5 @@ static const uint32_t *nxt_unicode_blocks[] nxt_aligned(64) = { NULL, NULL, NULL, - nxt_unicode_block_208, + nxt_unicode_lower_case_block_208, }; diff --git a/nxt/nxt_unicode_lowcase.pl b/nxt/nxt_unicode_lower_case.pl similarity index 64% rename from nxt/nxt_unicode_lowcase.pl rename to nxt/nxt_unicode_lower_case.pl index aca17fcd..58de8764 100755 --- a/nxt/nxt_unicode_lowcase.pl +++ b/nxt/nxt_unicode_lower_case.pl @@ -7,25 +7,28 @@ use strict; # the minimum memory footprint for both 32-bit and 64-bit platforms. use constant BLOCK_SIZE => 128; -my %lowcase; +my %lower_case; my %blocks; my $max_block = 0; -my $max_lowcase = 0; +my $max_lower_case = 0; while (<>) { - if (/^(\w+); (C|S); (\w+);/) { - my ($symbol, $folding) = (hex $1, hex $3); - $lowcase{$symbol} = $folding; + my @line = split(";", $_); + + if ($line[13]) { + my ($symbol, $folding) = (hex $line[0], hex $line[13]); + + $lower_case{$symbol} = $folding; $blocks{int($symbol / BLOCK_SIZE)} = 1; - if ($max_lowcase < $symbol) { - $max_lowcase = $symbol; + if ($max_lower_case < $symbol) { + $max_lower_case = $symbol; } } } -my $last_block_size = $max_lowcase % BLOCK_SIZE + 1; +my $last_block_size = $max_lower_case % BLOCK_SIZE + 1; for my $block (sort { $a <=> $b } keys %blocks) { @@ -45,15 +48,15 @@ printf("\n/*\n" . ($blocks - 1) * BLOCK_SIZE * 4 + $last_block_size + $max_block * 4, ($blocks - 1) * BLOCK_SIZE * 4 + $last_block_size + $max_block * 8); -printf("#define NXT_UNICODE_MAX_LOWCASE 0x%05x\n\n", $max_lowcase); -printf("#define NXT_UNICODE_BLOCK_SIZE %d\n\n\n", BLOCK_SIZE); +printf("#define NXT_UNICODE_MAX_LOWER_CASE 0x%05x\n\n", $max_lower_case); +printf("#define NXT_UNICODE_BLOCK_SIZE %d\n\n\n", BLOCK_SIZE); for my $block (sort { $a <=> $b } keys %blocks) { my $block_size = ($block != $max_block) ? BLOCK_SIZE : $last_block_size; print "static const uint32_t "; - printf("nxt_unicode_block_%03x[%d] nxt_aligned(64) = {", + printf("nxt_unicode_lower_case_block_%03x[%d] nxt_aligned(64) = {", $block, $block_size); for my $c (0 .. $block_size - 1) { @@ -61,8 +64,8 @@ for my $block (sort { $a <=> $b } keys %blocks) { my $n = $block * BLOCK_SIZE + $c; - if (exists $lowcase{$n}) { - printf(" 0x%05x,", $lowcase{$n}); + if (exists $lower_case{$n}) { + printf(" 0x%05x,", $lower_case{$n}); } else { #print " .......,"; @@ -74,11 +77,12 @@ for my $block (sort { $a <=> $b } keys %blocks) { } -print "static const uint32_t *nxt_unicode_blocks[] nxt_aligned(64) = {\n"; +print "static const uint32_t *nxt_unicode_lower_case_blocks[]" . + " nxt_aligned(64) = {\n"; for my $block (0 .. $max_block) { if (exists($blocks{$block})) { - printf(" nxt_unicode_block_%03x,\n", $block); + printf(" nxt_unicode_lower_case_block_%03x,\n", $block); } else { print " NULL,\n"; diff --git a/nxt/nxt_utf8.c b/nxt/nxt_utf8.c index 73f356e2..5125f1dc 100644 --- a/nxt/nxt_utf8.c +++ b/nxt/nxt_utf8.c @@ -9,22 +9,16 @@ #include /* - * The nxt_unicode_lowcase.h file is the auto-generated file from - * the CaseFolding-6.3.0.txt file provided by Unicode, Inc.: + * The nxt_unicode_lower_case.h file is a file auto-generated from + * the UnicodeData.txt file version 6.3.0 provided by Unicode, Inc.: * - * ./nxt_unicode_lowcase.pl CaseFolding-6.3.0.txt - * - * This file should be copied to system specific nxt_unicode_SYSTEM_lowcase.h - * file and utf8_file_name_test should be built with this file. - * Then a correct system specific file should be generated: - * - * ./build/utf8_file_name_test | ./nxt_unicode_lowcase.pl + * ./nxt_unicode_lower_case.pl UnicodeData.txt * * Only common and simple case foldings are supported. Full case foldings - * is not supported. Combined characters are also not supported. + * are not supported. Combined characters are also not supported. */ -#include +#include u_char * @@ -184,9 +178,9 @@ nxt_utf8_casecmp(const u_char *start1, const u_char *start2, size_t len1, while (start1 < end1 && start2 < end2) { - u1 = nxt_utf8_lowcase(&start1, end1); + u1 = nxt_utf8_lower_case(&start1, end1); - u2 = nxt_utf8_lowcase(&start2, end2); + u2 = nxt_utf8_lower_case(&start2, end2); if (nxt_slow_path((u1 | u2) == 0xFFFFFFFF)) { return NXT_UTF8_SORT_INVALID; @@ -204,7 +198,7 @@ nxt_utf8_casecmp(const u_char *start1, const u_char *start2, size_t len1, uint32_t -nxt_utf8_lowcase(const u_char **start, const u_char *end) +nxt_utf8_lower_case(const u_char **start, const u_char *end) { uint32_t u; const uint32_t *block; @@ -214,13 +208,13 @@ nxt_utf8_lowcase(const u_char **start, const u_char *end) if (nxt_fast_path(u < 0x80)) { (*start)++; - return nxt_unicode_block_000[u]; + return nxt_unicode_lower_case_block_000[u]; } u = nxt_utf8_decode2(start, end); - if (u <= NXT_UNICODE_MAX_LOWCASE) { - block = nxt_unicode_blocks[u / NXT_UNICODE_BLOCK_SIZE]; + if (u <= NXT_UNICODE_MAX_LOWER_CASE) { + block = nxt_unicode_lower_case_blocks[u / NXT_UNICODE_BLOCK_SIZE]; if (block != NULL) { return block[u % NXT_UNICODE_BLOCK_SIZE]; diff --git a/nxt/nxt_utf8.h b/nxt/nxt_utf8.h index 24e53ff5..e14d4435 100644 --- a/nxt/nxt_utf8.h +++ b/nxt/nxt_utf8.h @@ -21,7 +21,8 @@ NXT_EXPORT uint32_t nxt_utf8_decode(const u_char **start, const u_char *end); NXT_EXPORT uint32_t nxt_utf8_decode2(const u_char **start, const u_char *end); NXT_EXPORT nxt_int_t nxt_utf8_casecmp(const u_char *start1, const u_char *start2, size_t len1, size_t len2); -NXT_EXPORT uint32_t nxt_utf8_lowcase(const u_char **start, const u_char *end); +NXT_EXPORT uint32_t nxt_utf8_lower_case(const u_char **start, + const u_char *end); NXT_EXPORT ssize_t nxt_utf8_length(const u_char *p, size_t len); NXT_EXPORT nxt_bool_t nxt_utf8_is_valid(const u_char *p, size_t len);