From: Holger Schemel Date: Fri, 23 Feb 2024 17:57:48 +0000 (+0100) Subject: added functions to remove leading and/or trailing whitespace from strings X-Git-Tag: 4.4.0.0-test-1~300 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=9bda353724b6dc9176d0dfaf28ef9f1ff4084d4b;p=rocksndiamonds.git added functions to remove leading and/or trailing whitespace from strings --- diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 264b7f8d..7450c3a3 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -1441,6 +1441,44 @@ char *getUnescapedString(const char *s) return s_unescaped; } +char *chugString(char *s) +{ + if (s == NULL) + return NULL; + + char *start; + + for (start = (char *)s; *start && isspace(*start); start++) + ; + + memmove(s, start, strlen(start) + 1); + + return s; +} + +char *chompString(char *s) +{ + if (s == NULL) + return NULL; + + int len = strlen(s); + + while (len--) + { + if (isspace(s[len])) + s[len] = '\0'; + else + break; + } + + return s; +} + +char *stripString(char *s) +{ + return chugString(chompString(s)); +} + boolean strEqual(const char *s1, const char *s2) { return (s1 == NULL && s2 == NULL ? TRUE : diff --git a/src/libgame/misc.h b/src/libgame/misc.h index 111610f8..4548892c 100644 --- a/src/libgame/misc.h +++ b/src/libgame/misc.h @@ -188,6 +188,11 @@ char **getSplitStringArray(const char *s, const char *, int); int getStringArrayLength(char **); void freeStringArray(char **); char *getUnescapedString(const char *); + +char *chugString(char *); +char *chompString(char *); +char *stripString(char *); + boolean strEqual(const char *, const char *); boolean strEqualN(const char *, const char *, int); boolean strEqualCase(const char *, const char *);