Line | Count | Source |
1 | | |
2 | | /* |
3 | | * Copyright (C) Igor Sysoev |
4 | | * Copyright (C) NGINX, Inc. |
5 | | */ |
6 | | |
7 | | #ifndef _NJS_STR_H_INCLUDED_ |
8 | | #define _NJS_STR_H_INCLUDED_ |
9 | | |
10 | | |
11 | | typedef struct { |
12 | | size_t length; |
13 | | u_char *start; |
14 | | } njs_str_t; |
15 | | |
16 | | |
17 | | /* |
18 | | * C99 allows to assign struct as compound literal with struct name cast only. |
19 | | * SunC however issues error on the cast in struct static initialization: |
20 | | * non-constant initializer: op "NAME" |
21 | | * So a separate njs_str_value() macro is intended to use in assignment. |
22 | | */ |
23 | | |
24 | 12.6M | #define njs_length(s) (sizeof(s) - 1) |
25 | 289k | #define njs_str(s) { njs_length(s), (u_char *) s } |
26 | 0 | #define njs_null_str { 0, NULL } |
27 | 261k | #define njs_str_value(s) (njs_str_t) njs_str(s) |
28 | | |
29 | | |
30 | | njs_inline u_char |
31 | | njs_lower_case(u_char c) |
32 | 0 | { |
33 | 0 | return (u_char) ((c >= 'A' && c <= 'Z') ? c | 0x20 : c); |
34 | 0 | } Unexecuted instantiation: njs_shell.c:njs_lower_case Unexecuted instantiation: njs_arr.c:njs_lower_case Unexecuted instantiation: njs_rbtree.c:njs_lower_case Unexecuted instantiation: njs_mp.c:njs_lower_case Unexecuted instantiation: njs_sprintf.c:njs_lower_case Unexecuted instantiation: njs_value.c:njs_lower_case Unexecuted instantiation: njs_atom.c:njs_lower_case Unexecuted instantiation: njs_vm.c:njs_lower_case Unexecuted instantiation: njs_vmcode.c:njs_lower_case Unexecuted instantiation: njs_parser.c:njs_lower_case Unexecuted instantiation: njs_variable.c:njs_lower_case Unexecuted instantiation: njs_scope.c:njs_lower_case Unexecuted instantiation: njs_generator.c:njs_lower_case Unexecuted instantiation: njs_disassembler.c:njs_lower_case Unexecuted instantiation: njs_module.c:njs_lower_case Unexecuted instantiation: njs_extern.c:njs_lower_case Unexecuted instantiation: njs_number.c:njs_lower_case Unexecuted instantiation: njs_symbol.c:njs_lower_case Unexecuted instantiation: njs_string.c:njs_lower_case Unexecuted instantiation: njs_object.c:njs_lower_case Unexecuted instantiation: njs_object_prop.c:njs_lower_case Unexecuted instantiation: njs_array.c:njs_lower_case Unexecuted instantiation: njs_json.c:njs_lower_case Unexecuted instantiation: njs_function.c:njs_lower_case Unexecuted instantiation: njs_regexp.c:njs_lower_case Unexecuted instantiation: njs_date.c:njs_lower_case Unexecuted instantiation: njs_error.c:njs_lower_case Unexecuted instantiation: njs_array_buffer.c:njs_lower_case Unexecuted instantiation: njs_typed_array.c:njs_lower_case Unexecuted instantiation: njs_promise.c:njs_lower_case Unexecuted instantiation: njs_iterator.c:njs_lower_case Unexecuted instantiation: njs_async.c:njs_lower_case Unexecuted instantiation: njs_builtin.c:njs_lower_case Unexecuted instantiation: njs_regex.c:njs_lower_case Unexecuted instantiation: njs_buffer.c:njs_lower_case Unexecuted instantiation: njs_modules.c:njs_lower_case Unexecuted instantiation: njs_dtoa.c:njs_lower_case Unexecuted instantiation: njs_dtoa_fixed.c:njs_lower_case Unexecuted instantiation: njs_strtod.c:njs_lower_case Unexecuted instantiation: njs_djb_hash.c:njs_lower_case Unexecuted instantiation: njs_utf8.c:njs_lower_case Unexecuted instantiation: njs_utf16.c:njs_lower_case Unexecuted instantiation: njs_flathsh.c:njs_lower_case Unexecuted instantiation: njs_trace.c:njs_lower_case Unexecuted instantiation: njs_malloc.c:njs_lower_case Unexecuted instantiation: njs_utils.c:njs_lower_case Unexecuted instantiation: njs_chb.c:njs_lower_case Unexecuted instantiation: njs_lexer.c:njs_lower_case Unexecuted instantiation: njs_boolean.c:njs_lower_case Unexecuted instantiation: njs_math.c:njs_lower_case Unexecuted instantiation: njs_encoding.c:njs_lower_case Unexecuted instantiation: njs_crypto_module.c:njs_lower_case Unexecuted instantiation: njs_md5.c:njs_lower_case Unexecuted instantiation: njs_sha1.c:njs_lower_case Unexecuted instantiation: njs_sha2.c:njs_lower_case Unexecuted instantiation: njs_webcrypto_module.c:njs_lower_case Unexecuted instantiation: njs_fs_module.c:njs_lower_case Unexecuted instantiation: njs_query_string_module.c:njs_lower_case Unexecuted instantiation: njs_diyfp.c:njs_lower_case Unexecuted instantiation: njs_str.c:njs_lower_case Unexecuted instantiation: njs_random.c:njs_lower_case |
35 | | |
36 | | |
37 | | njs_inline u_char |
38 | | njs_upper_case(u_char c) |
39 | 0 | { |
40 | 0 | return (u_char) ((c >= 'a' && c <= 'z') ? c & 0xDF : c); |
41 | 0 | } Unexecuted instantiation: njs_shell.c:njs_upper_case Unexecuted instantiation: njs_arr.c:njs_upper_case Unexecuted instantiation: njs_rbtree.c:njs_upper_case Unexecuted instantiation: njs_mp.c:njs_upper_case Unexecuted instantiation: njs_sprintf.c:njs_upper_case Unexecuted instantiation: njs_value.c:njs_upper_case Unexecuted instantiation: njs_atom.c:njs_upper_case Unexecuted instantiation: njs_vm.c:njs_upper_case Unexecuted instantiation: njs_vmcode.c:njs_upper_case Unexecuted instantiation: njs_parser.c:njs_upper_case Unexecuted instantiation: njs_variable.c:njs_upper_case Unexecuted instantiation: njs_scope.c:njs_upper_case Unexecuted instantiation: njs_generator.c:njs_upper_case Unexecuted instantiation: njs_disassembler.c:njs_upper_case Unexecuted instantiation: njs_module.c:njs_upper_case Unexecuted instantiation: njs_extern.c:njs_upper_case Unexecuted instantiation: njs_number.c:njs_upper_case Unexecuted instantiation: njs_symbol.c:njs_upper_case Unexecuted instantiation: njs_string.c:njs_upper_case Unexecuted instantiation: njs_object.c:njs_upper_case Unexecuted instantiation: njs_object_prop.c:njs_upper_case Unexecuted instantiation: njs_array.c:njs_upper_case Unexecuted instantiation: njs_json.c:njs_upper_case Unexecuted instantiation: njs_function.c:njs_upper_case Unexecuted instantiation: njs_regexp.c:njs_upper_case Unexecuted instantiation: njs_date.c:njs_upper_case Unexecuted instantiation: njs_error.c:njs_upper_case Unexecuted instantiation: njs_array_buffer.c:njs_upper_case Unexecuted instantiation: njs_typed_array.c:njs_upper_case Unexecuted instantiation: njs_promise.c:njs_upper_case Unexecuted instantiation: njs_iterator.c:njs_upper_case Unexecuted instantiation: njs_async.c:njs_upper_case Unexecuted instantiation: njs_builtin.c:njs_upper_case Unexecuted instantiation: njs_regex.c:njs_upper_case Unexecuted instantiation: njs_buffer.c:njs_upper_case Unexecuted instantiation: njs_modules.c:njs_upper_case Unexecuted instantiation: njs_dtoa.c:njs_upper_case Unexecuted instantiation: njs_dtoa_fixed.c:njs_upper_case Unexecuted instantiation: njs_strtod.c:njs_upper_case Unexecuted instantiation: njs_djb_hash.c:njs_upper_case Unexecuted instantiation: njs_utf8.c:njs_upper_case Unexecuted instantiation: njs_utf16.c:njs_upper_case Unexecuted instantiation: njs_flathsh.c:njs_upper_case Unexecuted instantiation: njs_trace.c:njs_upper_case Unexecuted instantiation: njs_malloc.c:njs_upper_case Unexecuted instantiation: njs_utils.c:njs_upper_case Unexecuted instantiation: njs_chb.c:njs_upper_case Unexecuted instantiation: njs_lexer.c:njs_upper_case Unexecuted instantiation: njs_boolean.c:njs_upper_case Unexecuted instantiation: njs_math.c:njs_upper_case Unexecuted instantiation: njs_encoding.c:njs_upper_case Unexecuted instantiation: njs_crypto_module.c:njs_upper_case Unexecuted instantiation: njs_md5.c:njs_upper_case Unexecuted instantiation: njs_sha1.c:njs_upper_case Unexecuted instantiation: njs_sha2.c:njs_upper_case Unexecuted instantiation: njs_webcrypto_module.c:njs_upper_case Unexecuted instantiation: njs_fs_module.c:njs_upper_case Unexecuted instantiation: njs_query_string_module.c:njs_upper_case Unexecuted instantiation: njs_diyfp.c:njs_upper_case Unexecuted instantiation: njs_str.c:njs_upper_case Unexecuted instantiation: njs_random.c:njs_upper_case |
42 | | |
43 | | |
44 | | njs_inline njs_bool_t |
45 | | njs_is_whitespace(u_char c) |
46 | 1.80M | { |
47 | 1.80M | switch (c) { |
48 | 650 | case 0x09: /* <TAB> */ |
49 | 7.15k | case 0x0A: /* <LF> */ |
50 | 137k | case 0x0B: /* <VT> */ |
51 | 137k | case 0x0C: /* <FF> */ |
52 | 155k | case 0x0D: /* <CR> */ |
53 | 155k | case 0x20: /* <SP> */ |
54 | 155k | return 1; |
55 | | |
56 | 1.65M | default: |
57 | 1.65M | return 0; |
58 | 1.80M | } |
59 | 1.80M | } Unexecuted instantiation: njs_shell.c:njs_is_whitespace Unexecuted instantiation: njs_arr.c:njs_is_whitespace Unexecuted instantiation: njs_rbtree.c:njs_is_whitespace Unexecuted instantiation: njs_mp.c:njs_is_whitespace Unexecuted instantiation: njs_sprintf.c:njs_is_whitespace Unexecuted instantiation: njs_value.c:njs_is_whitespace Unexecuted instantiation: njs_atom.c:njs_is_whitespace Unexecuted instantiation: njs_vm.c:njs_is_whitespace Unexecuted instantiation: njs_vmcode.c:njs_is_whitespace Unexecuted instantiation: njs_parser.c:njs_is_whitespace Unexecuted instantiation: njs_variable.c:njs_is_whitespace Unexecuted instantiation: njs_scope.c:njs_is_whitespace Unexecuted instantiation: njs_generator.c:njs_is_whitespace Unexecuted instantiation: njs_disassembler.c:njs_is_whitespace Unexecuted instantiation: njs_module.c:njs_is_whitespace Unexecuted instantiation: njs_extern.c:njs_is_whitespace Unexecuted instantiation: njs_number.c:njs_is_whitespace Unexecuted instantiation: njs_symbol.c:njs_is_whitespace njs_string.c:njs_is_whitespace Line | Count | Source | 46 | 1.80M | { | 47 | 1.80M | switch (c) { | 48 | 650 | case 0x09: /* <TAB> */ | 49 | 7.15k | case 0x0A: /* <LF> */ | 50 | 137k | case 0x0B: /* <VT> */ | 51 | 137k | case 0x0C: /* <FF> */ | 52 | 155k | case 0x0D: /* <CR> */ | 53 | 155k | case 0x20: /* <SP> */ | 54 | 155k | return 1; | 55 | | | 56 | 1.65M | default: | 57 | 1.65M | return 0; | 58 | 1.80M | } | 59 | 1.80M | } |
Unexecuted instantiation: njs_object.c:njs_is_whitespace Unexecuted instantiation: njs_object_prop.c:njs_is_whitespace Unexecuted instantiation: njs_array.c:njs_is_whitespace Unexecuted instantiation: njs_json.c:njs_is_whitespace Unexecuted instantiation: njs_function.c:njs_is_whitespace Unexecuted instantiation: njs_regexp.c:njs_is_whitespace Unexecuted instantiation: njs_date.c:njs_is_whitespace Unexecuted instantiation: njs_error.c:njs_is_whitespace Unexecuted instantiation: njs_array_buffer.c:njs_is_whitespace Unexecuted instantiation: njs_typed_array.c:njs_is_whitespace Unexecuted instantiation: njs_promise.c:njs_is_whitespace Unexecuted instantiation: njs_iterator.c:njs_is_whitespace Unexecuted instantiation: njs_async.c:njs_is_whitespace Unexecuted instantiation: njs_builtin.c:njs_is_whitespace Unexecuted instantiation: njs_regex.c:njs_is_whitespace Unexecuted instantiation: njs_buffer.c:njs_is_whitespace Unexecuted instantiation: njs_modules.c:njs_is_whitespace Unexecuted instantiation: njs_dtoa.c:njs_is_whitespace Unexecuted instantiation: njs_dtoa_fixed.c:njs_is_whitespace Unexecuted instantiation: njs_strtod.c:njs_is_whitespace Unexecuted instantiation: njs_djb_hash.c:njs_is_whitespace Unexecuted instantiation: njs_utf8.c:njs_is_whitespace Unexecuted instantiation: njs_utf16.c:njs_is_whitespace Unexecuted instantiation: njs_flathsh.c:njs_is_whitespace Unexecuted instantiation: njs_trace.c:njs_is_whitespace Unexecuted instantiation: njs_malloc.c:njs_is_whitespace Unexecuted instantiation: njs_utils.c:njs_is_whitespace Unexecuted instantiation: njs_chb.c:njs_is_whitespace Unexecuted instantiation: njs_lexer.c:njs_is_whitespace Unexecuted instantiation: njs_boolean.c:njs_is_whitespace Unexecuted instantiation: njs_math.c:njs_is_whitespace Unexecuted instantiation: njs_encoding.c:njs_is_whitespace Unexecuted instantiation: njs_crypto_module.c:njs_is_whitespace Unexecuted instantiation: njs_md5.c:njs_is_whitespace Unexecuted instantiation: njs_sha1.c:njs_is_whitespace Unexecuted instantiation: njs_sha2.c:njs_is_whitespace Unexecuted instantiation: njs_webcrypto_module.c:njs_is_whitespace Unexecuted instantiation: njs_fs_module.c:njs_is_whitespace Unexecuted instantiation: njs_query_string_module.c:njs_is_whitespace Unexecuted instantiation: njs_diyfp.c:njs_is_whitespace Unexecuted instantiation: njs_str.c:njs_is_whitespace Unexecuted instantiation: njs_random.c:njs_is_whitespace |
60 | | |
61 | | |
62 | | njs_inline u_char * |
63 | | njs_strlchr(u_char *p, u_char *last, u_char c) |
64 | 14.7k | { |
65 | 42.1k | while (p < last) { |
66 | | |
67 | 36.8k | if (*p == c) { |
68 | 9.44k | return p; |
69 | 9.44k | } |
70 | | |
71 | 27.3k | p++; |
72 | 27.3k | } |
73 | | |
74 | 5.33k | return NULL; |
75 | 14.7k | } Unexecuted instantiation: njs_shell.c:njs_strlchr Unexecuted instantiation: njs_arr.c:njs_strlchr Unexecuted instantiation: njs_rbtree.c:njs_strlchr Unexecuted instantiation: njs_mp.c:njs_strlchr Unexecuted instantiation: njs_sprintf.c:njs_strlchr Unexecuted instantiation: njs_value.c:njs_strlchr Unexecuted instantiation: njs_atom.c:njs_strlchr Line | Count | Source | 64 | 1.89k | { | 65 | 11.3k | while (p < last) { | 66 | | | 67 | 10.4k | if (*p == c) { | 68 | 948 | return p; | 69 | 948 | } | 70 | | | 71 | 9.48k | p++; | 72 | 9.48k | } | 73 | | | 74 | 948 | return NULL; | 75 | 1.89k | } |
Unexecuted instantiation: njs_vmcode.c:njs_strlchr Unexecuted instantiation: njs_parser.c:njs_strlchr Unexecuted instantiation: njs_variable.c:njs_strlchr Unexecuted instantiation: njs_scope.c:njs_strlchr Unexecuted instantiation: njs_generator.c:njs_strlchr Unexecuted instantiation: njs_disassembler.c:njs_strlchr Unexecuted instantiation: njs_module.c:njs_strlchr Unexecuted instantiation: njs_extern.c:njs_strlchr Unexecuted instantiation: njs_number.c:njs_strlchr Unexecuted instantiation: njs_symbol.c:njs_strlchr Line | Count | Source | 64 | 12.8k | { | 65 | 30.7k | while (p < last) { | 66 | | | 67 | 26.4k | if (*p == c) { | 68 | 8.49k | return p; | 69 | 8.49k | } | 70 | | | 71 | 17.9k | p++; | 72 | 17.9k | } | 73 | | | 74 | 4.38k | return NULL; | 75 | 12.8k | } |
Unexecuted instantiation: njs_object.c:njs_strlchr Unexecuted instantiation: njs_object_prop.c:njs_strlchr Unexecuted instantiation: njs_array.c:njs_strlchr Unexecuted instantiation: njs_json.c:njs_strlchr Unexecuted instantiation: njs_function.c:njs_strlchr Unexecuted instantiation: njs_regexp.c:njs_strlchr Unexecuted instantiation: njs_date.c:njs_strlchr Unexecuted instantiation: njs_error.c:njs_strlchr Unexecuted instantiation: njs_array_buffer.c:njs_strlchr Unexecuted instantiation: njs_typed_array.c:njs_strlchr Unexecuted instantiation: njs_promise.c:njs_strlchr Unexecuted instantiation: njs_iterator.c:njs_strlchr Unexecuted instantiation: njs_async.c:njs_strlchr Unexecuted instantiation: njs_builtin.c:njs_strlchr Unexecuted instantiation: njs_regex.c:njs_strlchr Unexecuted instantiation: njs_buffer.c:njs_strlchr Unexecuted instantiation: njs_modules.c:njs_strlchr Unexecuted instantiation: njs_dtoa.c:njs_strlchr Unexecuted instantiation: njs_dtoa_fixed.c:njs_strlchr Unexecuted instantiation: njs_strtod.c:njs_strlchr Unexecuted instantiation: njs_djb_hash.c:njs_strlchr Unexecuted instantiation: njs_utf8.c:njs_strlchr Unexecuted instantiation: njs_utf16.c:njs_strlchr Unexecuted instantiation: njs_flathsh.c:njs_strlchr Unexecuted instantiation: njs_trace.c:njs_strlchr Unexecuted instantiation: njs_malloc.c:njs_strlchr Unexecuted instantiation: njs_utils.c:njs_strlchr Unexecuted instantiation: njs_chb.c:njs_strlchr Unexecuted instantiation: njs_lexer.c:njs_strlchr Unexecuted instantiation: njs_boolean.c:njs_strlchr Unexecuted instantiation: njs_math.c:njs_strlchr Unexecuted instantiation: njs_encoding.c:njs_strlchr Unexecuted instantiation: njs_crypto_module.c:njs_strlchr Unexecuted instantiation: njs_md5.c:njs_strlchr Unexecuted instantiation: njs_sha1.c:njs_strlchr Unexecuted instantiation: njs_sha2.c:njs_strlchr Unexecuted instantiation: njs_webcrypto_module.c:njs_strlchr Unexecuted instantiation: njs_fs_module.c:njs_strlchr Unexecuted instantiation: njs_query_string_module.c:njs_strlchr Unexecuted instantiation: njs_diyfp.c:njs_strlchr Unexecuted instantiation: njs_str.c:njs_strlchr Unexecuted instantiation: njs_random.c:njs_strlchr |
76 | | |
77 | | |
78 | | #define \ |
79 | | njs_strlen(s) \ |
80 | 170k | strlen((char *) s) |
81 | | |
82 | | |
83 | | #define \ |
84 | | njs_cpymem(dst, src, n) \ |
85 | 5.02M | (((u_char *) memcpy(dst, src, n)) + (n)) |
86 | | |
87 | | |
88 | | #define \ |
89 | | njs_strncmp(s1, s2, n) \ |
90 | 0 | strncmp((char *) s1, (char *) s2, n) |
91 | | |
92 | | |
93 | | #define \ |
94 | | njs_strchr(s1, c) \ |
95 | 33.1k | (u_char *) strchr((const char *) s1, (int) c) |
96 | | |
97 | | |
98 | | #define \ |
99 | | njs_memset(buf, c, length) \ |
100 | 94.9M | (void) memset(buf, c, length) |
101 | | |
102 | | |
103 | | #define \ |
104 | | njs_memzero(buf, length) \ |
105 | 40.1M | (void) memset(buf, 0, length) |
106 | | |
107 | | |
108 | | #if (NJS_HAVE_EXPLICIT_BZERO && !NJS_HAVE_MEMORY_SANITIZER) |
109 | | #define \ |
110 | | njs_explicit_memzero(buf, length) \ |
111 | 0 | explicit_bzero(buf, length) |
112 | | #elif (NJS_HAVE_EXPLICIT_MEMSET) |
113 | | #define \ |
114 | | njs_explicit_memzero(buf, length) \ |
115 | | (void) explicit_memset(buf, 0, length) |
116 | | #else |
117 | | njs_inline void |
118 | | njs_explicit_memzero(void *buf, size_t length) |
119 | 0 | { |
120 | 0 | volatile u_char *p = (volatile u_char *) buf; |
121 | |
|
122 | 0 | while (length != 0) { |
123 | 0 | *p++ = 0; |
124 | 0 | length--; |
125 | 0 | } |
126 | 0 | } Unexecuted instantiation: njs_md5.c:njs_explicit_memzero Unexecuted instantiation: njs_sha1.c:njs_explicit_memzero Unexecuted instantiation: njs_sha2.c:njs_explicit_memzero |
127 | | #endif |
128 | | |
129 | | |
130 | | #define \ |
131 | | njs_strstr_eq(s1, s2) \ |
132 | 66.8k | (((s1)->length == (s2)->length) \ |
133 | 66.8k | && (memcmp((s1)->start, (s2)->start, (s1)->length) == 0)) |
134 | | |
135 | | |
136 | | #define \ |
137 | | njs_strstr_case_eq(s1, s2) \ |
138 | 0 | (((s1)->length == (s2)->length) \ |
139 | 0 | && (njs_strncasecmp((s1)->start, (s2)->start, (s1)->length) == 0)) |
140 | | |
141 | | |
142 | | NJS_EXPORT njs_int_t njs_strncasecmp(u_char *s1, u_char *s2, size_t n); |
143 | | |
144 | | |
145 | | #endif /* _NJS_STR_H_INCLUDED_ */ |