diff options
| author | Burt P <pburt0@gmail.com> | 2019-08-23 20:47:41 -0500 | 
|---|---|---|
| committer | Leandro A. F. Pereira <leandro@hardinfo.org> | 2019-08-28 13:15:48 +0200 | 
| commit | 348d6d919c7d128cd6300e9a7f02483850edd079 (patch) | |
| tree | 1013fff352c89d285cbec91a73aacc1a885ef876 /deps | |
| parent | a08f2a909f7a67f7ca81354a88b7c2e47dc6f19f (diff) | |
vendor: update vendor.{h,c}
Mostly new match rules.
Signed-off-by: Burt P <pburt0@gmail.com>
Diffstat (limited to 'deps')
| -rw-r--r-- | deps/sysobj_early/include/strstr_word.h | 11 | ||||
| -rw-r--r-- | deps/sysobj_early/src/strstr_word.c | 56 | 
2 files changed, 44 insertions, 23 deletions
| diff --git a/deps/sysobj_early/include/strstr_word.h b/deps/sysobj_early/include/strstr_word.h index f607b2ed..f17e78ff 100644 --- a/deps/sysobj_early/include/strstr_word.h +++ b/deps/sysobj_early/include/strstr_word.h @@ -18,13 +18,18 @@   *   */ -/* versions of strstr() and strcasestr() where the match must be preceded and - * succeded by a non-alpha-numeric character. */ -  #ifndef __STRSTR_WORD_H__  #define __STRSTR_WORD_H__ +/* versions of strstr() and strcasestr() where the match must be preceded and + * succeded by a non-alpha-numeric character. */  char *strstr_word(const char *haystack, const char *needle);  char *strcasestr_word(const char *haystack, const char *needle); +/* word boundary at start only (prefix), or end only (suffix) */ +char *strstr_word_prefix(const char *haystack, const char *needle); +char *strcasestr_word_prefix(const char *haystack, const char *needle); +char *strstr_word_suffix(const char *haystack, const char *needle); +char *strcasestr_word_suffix(const char *haystack, const char *needle); +  #endif diff --git a/deps/sysobj_early/src/strstr_word.c b/deps/sysobj_early/src/strstr_word.c index b12f01a2..0b51e4ac 100644 --- a/deps/sysobj_early/src/strstr_word.c +++ b/deps/sysobj_early/src/strstr_word.c @@ -25,40 +25,56 @@  #include <string.h>  #include <ctype.h> -char *strstr_word(const char *haystack, const char *needle) { +static char *_strstr(const char *haystack, const char *needle, int anycase) { +    return anycase +        ? strcasestr(haystack, needle) +        : strstr(haystack, needle); +} + +static char *_strstr_word(const char *haystack, const char *needle, +                          int anycase, int prefix_ok, int suffix_ok) { +      if (!haystack || !needle)          return NULL;      char *c;      const char *p = haystack;      size_t l = strlen(needle); -    while(c = strstr(p, needle)) { +    while((c = _strstr(p, needle, anycase))) {          const char *before = (c == haystack) ? NULL : c-1;          const char *after = c + l; -        int ok = 1; -        if (isalnum(*after)) ok = 0; -        if (before && isalnum(*before)) ok = 0; +        int ok = 1, wbs = 1, wbe = 1; +        if (isalnum(*after)) wbe = 0; +        if (before && isalnum(*before)) wbs = 0; +        if (!wbe && !prefix_ok) ok = 0; +        if (!wbs && !suffix_ok) ok = 0; +        if (!(wbs || wbe)) ok = 0;          if (ok) return c;          p++;      }      return NULL;  } +char *strstr_word(const char *haystack, const char *needle) { +    return _strstr_word(haystack, needle, 0, 0, 0); +} +  char *strcasestr_word(const char *haystack, const char *needle) { -    if (!haystack || !needle) -        return NULL; +    return _strstr_word(haystack, needle, 1, 0, 0); +} -    char *c; -    const char *p = haystack; -    size_t l = strlen(needle); -    while(c = strcasestr(p, needle)) { -        const char *before = (c == haystack) ? NULL : c-1; -        const char *after = c + l; -        int ok = 1; -        if (isalnum(*after)) ok = 0; -        if (before && isalnum(*before)) ok = 0; -        if (ok) return c; -        p++; -    } -    return NULL; +char *strstr_word_prefix(const char *haystack, const char *needle) { +    return _strstr_word(haystack, needle, 0, 1, 0); +} + +char *strcasestr_word_prefix(const char *haystack, const char *needle) { +    return _strstr_word(haystack, needle, 1, 1, 0); +} + +char *strstr_word_suffix(const char *haystack, const char *needle) { +    return _strstr_word(haystack, needle, 0, 0, 1); +} + +char *strcasestr_word_suffix(const char *haystack, const char *needle) { +    return _strstr_word(haystack, needle, 1, 0, 1);  } | 
