added functions to remove leading and/or trailing whitespace from strings
[rocksndiamonds.git] / src / libgame / misc.c
index c96fa177de8ad5ebfb50cb7daa3242db7654ebe7..7450c3a35fd4942d4e0a19a039738b9c997b2650 100644 (file)
@@ -1085,7 +1085,7 @@ char *getBasePath(char *filename)
 
 
 // ----------------------------------------------------------------------------
-// various string functions
+// various memory functions
 // ----------------------------------------------------------------------------
 
 void *getMemCopy(const void *m, size_t size)
@@ -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  :