src/ucx/string.h

branch
constsstr
changeset 276
f1b2146d4805
parent 275
96f643d30ff1
child 288
6af5798342e8
     1.1 --- a/src/ucx/string.h	Sun Mar 11 13:43:07 2018 +0100
     1.2 +++ b/src/ucx/string.h	Sun Apr 01 09:51:01 2018 +0200
     1.3 @@ -264,6 +264,14 @@
     1.4   */
     1.5  sstr_t sstrrchr(sstr_t string, int chr);
     1.6  
     1.7 +
     1.8 +const char* ucx_strstr(
     1.9 +        const char *str,
    1.10 +        size_t length,
    1.11 +        const char *match,
    1.12 +        size_t matchlen,
    1.13 +        size_t *newlen);
    1.14 +
    1.15  /**
    1.16   * Returns a substring starting at the location of the first occurrence of the
    1.17   * specified string.
    1.18 @@ -279,7 +287,11 @@
    1.19   *               <code>match</code>, or an empty string, if the sequence is not
    1.20   *               present in <code>string</code>
    1.21   */
    1.22 -sstr_t sstrstr(sstr_t string, sstr_t match);
    1.23 +sstr_t ucx_sstrstr(sstr_t string, scstr_t match);
    1.24 +#define sstrstr(string, match) ucx_sstrstr(string, SCSTR(match))
    1.25 +
    1.26 +scstr_t ucx_scstrstr(scstr_t string, scstr_t match);
    1.27 +#define scstrstr(string, match) ucx_scstrstr(string, SCSTR(match))
    1.28  
    1.29  /**
    1.30   * Splits a string into parts by using a delimiter string.
    1.31 @@ -328,7 +340,9 @@
    1.32   * 
    1.33   * @see sstrsplit_a()
    1.34   */
    1.35 -sstr_t* sstrsplit(sstr_t string, sstr_t delim, ssize_t *count);
    1.36 +sstr_t* ucx_strsplit(scstr_t string, scstr_t delim, ssize_t *count);
    1.37 +
    1.38 +#define sstrsplit(s, delim, count) ucx_strsplit(SCSTR(s), SCSTR(delim), count)
    1.39  
    1.40  /**
    1.41   * Performing sstrsplit() using a UcxAllocator.
    1.42 @@ -352,9 +366,11 @@
    1.43   * 
    1.44   * @see sstrsplit()
    1.45   */
    1.46 -sstr_t* sstrsplit_a(UcxAllocator *allocator, sstr_t string, sstr_t delim,
    1.47 +sstr_t* ucx_strsplit_a(UcxAllocator *allocator, scstr_t string, scstr_t delim,
    1.48          ssize_t *count);
    1.49  
    1.50 +#define sstrsplit_a(a, s, d, c) ucx_strsplit_a(a, SCSTR(s), SCSTR(d, c))
    1.51 +
    1.52  /**
    1.53   * Compares two UCX strings with standard <code>memcmp()</code>.
    1.54   * 
    1.55 @@ -367,7 +383,9 @@
    1.56   * length of s1 is greater than the length of s2 or the result of
    1.57   * <code>memcmp()</code> otherwise (i.e. 0 if the strings match)
    1.58   */
    1.59 -int sstrcmp(sstr_t s1, sstr_t s2);
    1.60 +int ucx_str_cmp(scstr_t s1, scstr_t s2);
    1.61 +
    1.62 +#define sstrcmp(s1, s2) ucx_str_cmp(SCSTR(s1), SCSTR(s2))
    1.63  
    1.64  /**
    1.65   * Compares two UCX strings ignoring the case.
    1.66 @@ -383,7 +401,9 @@
    1.67   * first two differing characters otherwise (i.e. 0 if the strings match and
    1.68   * no characters differ)
    1.69   */
    1.70 -int sstrcasecmp(sstr_t s1, sstr_t s2);
    1.71 +int ucx_str_casecmp(scstr_t s1, scstr_t s2);
    1.72 +
    1.73 +#define sstrcasecmp(s1, s2) ucx_str_casecmp(SCSTR(s1), SCSTR(s2))
    1.74  
    1.75  /**
    1.76   * Creates a duplicate of the specified string.
    1.77 @@ -423,6 +443,9 @@
    1.78  
    1.79  #define sstrdup_a(allocator, s) scstrdup_a(allocator, SCSTR(s))
    1.80  
    1.81 +
    1.82 +size_t ucx_strtrim(const char *str, size_t length, size_t *newlen);
    1.83 +
    1.84  /**
    1.85   * Omits leading and trailing spaces.
    1.86   * 
    1.87 @@ -442,6 +465,8 @@
    1.88   */
    1.89  sstr_t sstrtrim(sstr_t string);
    1.90  
    1.91 +scstr_t scstrtrim(scstr_t string);
    1.92 +
    1.93  /**
    1.94   * Checks, if a string has a specific prefix.
    1.95   * @param string the string to check

mercurial