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 | 134M | #define njs_length(s) (sizeof(s) - 1) |
25 | 49.4M | #define njs_str(s) { njs_length(s), (u_char *) s } |
26 | 0 | #define njs_null_str { 0, NULL } |
27 | 49.3M | #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 | 14.0k | { |
33 | 14.0k | return (u_char) ((c >= 'A' && c <= 'Z') ? c | 0x20 : c); |
34 | 14.0k | } 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 njs_string.c:njs_lower_case Line | Count | Source | 32 | 14.0k | { | 33 | 14.0k | return (u_char) ((c >= 'A' && c <= 'Z') ? c | 0x20 : c); | 34 | 14.0k | } |
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_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_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_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_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_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_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 | 7.05M | { |
47 | 7.05M | switch (c) { |
48 | 3.80k | case 0x09: /* <TAB> */ |
49 | 62.4k | case 0x0A: /* <LF> */ |
50 | 157k | case 0x0B: /* <VT> */ |
51 | 159k | case 0x0C: /* <FF> */ |
52 | 161k | case 0x0D: /* <CR> */ |
53 | 172k | case 0x20: /* <SP> */ |
54 | 172k | return 1; |
55 | | |
56 | 6.88M | default: |
57 | 6.88M | return 0; |
58 | 7.05M | } |
59 | 7.05M | } 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 | 7.05M | { | 47 | 7.05M | switch (c) { | 48 | 3.80k | case 0x09: /* <TAB> */ | 49 | 62.4k | case 0x0A: /* <LF> */ | 50 | 157k | case 0x0B: /* <VT> */ | 51 | 159k | case 0x0C: /* <FF> */ | 52 | 161k | case 0x0D: /* <CR> */ | 53 | 172k | case 0x20: /* <SP> */ | 54 | 172k | return 1; | 55 | | | 56 | 6.88M | default: | 57 | 6.88M | return 0; | 58 | 7.05M | } | 59 | 7.05M | } |
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_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_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_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 | 336k | { |
65 | 36.9M | while (p < last) { |
66 | | |
67 | 36.8M | if (*p == c) { |
68 | 237k | return p; |
69 | 237k | } |
70 | | |
71 | 36.6M | p++; |
72 | 36.6M | } |
73 | | |
74 | 98.4k | return NULL; |
75 | 336k | } 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 | 17.8k | { | 65 | 106k | while (p < last) { | 66 | | | 67 | 97.9k | if (*p == c) { | 68 | 8.90k | return p; | 69 | 8.90k | } | 70 | | | 71 | 89.0k | p++; | 72 | 89.0k | } | 73 | | | 74 | 8.90k | return NULL; | 75 | 17.8k | } |
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 | 318k | { | 65 | 36.8M | while (p < last) { | 66 | | | 67 | 36.7M | if (*p == c) { | 68 | 228k | return p; | 69 | 228k | } | 70 | | | 71 | 36.5M | p++; | 72 | 36.5M | } | 73 | | | 74 | 89.5k | return NULL; | 75 | 318k | } |
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_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_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_str.c:njs_strlchr Unexecuted instantiation: njs_random.c:njs_strlchr |
76 | | |
77 | | |
78 | | #define \ |
79 | | njs_strlen(s) \ |
80 | 662k | strlen((char *) s) |
81 | | |
82 | | |
83 | | #define \ |
84 | | njs_cpymem(dst, src, n) \ |
85 | 22.6M | (((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 | 293k | (u_char *) strchr((const char *) s1, (int) c) |
96 | | |
97 | | |
98 | | #define \ |
99 | | njs_memset(buf, c, length) \ |
100 | 147M | (void) memset(buf, c, length) |
101 | | |
102 | | |
103 | | #define \ |
104 | | njs_memzero(buf, length) \ |
105 | 91.5M | (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 | | 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 | | { |
120 | | volatile u_char *p = (volatile u_char *) buf; |
121 | | |
122 | | while (length != 0) { |
123 | | *p++ = 0; |
124 | | length--; |
125 | | } |
126 | | } |
127 | | #endif |
128 | | |
129 | | |
130 | | #define \ |
131 | | njs_strstr_eq(s1, s2) \ |
132 | 270k | (((s1)->length == (s2)->length) \ |
133 | 270k | && (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 | | #define \ |
143 | | njs_strstr_starts_with(str, prefix) \ |
144 | | (((str)->length >= (prefix)->length) \ |
145 | | && (memcmp((str)->start, (prefix)->start, (prefix)->length) == 0)) |
146 | | |
147 | | |
148 | | NJS_EXPORT njs_int_t njs_strncasecmp(u_char *s1, u_char *s2, size_t n); |
149 | | |
150 | | |
151 | | #endif /* _NJS_STR_H_INCLUDED_ */ |