src/string.c

Tue, 08 May 2018 12:49:56 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 08 May 2018 12:49:56 +0200
branch
constsstr
changeset 288
6af5798342e8
parent 276
f1b2146d4805
child 300
d1f814633049
permissions
-rw-r--r--

makes sstrcat and sstrnlen scstr_t compatible

olaf@20 1 /*
universe@103 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
olaf@20 3 *
universe@259 4 * Copyright 2017 Mike Becker, Olaf Wintermann All rights reserved.
universe@103 5 *
universe@103 6 * Redistribution and use in source and binary forms, with or without
universe@103 7 * modification, are permitted provided that the following conditions are met:
universe@103 8 *
universe@103 9 * 1. Redistributions of source code must retain the above copyright
universe@103 10 * notice, this list of conditions and the following disclaimer.
universe@103 11 *
universe@103 12 * 2. Redistributions in binary form must reproduce the above copyright
universe@103 13 * notice, this list of conditions and the following disclaimer in the
universe@103 14 * documentation and/or other materials provided with the distribution.
universe@103 15 *
universe@103 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
universe@103 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
universe@103 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
universe@103 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
universe@103 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
universe@103 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
universe@103 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
universe@103 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
universe@103 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
universe@103 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
universe@103 26 * POSSIBILITY OF SUCH DAMAGE.
olaf@20 27 */
olaf@20 28
universe@251 29 #include "ucx/string.h"
universe@251 30
universe@251 31 #include "ucx/allocator.h"
universe@251 32
olaf@20 33 #include <stdlib.h>
universe@69 34 #include <string.h>
olaf@20 35 #include <stdarg.h>
universe@236 36 #include <stdint.h>
universe@189 37 #include <ctype.h>
olaf@20 38
universe@116 39 sstr_t sstr(char *cstring) {
olaf@20 40 sstr_t string;
universe@116 41 string.ptr = cstring;
universe@116 42 string.length = strlen(cstring);
olaf@20 43 return string;
olaf@20 44 }
olaf@20 45
universe@116 46 sstr_t sstrn(char *cstring, size_t length) {
olaf@20 47 sstr_t string;
universe@116 48 string.ptr = cstring;
universe@116 49 string.length = length;
olaf@20 50 return string;
olaf@20 51 }
olaf@20 52
olaf@275 53 scstr_t scstr(const char *cstring) {
olaf@275 54 scstr_t string;
olaf@275 55 string.ptr = cstring;
olaf@275 56 string.length = strlen(cstring);
olaf@275 57 return string;
olaf@275 58 }
olaf@275 59
olaf@275 60 scstr_t scstrn(const char *cstring, size_t length) {
olaf@275 61 scstr_t string;
olaf@275 62 string.ptr = cstring;
olaf@275 63 string.length = length;
olaf@275 64 return string;
olaf@275 65 }
olaf@275 66
olaf@275 67
olaf@288 68 size_t ucx_strnlen(size_t n, ...) {
olaf@20 69 va_list ap;
olaf@288 70 va_start(ap, n);
olaf@288 71
olaf@288 72 size_t size = 0;
olaf@20 73
olaf@288 74 for (size_t i = 0 ; i < n ; i++) {
olaf@288 75 scstr_t str = va_arg(ap, scstr_t);
olaf@272 76 if(((size_t)-1) - str.length < size) {
olaf@272 77 size = 0;
olaf@272 78 break;
olaf@272 79 }
olaf@20 80 size += str.length;
olaf@20 81 }
universe@24 82 va_end(ap);
olaf@20 83
olaf@20 84 return size;
olaf@20 85 }
olaf@20 86
olaf@180 87 static sstr_t sstrvcat_a(
olaf@180 88 UcxAllocator *a,
olaf@180 89 size_t count,
olaf@288 90 scstr_t s1,
olaf@180 91 va_list ap) {
olaf@180 92 sstr_t str;
olaf@180 93 str.ptr = NULL;
olaf@180 94 str.length = 0;
olaf@180 95 if(count < 2) {
olaf@180 96 return str;
olaf@180 97 }
olaf@180 98
olaf@288 99 scstr_t s2 = va_arg (ap, scstr_t);
olaf@288 100
olaf@272 101 if(((size_t)-1) - s1.length < s2.length) {
olaf@272 102 return str;
olaf@272 103 }
olaf@272 104
olaf@288 105 scstr_t *strings = (scstr_t*) calloc(count, sizeof(scstr_t));
olaf@180 106 if(!strings) {
olaf@180 107 return str;
olaf@180 108 }
olaf@180 109
olaf@180 110 // get all args and overall length
olaf@180 111 strings[0] = s1;
olaf@180 112 strings[1] = s2;
olaf@272 113 size_t slen = s1.length + s2.length;
olaf@272 114 int error = 0;
olaf@180 115 for (size_t i=2;i<count;i++) {
olaf@288 116 scstr_t s = va_arg (ap, scstr_t);
olaf@180 117 strings[i] = s;
olaf@272 118 if(((size_t)-1) - s.length < slen) {
olaf@272 119 error = 1;
olaf@272 120 break;
olaf@272 121 }
olaf@272 122 slen += s.length;
olaf@272 123 }
olaf@272 124 if(error) {
olaf@272 125 free(strings);
olaf@272 126 return str;
olaf@180 127 }
olaf@180 128
olaf@180 129 // create new string
olaf@272 130 str.ptr = (char*) almalloc(a, slen + 1);
olaf@272 131 str.length = slen;
olaf@180 132 if(!str.ptr) {
olaf@180 133 free(strings);
olaf@180 134 str.length = 0;
olaf@180 135 return str;
olaf@180 136 }
olaf@180 137
olaf@180 138 // concatenate strings
olaf@180 139 size_t pos = 0;
olaf@180 140 for (size_t i=0;i<count;i++) {
olaf@288 141 scstr_t s = strings[i];
olaf@180 142 memcpy(str.ptr + pos, s.ptr, s.length);
olaf@180 143 pos += s.length;
olaf@180 144 }
olaf@180 145
olaf@180 146 str.ptr[str.length] = '\0';
olaf@180 147
olaf@180 148 free(strings);
olaf@180 149
olaf@180 150 return str;
olaf@180 151 }
olaf@180 152
olaf@288 153 sstr_t ucx_strcat(size_t count, scstr_t s1, ...) {
olaf@180 154 va_list ap;
olaf@288 155 va_start(ap, s1);
olaf@288 156 sstr_t s = sstrvcat_a(ucx_default_allocator(), count, s1, ap);
olaf@180 157 va_end(ap);
olaf@180 158 return s;
olaf@180 159 }
olaf@180 160
olaf@288 161 sstr_t ucx_strcat_a(UcxAllocator *a, size_t count, scstr_t s1, ...) {
olaf@180 162 va_list ap;
olaf@288 163 va_start(ap, s1);
olaf@288 164 sstr_t s = sstrvcat_a(a, count, s1, ap);
olaf@180 165 va_end(ap);
olaf@180 166 return s;
olaf@180 167 }
olaf@180 168
olaf@68 169 sstr_t sstrsubs(sstr_t s, size_t start) {
olaf@20 170 return sstrsubsl (s, start, s.length-start);
olaf@20 171 }
olaf@20 172
olaf@68 173 sstr_t sstrsubsl(sstr_t s, size_t start, size_t length) {
olaf@20 174 sstr_t new_sstr;
olaf@104 175 if (start >= s.length) {
universe@173 176 new_sstr.ptr = NULL;
universe@173 177 new_sstr.length = 0;
universe@173 178 } else {
universe@173 179 if (length > s.length-start) {
universe@173 180 length = s.length-start;
universe@173 181 }
universe@173 182 new_sstr.ptr = &s.ptr[start];
universe@173 183 new_sstr.length = length;
olaf@20 184 }
olaf@20 185 return new_sstr;
olaf@20 186 }
olaf@20 187
olaf@108 188 sstr_t sstrchr(sstr_t s, int c) {
olaf@108 189 for(size_t i=0;i<s.length;i++) {
olaf@108 190 if(s.ptr[i] == c) {
olaf@108 191 return sstrsubs(s, i);
olaf@108 192 }
olaf@108 193 }
olaf@108 194 sstr_t n;
olaf@108 195 n.ptr = NULL;
olaf@108 196 n.length = 0;
olaf@108 197 return n;
olaf@108 198 }
olaf@108 199
universe@148 200 sstr_t sstrrchr(sstr_t s, int c) {
universe@148 201 if (s.length > 0) {
universe@152 202 for(size_t i=s.length;i>0;i--) {
universe@152 203 if(s.ptr[i-1] == c) {
universe@152 204 return sstrsubs(s, i-1);
universe@148 205 }
universe@148 206 }
universe@148 207 }
universe@148 208 sstr_t n;
universe@148 209 n.ptr = NULL;
universe@148 210 n.length = 0;
universe@148 211 return n;
universe@148 212 }
universe@148 213
universe@237 214 #define ptable_r(dest, useheap, ptable, index) (dest = useheap ? \
universe@237 215 ((size_t*)ptable)[index] : (size_t) ((uint8_t*)ptable)[index])
universe@236 216
universe@237 217 #define ptable_w(useheap, ptable, index, src) do {\
universe@237 218 if (!useheap) ((uint8_t*)ptable)[index] = (uint8_t) src;\
universe@237 219 else ((size_t*)ptable)[index] = src;\
universe@237 220 } while (0);
universe@236 221
olaf@276 222
olaf@276 223 const char* ucx_strstr(
olaf@276 224 const char *str,
olaf@276 225 size_t length,
olaf@276 226 const char *match,
olaf@276 227 size_t matchlen,
olaf@276 228 size_t *newlen)
olaf@276 229 {
olaf@276 230 *newlen = length;
olaf@276 231 if (matchlen == 0) {
olaf@276 232 return str;
universe@214 233 }
universe@214 234
olaf@276 235 const char *result = NULL;
olaf@276 236 size_t resultlen = 0;
universe@236 237
universe@236 238 /*
universe@236 239 * IMPORTANT:
universe@236 240 * our prefix table contains the prefix length PLUS ONE
universe@236 241 * this is our decision, because we want to use the full range of size_t
universe@236 242 * the original algorithm needs a (-1) at one single place
universe@236 243 * and we want to avoid that
universe@236 244 */
universe@236 245
universe@236 246 /* static prefix table */
universe@236 247 static uint8_t s_prefix_table[256];
universe@236 248
universe@236 249 /* check pattern length and use appropriate prefix table */
universe@237 250 /* if the pattern exceeds static prefix table, allocate on the heap */
olaf@276 251 register int useheap = matchlen > 255;
universe@237 252 register void* ptable = useheap ?
olaf@276 253 calloc(matchlen+1, sizeof(size_t)): s_prefix_table;
universe@236 254
universe@236 255 /* keep counter in registers */
universe@236 256 register size_t i, j;
universe@236 257
universe@236 258 /* fill prefix table */
universe@236 259 i = 0; j = 0;
universe@237 260 ptable_w(useheap, ptable, i, j);
olaf@276 261 while (i < matchlen) {
olaf@276 262 while (j >= 1 && match[j-1] != match[i]) {
universe@238 263 ptable_r(j, useheap, ptable, j-1);
universe@236 264 }
universe@236 265 i++; j++;
universe@237 266 ptable_w(useheap, ptable, i, j);
universe@236 267 }
universe@236 268
universe@236 269 /* search */
universe@236 270 i = 0; j = 1;
olaf@276 271 while (i < length) {
olaf@276 272 while (j >= 1 && str[i] != match[j-1]) {
universe@237 273 ptable_r(j, useheap, ptable, j-1);
universe@236 274 }
universe@236 275 i++; j++;
olaf@276 276 if (j-1 == matchlen) {
olaf@276 277 size_t start = i - matchlen;
olaf@276 278 result = str + start;
olaf@276 279 resultlen = length - start;
universe@236 280 break;
universe@214 281 }
universe@214 282 }
universe@236 283
universe@236 284 /* if prefix table was allocated on the heap, free it */
universe@236 285 if (ptable != s_prefix_table) {
universe@236 286 free(ptable);
universe@236 287 }
universe@214 288
olaf@276 289 *newlen = resultlen;
olaf@276 290 return result;
olaf@276 291 }
olaf@276 292
olaf@276 293 sstr_t ucx_sstrstr(sstr_t string, scstr_t match) {
olaf@276 294 sstr_t result;
olaf@276 295
olaf@276 296 size_t reslen;
olaf@276 297 const char *resstr = ucx_strstr(string.ptr, string.length, match.ptr, match.length, &reslen);
olaf@276 298 if(!resstr) {
olaf@276 299 result.ptr = NULL;
olaf@276 300 result.length = 0;
olaf@276 301 return result;
olaf@276 302 }
olaf@276 303
olaf@276 304 size_t pos = resstr - string.ptr;
olaf@276 305 result.ptr = string.ptr + pos;
olaf@276 306 result.length = reslen;
olaf@276 307
olaf@276 308 return result;
olaf@276 309 }
olaf@276 310
olaf@276 311 scstr_t ucx_scstrstr(scstr_t string, scstr_t match) {
olaf@276 312 scstr_t result;
olaf@276 313
olaf@276 314 size_t reslen;
olaf@276 315 const char *resstr = ucx_strstr(string.ptr, string.length, match.ptr, match.length, &reslen);
olaf@276 316 if(!resstr) {
olaf@276 317 result.ptr = NULL;
olaf@276 318 result.length = 0;
olaf@276 319 return result;
olaf@276 320 }
olaf@276 321
olaf@276 322 size_t pos = resstr - string.ptr;
olaf@276 323 result.ptr = string.ptr + pos;
olaf@276 324 result.length = reslen;
olaf@276 325
universe@236 326 return result;
universe@214 327 }
universe@214 328
universe@237 329 #undef ptable_r
universe@237 330 #undef ptable_w
universe@237 331
olaf@276 332 sstr_t* ucx_strsplit(scstr_t s, scstr_t d, ssize_t *n) {
olaf@276 333 return ucx_strsplit_a(ucx_default_allocator(), s, d, n);
universe@119 334 }
universe@119 335
olaf@276 336 sstr_t* ucx_strsplit_a(UcxAllocator *allocator, scstr_t s, scstr_t d, ssize_t *n) {
universe@119 337 if (s.length == 0 || d.length == 0) {
universe@119 338 *n = -1;
universe@39 339 return NULL;
universe@39 340 }
universe@231 341
universe@231 342 /* special cases: delimiter is at least as large as the string */
universe@231 343 if (d.length >= s.length) {
universe@231 344 /* exact match */
universe@231 345 if (sstrcmp(s, d) == 0) {
universe@231 346 *n = 0;
universe@231 347 return NULL;
universe@231 348 } else /* no match possible */ {
universe@231 349 *n = 1;
universe@231 350 sstr_t *result = (sstr_t*) almalloc(allocator, sizeof(sstr_t));
olaf@270 351 if(result) {
olaf@270 352 *result = sstrdup_a(allocator, s);
olaf@270 353 } else {
olaf@270 354 *n = -2;
olaf@270 355 }
universe@231 356 return result;
universe@231 357 }
universe@231 358 }
universe@231 359
universe@173 360 ssize_t nmax = *n;
universe@235 361 size_t arrlen = 16;
olaf@270 362 sstr_t* result = (sstr_t*) alcalloc(allocator, arrlen, sizeof(sstr_t));
universe@39 363
universe@119 364 if (result) {
olaf@276 365 scstr_t curpos = s;
universe@233 366 ssize_t j = 1;
universe@233 367 while (1) {
olaf@276 368 scstr_t match;
universe@234 369 /* optimize for one byte delimiters */
universe@234 370 if (d.length == 1) {
universe@234 371 match = curpos;
universe@234 372 for (size_t i = 0 ; i < curpos.length ; i++) {
universe@234 373 if (curpos.ptr[i] == *(d.ptr)) {
universe@234 374 match.ptr = curpos.ptr + i;
universe@234 375 break;
universe@234 376 }
universe@234 377 match.length--;
universe@234 378 }
universe@234 379 } else {
olaf@276 380 match = scstrstr(curpos, d);
universe@234 381 }
universe@233 382 if (match.length > 0) {
universe@233 383 /* is this our last try? */
universe@233 384 if (nmax == 0 || j < nmax) {
universe@233 385 /* copy the current string to the array */
olaf@276 386 scstr_t item = scstrn(curpos.ptr, match.ptr - curpos.ptr);
universe@233 387 result[j-1] = sstrdup_a(allocator, item);
universe@233 388 size_t processed = item.length + d.length;
universe@233 389 curpos.ptr += processed;
universe@233 390 curpos.length -= processed;
universe@39 391
universe@233 392 /* allocate memory for the next string */
universe@233 393 j++;
universe@235 394 if (j > arrlen) {
universe@235 395 arrlen *= 2;
olaf@270 396 size_t reallocsz;
olaf@270 397 sstr_t* reallocated = NULL;
olaf@270 398 if(!ucx_szmul(arrlen, sizeof(sstr_t), &reallocsz)) {
olaf@270 399 reallocated = (sstr_t*) alrealloc(
olaf@270 400 allocator, result, reallocsz);
olaf@270 401 }
universe@235 402 if (reallocated) {
universe@235 403 result = reallocated;
universe@235 404 } else {
universe@235 405 for (ssize_t i = 0 ; i < j-1 ; i++) {
universe@235 406 alfree(allocator, result[i].ptr);
universe@235 407 }
universe@235 408 alfree(allocator, result);
universe@235 409 *n = -2;
universe@235 410 return NULL;
universe@233 411 }
universe@233 412 }
universe@233 413 } else {
universe@233 414 /* nmax reached, copy the _full_ remaining string */
universe@233 415 result[j-1] = sstrdup_a(allocator, curpos);
universe@233 416 break;
universe@233 417 }
universe@173 418 } else {
universe@233 419 /* no more matches, copy last string */
universe@233 420 result[j-1] = sstrdup_a(allocator, curpos);
universe@173 421 break;
universe@173 422 }
universe@119 423 }
universe@233 424 *n = j;
universe@119 425 } else {
universe@119 426 *n = -2;
universe@39 427 }
universe@39 428
universe@39 429 return result;
universe@39 430 }
universe@39 431
olaf@276 432 int ucx_str_cmp(scstr_t s1, scstr_t s2) {
universe@116 433 if (s1.length == s2.length) {
universe@116 434 return memcmp(s1.ptr, s2.ptr, s1.length);
universe@116 435 } else if (s1.length > s2.length) {
universe@116 436 return 1;
universe@116 437 } else {
universe@116 438 return -1;
universe@116 439 }
olaf@20 440 }
olaf@20 441
olaf@276 442 int ucx_str_casecmp(scstr_t s1, scstr_t s2) {
universe@149 443 if (s1.length == s2.length) {
universe@149 444 #ifdef _WIN32
universe@149 445 return _strnicmp(s1.ptr, s2.ptr, s1.length);
universe@149 446 #else
universe@149 447 return strncasecmp(s1.ptr, s2.ptr, s1.length);
universe@149 448 #endif
universe@149 449 } else if (s1.length > s2.length) {
universe@149 450 return 1;
universe@149 451 } else {
universe@149 452 return -1;
universe@149 453 }
universe@149 454 }
universe@149 455
olaf@275 456 sstr_t scstrdup(scstr_t s) {
universe@125 457 return sstrdup_a(ucx_default_allocator(), s);
olaf@109 458 }
olaf@20 459
olaf@275 460 sstr_t scstrdup_a(UcxAllocator *allocator, scstr_t s) {
olaf@109 461 sstr_t newstring;
universe@173 462 newstring.ptr = (char*)almalloc(allocator, s.length + 1);
olaf@109 463 if (newstring.ptr) {
olaf@109 464 newstring.length = s.length;
olaf@109 465 newstring.ptr[newstring.length] = 0;
olaf@109 466
olaf@109 467 memcpy(newstring.ptr, s.ptr, s.length);
olaf@109 468 } else {
olaf@109 469 newstring.length = 0;
olaf@109 470 }
olaf@109 471
olaf@20 472 return newstring;
olaf@20 473 }
olaf@96 474
olaf@276 475
olaf@276 476 size_t ucx_strtrim(const char *s, size_t len, size_t *newlen) {
olaf@276 477 const char *newptr = s;
olaf@276 478 size_t length = len;
universe@189 479
olaf@276 480 while(length > 0 && isspace(*newptr)) {
olaf@276 481 newptr++;
olaf@276 482 length--;
universe@98 483 }
olaf@276 484 while(length > 0 && isspace(newptr[length-1])) {
olaf@276 485 length--;
olaf@96 486 }
olaf@96 487
olaf@276 488 *newlen = length;
olaf@276 489 return newptr - s;
olaf@276 490 }
olaf@276 491
olaf@276 492 sstr_t sstrtrim(sstr_t string) {
olaf@276 493 sstr_t newstr;
olaf@276 494 newstr.ptr = string.ptr
olaf@276 495 + ucx_strtrim(string.ptr, string.length, &newstr.length);
olaf@276 496 return newstr;
olaf@276 497 }
olaf@276 498
olaf@276 499 scstr_t scstrtrim(scstr_t string) {
olaf@276 500 scstr_t newstr;
olaf@276 501 newstr.ptr = string.ptr
olaf@276 502 + ucx_strtrim(string.ptr, string.length, &newstr.length);
olaf@96 503 return newstr;
olaf@96 504 }
universe@146 505
olaf@275 506 int ucx_strprefix(scstr_t string, scstr_t prefix) {
universe@146 507 if (string.length == 0) {
universe@146 508 return prefix.length == 0;
universe@146 509 }
universe@146 510 if (prefix.length == 0) {
universe@146 511 return 1;
universe@146 512 }
universe@146 513
universe@146 514 if (prefix.length > string.length) {
universe@146 515 return 0;
universe@146 516 } else {
universe@146 517 return memcmp(string.ptr, prefix.ptr, prefix.length) == 0;
universe@146 518 }
universe@146 519 }
universe@146 520
olaf@275 521 int ucx_strsuffix(scstr_t string, scstr_t suffix) {
universe@146 522 if (string.length == 0) {
universe@146 523 return suffix.length == 0;
universe@146 524 }
universe@146 525 if (suffix.length == 0) {
universe@146 526 return 1;
universe@146 527 }
universe@146 528
universe@146 529 if (suffix.length > string.length) {
universe@146 530 return 0;
universe@146 531 } else {
universe@146 532 return memcmp(string.ptr+string.length-suffix.length,
universe@146 533 suffix.ptr, suffix.length) == 0;
universe@146 534 }
universe@146 535 }
universe@210 536
olaf@275 537 sstr_t ucx_strlower(scstr_t string) {
universe@210 538 sstr_t ret = sstrdup(string);
universe@210 539 for (size_t i = 0; i < ret.length ; i++) {
universe@210 540 ret.ptr[i] = tolower(ret.ptr[i]);
universe@210 541 }
universe@210 542 return ret;
universe@210 543 }
universe@210 544
olaf@275 545 sstr_t ucx_strlower_a(UcxAllocator *allocator, scstr_t string) {
universe@210 546 sstr_t ret = sstrdup_a(allocator, string);
universe@210 547 for (size_t i = 0; i < ret.length ; i++) {
universe@210 548 ret.ptr[i] = tolower(ret.ptr[i]);
universe@210 549 }
universe@210 550 return ret;
universe@210 551 }
universe@210 552
olaf@275 553 sstr_t ucx_strupper(scstr_t string) {
universe@210 554 sstr_t ret = sstrdup(string);
universe@210 555 for (size_t i = 0; i < ret.length ; i++) {
universe@210 556 ret.ptr[i] = toupper(ret.ptr[i]);
universe@210 557 }
universe@210 558 return ret;
universe@210 559 }
universe@210 560
olaf@275 561 sstr_t ucx_strupper_a(UcxAllocator *allocator, scstr_t string) {
universe@210 562 sstr_t ret = sstrdup_a(allocator, string);
universe@210 563 for (size_t i = 0; i < ret.length ; i++) {
universe@210 564 ret.ptr[i] = toupper(ret.ptr[i]);
universe@210 565 }
universe@210 566 return ret;
universe@210 567 }
olaf@275 568
olaf@275 569 // private string conversion functions
olaf@275 570 scstr_t ucx_sc2sc(scstr_t c) {
olaf@275 571 return c;
olaf@275 572 }
olaf@275 573 scstr_t ucx_ss2sc(sstr_t str) {
olaf@275 574 scstr_t cs;
olaf@275 575 cs.ptr = str.ptr;
olaf@275 576 cs.length = str.length;
olaf@275 577 return cs;
olaf@275 578 }
olaf@275 579 scstr_t ucx_ss2c_s(scstr_t c) {
olaf@275 580 return c;
olaf@275 581 }

mercurial