src/string.c

changeset 1676
f889ffd07c86
parent 1674
8b0f162ac88e
child 1677
1d73c7302fbc
equal deleted inserted replaced
1675:36c0fb2b60b2 1676:f889ffd07c86
176 } 176 }
177 177
178 return (cxstring) {string.ptr + start, length}; 178 return (cxstring) {string.ptr + start, length};
179 } 179 }
180 180
181 cxstring cx_strchr( 181 cxstring cx_strchr_(
182 cxstring string, 182 cxstring string,
183 int chr 183 int chr
184 ) { 184 ) {
185 char *ret = memchr(string.ptr, 0xFF & chr, string.length); 185 char *ret = memchr(string.ptr, 0xFF & chr, string.length);
186 if (ret == NULL) return (cxstring) {NULL, 0}; 186 if (ret == NULL) return (cxstring) {NULL, 0};
187 return (cxstring) {ret, string.length - (ret - string.ptr)}; 187 return (cxstring) {ret, string.length - (ret - string.ptr)};
188 } 188 }
189 189
190 cxmutstr cx_strchr_m( 190 cxstring cx_strrchr_(
191 cxmutstr string,
192 int chr
193 ) {
194 cxstring result = cx_strchr(cx_strcast(string), chr);
195 return (cxmutstr) {(char *) result.ptr, result.length};
196 }
197
198 cxstring cx_strrchr(
199 cxstring string, 191 cxstring string,
200 int chr 192 int chr
201 ) { 193 ) {
202 #ifdef WITH_MEMRCHR 194 #ifdef WITH_MEMRCHR
203 char *ret = memrchr(string.ptr, 0xFF & chr, string.length); 195 char *ret = memrchr(string.ptr, 0xFF & chr, string.length);
212 return cx_strsubs(string, i); 204 return cx_strsubs(string, i);
213 } 205 }
214 } 206 }
215 return (cxstring) {NULL, 0}; 207 return (cxstring) {NULL, 0};
216 #endif 208 #endif
217 }
218
219 cxmutstr cx_strrchr_m(
220 cxmutstr string,
221 int chr
222 ) {
223 cxstring result = cx_strrchr(cx_strcast(string), chr);
224 return (cxmutstr) {(char *) result.ptr, result.length};
225 } 209 }
226 210
227 #ifndef CX_STRSTR_SBO_SIZE 211 #ifndef CX_STRSTR_SBO_SIZE
228 #define CX_STRSTR_SBO_SIZE 128 212 #define CX_STRSTR_SBO_SIZE 128
229 #endif 213 #endif

mercurial