src/string.c

changeset 364
5577d6c27a33
parent 363
8175ba2b3bcb
child 378
952c2df7e7ac
     1.1 --- a/src/string.c	Sun Nov 03 16:22:46 2019 +0100
     1.2 +++ b/src/string.c	Sun Nov 03 16:34:29 2019 +0100
     1.3 @@ -598,6 +598,38 @@
     1.4      }
     1.5  }
     1.6  
     1.7 +int scstrcaseprefix(scstr_t string, scstr_t prefix) {
     1.8 +    if (string.length == 0) {
     1.9 +        return prefix.length == 0;
    1.10 +    }
    1.11 +    if (prefix.length == 0) {
    1.12 +        return 1;
    1.13 +    }
    1.14 +    
    1.15 +    if (prefix.length > string.length) {
    1.16 +        return 0;
    1.17 +    } else {
    1.18 +        scstr_t subs = scstrsubsl(string, 0, prefix.length);
    1.19 +        return scstrcasecmp(subs, prefix) == 0;
    1.20 +    }
    1.21 +}
    1.22 +
    1.23 +int scstrcasesuffix(scstr_t string, scstr_t suffix) {
    1.24 +    if (string.length == 0) {
    1.25 +        return suffix.length == 0;
    1.26 +    }
    1.27 +    if (suffix.length == 0) {
    1.28 +        return 1;
    1.29 +    }
    1.30 +    
    1.31 +    if (suffix.length > string.length) {
    1.32 +        return 0;
    1.33 +    } else {
    1.34 +        scstr_t subs = scstrsubs(string, string.length-suffix.length);
    1.35 +        return scstrcasecmp(subs, suffix) == 0;
    1.36 +    }
    1.37 +}
    1.38 +
    1.39  sstr_t scstrlower(scstr_t string) {
    1.40      sstr_t ret = sstrdup(string);
    1.41      for (size_t i = 0; i < ret.length ; i++) {

mercurial