X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=util.c;h=7cf781212d9a822241b1348c645a54d489a44643;hb=e4a839df954d06da4721ded5192b4f1d27c52ee8;hp=62d58fff3e5fca7ab893d2a443ef929257bb0d5e;hpb=403901d6ee0cbcebb3723f2b8732a6421f85816a;p=xonotic%2Fgmqcc.git diff --git a/util.c b/util.c index 62d58ff..7cf7812 100644 --- a/util.c +++ b/util.c @@ -102,9 +102,9 @@ char *util_strdup(const char *s) { * as well. This function shouldn't be used to create a * char array that is later freed (it uses pointer arith) */ -char *util_strrq(char *s) { - char *dst = s; - char *src = s; +char *util_strrq(const char *s) { + char *dst = (char*)s; + char *src = (char*)s; char chr; while ((chr = *src++) != '\0') { if (chr == '\\') { @@ -126,14 +126,12 @@ char *util_strrq(char *s) { char *util_strchp(const char *s, const char *e) { if (!s || !e) return NULL; + + const char *c = s; + while (c != e) + c++; - size_t m = 0; - char *c = util_strdup(s); - while (s != e) - s++,c++,m++; - - *c = '\0'; - return c-m; + return util_strdup(s); } /* @@ -141,14 +139,14 @@ char *util_strchp(const char *s, const char *e) { * done pointer wise instead of strlen(), and an array * access. */ -char *util_strrnl(char *src) { +char *util_strrnl(const char *src) { if (!src) return NULL; - char *cpy = src; + char *cpy = (char*)src; while (*cpy && *cpy != '\n') cpy++; *cpy = '\0'; - return src; + return (char*)src; } /* @@ -166,6 +164,32 @@ char *util_strsws(const char *skip) { return util_strdup(skip-size); } +/* + * Returns true if string is all uppercase, otherwise + * it returns false. + */ +bool util_strupper(const char *str) { + while (*str) { + if(!isupper(*str)) + return false; + str++; + } + return true; +} + +/* + * Returns true if string is all digits, otherwise + * it returns false. + */ +bool util_strdigit(const char *str) { + while (*str) { + if(!isdigit(*str)) + return false; + str++; + } + return true; +} + void util_debug(const char *area, const char *ms, ...) { if (!opts_debug) return;