src/string.c

changeset 1646
85fd3ff8416e
parent 1644
bbe3199e37fc
equal deleted inserted replaced
1644:bbe3199e37fc 1646:85fd3ff8416e
246 #ifndef CX_STRSTR_SBO_SIZE 246 #ifndef CX_STRSTR_SBO_SIZE
247 #define CX_STRSTR_SBO_SIZE 128 247 #define CX_STRSTR_SBO_SIZE 128
248 #endif 248 #endif
249 const unsigned cx_strstr_sbo_size = CX_STRSTR_SBO_SIZE; 249 const unsigned cx_strstr_sbo_size = CX_STRSTR_SBO_SIZE;
250 250
251 cxstring cx_strstr( 251 cxstring cx_strstr_(cxstring haystack, cxstring needle) {
252 cxstring haystack,
253 cxstring needle
254 ) {
255 if (needle.length == 0) { 252 if (needle.length == 0) {
256 return haystack; 253 return haystack;
257 } 254 }
258 255
259 // optimize for single-char needles 256 // optimize for single-char needles
319 } 316 }
320 317
321 return result; 318 return result;
322 } 319 }
323 320
324 cxmutstr cx_strstr_m( 321 cxmutstr cx_strstr_m_(
325 cxmutstr haystack, 322 cxmutstr haystack,
326 cxstring needle 323 cxstring needle
327 ) { 324 ) {
328 cxstring result = cx_strstr(cx_strcast(haystack), needle); 325 cxstring result = cx_strstr(cx_strcast(haystack), needle);
329 return (cxmutstr) {(char *) result.ptr, result.length}; 326 return (cxmutstr) {(char *) result.ptr, result.length};

mercurial