X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib-lib%2Fstr.c;h=a5333e481fe7b1f7c62c8d75928ba1b4076ac310;hp=72254833748f3e92e5147f7bb666f8018ce03fa3;hb=108f3c7ab59844591f7540347914ea57be5245e2;hpb=bec523bb3ad78ec9100efb18fb58d43d38b304de diff --git a/lib-lib/str.c b/lib-lib/str.c index 7225483..a5333e4 100644 --- a/lib-lib/str.c +++ b/lib-lib/str.c @@ -54,6 +54,20 @@ char const __m_b64chars[64] = { '8', '9', '+', '/' }; +char const __m_b36chars_lower[36] = { + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', + 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', + 'u', 'v', 'w', 'x', 'y', 'z' +}; + +char const __m_b36chars_upper[36] = { + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', + 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', + 'U', 'V', 'W', 'X', 'Y', 'Z' +}; + ssize_t m_strcpy(char *dst, ssize_t n, const char *src) { @@ -80,3 +94,50 @@ ssize_t m_strncpy(char *dst, ssize_t n, const char *src, ssize_t l) return len; } + +char *m_strrtrim(char *s) +{ + if (s) { + char *p = s + m_strlen(s); + + while (p > s && ISSPACE(p[-1])) { + *--p = '\0'; + } + return p; + } + + return NULL; +} + +const char *m_stristrn(const char *haystack, const char *needle, ssize_t nlen) +{ + int nc; + + if (!nlen) + return haystack; + + nc = tolower(*needle); + for (;;) { + int c = tolower(*haystack); + + if (c != nc) { + if (c == '\0') + return NULL; + } else { + ssize_t i; + + /* compare the rest of needle */ + for (i = 1;; i++) { + if (i == nlen) + return haystack; + if (c == '\0') + return NULL; + c = tolower(haystack[i]); + if (c != tolower(needle[i])) + break; + } + } + + haystack++; + } +}