src/string.c

changeset 318
348fd9cb7b14
parent 317
ebae0e434898
child 319
0380e438a7ce
equal deleted inserted replaced
317:ebae0e434898 318:348fd9cb7b14
199 ret.ptr = s.ptr + pos; 199 ret.ptr = s.ptr + pos;
200 } 200 }
201 return ret; 201 return ret;
202 } 202 }
203 203
204 scstr_t scstrsubs(scstr_t s, size_t start) { 204 scstr_t scstrsubs(scstr_t string, size_t start) {
205 return scstrsubsl (s, start, s.length-start); 205 return scstrsubsl(string, start, string.length-start);
206 } 206 }
207 207
208 scstr_t scstrsubsl(scstr_t s, size_t start, size_t length) { 208 scstr_t scstrsubsl(scstr_t s, size_t start, size_t length) {
209 size_t pos; 209 size_t pos;
210 scstr_t ret = { NULL, 0 }; 210 scstr_t ret = { NULL, 0 };
213 } 213 }
214 return ret; 214 return ret;
215 } 215 }
216 216
217 217
218 int ucx_strchr(const char *string, size_t length, int chr, size_t *pos) { 218 static int ucx_strchr(const char *str, size_t length, int chr, size_t *pos) {
219 for(size_t i=0;i<length;i++) { 219 for(size_t i=0;i<length;i++) {
220 if(string[i] == chr) { 220 if(str[i] == chr) {
221 *pos = i; 221 *pos = i;
222 return 1; 222 return 1;
223 } 223 }
224 } 224 }
225 return 0; 225 return 0;
226 } 226 }
227 227
228 int ucx_strrchr(const char *string, size_t length, int chr, size_t *pos) { 228 static int ucx_strrchr(const char *str, size_t length, int chr, size_t *pos) {
229 if(length > 0) { 229 if(length > 0) {
230 for(size_t i=length ; i>0 ; i--) { 230 for(size_t i=length ; i>0 ; i--) {
231 if(string[i-1] == chr) { 231 if(str[i-1] == chr) {
232 *pos = i-1; 232 *pos = i-1;
233 return 1; 233 return 1;
234 } 234 }
235 } 235 }
236 } 236 }
276 if (!useheap) ((uint8_t*)ptable)[index] = (uint8_t) src;\ 276 if (!useheap) ((uint8_t*)ptable)[index] = (uint8_t) src;\
277 else ((size_t*)ptable)[index] = src;\ 277 else ((size_t*)ptable)[index] = src;\
278 } while (0); 278 } while (0);
279 279
280 280
281 const char* ucx_strstr( 281 static const char* ucx_strstr(
282 const char *str, 282 const char *str,
283 size_t length, 283 size_t length,
284 const char *match, 284 const char *match,
285 size_t matchlen, 285 size_t matchlen,
286 size_t *newlen) 286 size_t *newlen)
509 } else { 509 } else {
510 return -1; 510 return -1;
511 } 511 }
512 } 512 }
513 513
514 sstr_t scstrdup(scstr_t s) { 514 sstr_t ucx_strdup(scstr_t s) {
515 return sstrdup_a(ucx_default_allocator(), s); 515 return sstrdup_a(ucx_default_allocator(), s);
516 } 516 }
517 517
518 sstr_t scstrdup_a(UcxAllocator *allocator, scstr_t s) { 518 sstr_t ucx_strdup_a(UcxAllocator *allocator, scstr_t s) {
519 sstr_t newstring; 519 sstr_t newstring;
520 newstring.ptr = (char*)almalloc(allocator, s.length + 1); 520 newstring.ptr = (char*)almalloc(allocator, s.length + 1);
521 if (newstring.ptr) { 521 if (newstring.ptr) {
522 newstring.length = s.length; 522 newstring.length = s.length;
523 newstring.ptr[newstring.length] = 0; 523 newstring.ptr[newstring.length] = 0;
529 529
530 return newstring; 530 return newstring;
531 } 531 }
532 532
533 533
534 size_t ucx_strtrim(const char *s, size_t len, size_t *newlen) { 534 static size_t ucx_strtrim(const char *s, size_t len, size_t *newlen) {
535 const char *newptr = s; 535 const char *newptr = s;
536 size_t length = len; 536 size_t length = len;
537 537
538 while(length > 0 && isspace(*newptr)) { 538 while(length > 0 && isspace(*newptr)) {
539 newptr++; 539 newptr++;

mercurial