src/string.c

branch
constsstr
changeset 275
96f643d30ff1
parent 272
2def28b65328
child 276
f1b2146d4805
     1.1 --- a/src/string.c	Tue Jan 23 19:23:34 2018 +0100
     1.2 +++ b/src/string.c	Sun Mar 11 13:43:07 2018 +0100
     1.3 @@ -50,6 +50,21 @@
     1.4      return string;
     1.5  }
     1.6  
     1.7 +scstr_t scstr(const char *cstring) {
     1.8 +    scstr_t string;
     1.9 +    string.ptr = cstring;
    1.10 +    string.length = strlen(cstring);
    1.11 +    return string;
    1.12 +}
    1.13 +
    1.14 +scstr_t scstrn(const char *cstring, size_t length) {
    1.15 +    scstr_t string;
    1.16 +    string.ptr = cstring;
    1.17 +    string.length = length;
    1.18 +    return string;
    1.19 +}
    1.20 +
    1.21 +
    1.22  size_t sstrnlen(size_t n, sstr_t s, ...) {
    1.23      va_list ap;
    1.24      size_t size = s.length;
    1.25 @@ -391,11 +406,11 @@
    1.26      }
    1.27  }
    1.28  
    1.29 -sstr_t sstrdup(sstr_t s) {
    1.30 +sstr_t scstrdup(scstr_t s) {
    1.31      return sstrdup_a(ucx_default_allocator(), s);
    1.32  }
    1.33  
    1.34 -sstr_t sstrdup_a(UcxAllocator *allocator, sstr_t s) {
    1.35 +sstr_t scstrdup_a(UcxAllocator *allocator, scstr_t s) {
    1.36      sstr_t newstring;
    1.37      newstring.ptr = (char*)almalloc(allocator, s.length + 1);
    1.38      if (newstring.ptr) {
    1.39 @@ -424,7 +439,7 @@
    1.40      return newstr;
    1.41  }
    1.42  
    1.43 -int sstrprefix(sstr_t string, sstr_t prefix) {
    1.44 +int ucx_strprefix(scstr_t string, scstr_t prefix) {
    1.45      if (string.length == 0) {
    1.46          return prefix.length == 0;
    1.47      }
    1.48 @@ -439,7 +454,7 @@
    1.49      }
    1.50  }
    1.51  
    1.52 -int sstrsuffix(sstr_t string, sstr_t suffix) {
    1.53 +int ucx_strsuffix(scstr_t string, scstr_t suffix) {
    1.54      if (string.length == 0) {
    1.55          return suffix.length == 0;
    1.56      }
    1.57 @@ -455,7 +470,7 @@
    1.58      }
    1.59  }
    1.60  
    1.61 -sstr_t sstrlower(sstr_t string) {
    1.62 +sstr_t ucx_strlower(scstr_t string) {
    1.63      sstr_t ret = sstrdup(string);
    1.64      for (size_t i = 0; i < ret.length ; i++) {
    1.65          ret.ptr[i] = tolower(ret.ptr[i]);
    1.66 @@ -463,7 +478,7 @@
    1.67      return ret;
    1.68  }
    1.69  
    1.70 -sstr_t sstrlower_a(UcxAllocator *allocator, sstr_t string) {
    1.71 +sstr_t ucx_strlower_a(UcxAllocator *allocator, scstr_t string) {
    1.72      sstr_t ret = sstrdup_a(allocator, string);
    1.73      for (size_t i = 0; i < ret.length ; i++) {
    1.74          ret.ptr[i] = tolower(ret.ptr[i]);
    1.75 @@ -471,7 +486,7 @@
    1.76      return ret;
    1.77  }
    1.78  
    1.79 -sstr_t sstrupper(sstr_t string) {
    1.80 +sstr_t ucx_strupper(scstr_t string) {
    1.81      sstr_t ret = sstrdup(string);
    1.82      for (size_t i = 0; i < ret.length ; i++) {
    1.83          ret.ptr[i] = toupper(ret.ptr[i]);
    1.84 @@ -479,10 +494,24 @@
    1.85      return ret;
    1.86  }
    1.87  
    1.88 -sstr_t sstrupper_a(UcxAllocator *allocator, sstr_t string) {
    1.89 +sstr_t ucx_strupper_a(UcxAllocator *allocator, scstr_t string) {
    1.90      sstr_t ret = sstrdup_a(allocator, string);
    1.91      for (size_t i = 0; i < ret.length ; i++) {
    1.92          ret.ptr[i] = toupper(ret.ptr[i]);
    1.93      }
    1.94      return ret;
    1.95  }
    1.96 +
    1.97 +// private string conversion functions
    1.98 +scstr_t ucx_sc2sc(scstr_t c) {
    1.99 +    return c;
   1.100 +}
   1.101 +scstr_t ucx_ss2sc(sstr_t str) {
   1.102 +    scstr_t cs;
   1.103 +    cs.ptr = str.ptr;
   1.104 +    cs.length = str.length;
   1.105 +    return cs;
   1.106 +}
   1.107 +scstr_t ucx_ss2c_s(scstr_t c) {
   1.108 +    return c;
   1.109 +}

mercurial