src/string.c

changeset 1161
747c4baed44f
parent 1155
b77d56a27e9c
child 1162
e3bb67b72d33
equal deleted inserted replaced
1160:4f02c1101f2e 1161:747c4baed44f
218 218
219 cxstring cx_strchr( 219 cxstring cx_strchr(
220 cxstring string, 220 cxstring string,
221 int chr 221 int chr
222 ) { 222 ) {
223 chr = 0xFF & chr; 223 char *ret = memchr(string.ptr, 0xFF & chr, string.length);
224 // TODO: improve by comparing multiple bytes at once 224 if (ret == NULL) return (cxstring) {NULL, 0};
225 for (size_t i = 0; i < string.length; i++) { 225 return (cxstring) {ret, string.length - (ret - string.ptr)};
226 if (string.ptr[i] == chr) {
227 return cx_strsubs(string, i);
228 }
229 }
230 return (cxstring) {NULL, 0};
231 } 226 }
232 227
233 cxmutstr cx_strchr_m( 228 cxmutstr cx_strchr_m(
234 cxmutstr string, 229 cxmutstr string,
235 int chr 230 int chr

mercurial