130 if (str.ptr == NULL) abort(); |
129 if (str.ptr == NULL) abort(); |
131 |
130 |
132 // concatenate strings |
131 // concatenate strings |
133 size_t pos = str.length; |
132 size_t pos = str.length; |
134 str.length = slen; |
133 str.length = slen; |
135 cx_for_n(i, count) { |
134 for (size_t i = 0; i < count; i++) { |
136 cxstring s = strings[i]; |
135 cxstring s = strings[i]; |
137 memcpy(str.ptr + pos, s.ptr, s.length); |
136 memcpy(str.ptr + pos, s.ptr, s.length); |
138 pos += s.length; |
137 pos += s.length; |
139 } |
138 } |
140 |
139 |
191 cxstring string, |
190 cxstring string, |
192 int chr |
191 int chr |
193 ) { |
192 ) { |
194 chr = 0xFF & chr; |
193 chr = 0xFF & chr; |
195 // TODO: improve by comparing multiple bytes at once |
194 // TODO: improve by comparing multiple bytes at once |
196 cx_for_n(i, string.length) { |
195 for (size_t i = 0; i < string.length; i++) { |
197 if (string.ptr[i] == chr) { |
196 if (string.ptr[i] == chr) { |
198 return cx_strsubs(string, i); |
197 return cx_strsubs(string, i); |
199 } |
198 } |
200 } |
199 } |
201 return (cxstring) {NULL, 0}; |
200 return (cxstring) {NULL, 0}; |
554 suffix.ptr, suffix.length) == 0; |
553 suffix.ptr, suffix.length) == 0; |
555 #endif |
554 #endif |
556 } |
555 } |
557 |
556 |
558 void cx_strlower(cxmutstr string) { |
557 void cx_strlower(cxmutstr string) { |
559 cx_for_n(i, string.length) { |
558 for (size_t i = 0; i < string.length; i++) { |
560 string.ptr[i] = (char) tolower(string.ptr[i]); |
559 string.ptr[i] = (char) tolower(string.ptr[i]); |
561 } |
560 } |
562 } |
561 } |
563 |
562 |
564 void cx_strupper(cxmutstr string) { |
563 void cx_strupper(cxmutstr string) { |
565 cx_for_n(i, string.length) { |
564 for (size_t i = 0; i < string.length; i++) { |
566 string.ptr[i] = (char) toupper(string.ptr[i]); |
565 string.ptr[i] = (char) toupper(string.ptr[i]); |
567 } |
566 } |
568 } |
567 } |
569 |
568 |
570 #ifndef CX_STRREPLACE_INDEX_BUFFER_SIZE |
569 #ifndef CX_STRREPLACE_INDEX_BUFFER_SIZE |
746 delim.length = ctx->delim.length; |
745 delim.length = ctx->delim.length; |
747 } |
746 } |
748 |
747 |
749 // if more delimiters are specified, check them now |
748 // if more delimiters are specified, check them now |
750 if (ctx->delim_more_count > 0) { |
749 if (ctx->delim_more_count > 0) { |
751 cx_for_n(i, ctx->delim_more_count) { |
750 for (size_t i = 0; i < ctx->delim_more_count; i++) { |
752 cxstring d = cx_strstr(haystack, ctx->delim_more[i]); |
751 cxstring d = cx_strstr(haystack, ctx->delim_more[i]); |
753 if (d.length > 0 && (delim.length == 0 || d.ptr < delim.ptr)) { |
752 if (d.length > 0 && (delim.length == 0 || d.ptr < delim.ptr)) { |
754 delim.ptr = d.ptr; |
753 delim.ptr = d.ptr; |
755 delim.length = ctx->delim_more[i].length; |
754 delim.length = ctx->delim_more[i].length; |
756 } |
755 } |