changeset 71:210bfe10609f

Change return type of {Valid|Invalid}TextureName() functions, and make them check for texture names consisting only of whitespace.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 26 Sep 2011 12:47:29 +0300
parents dd9e9b980eb9
children 8cf53c768138
files src/textures.cc src/textures.h
diffstat 2 files changed, 19 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/textures.cc	Mon Sep 26 11:23:55 2011 +0300
+++ b/src/textures.cc	Mon Sep 26 12:47:29 2011 +0300
@@ -46,12 +46,26 @@
 
 /* Rudimentary check if the texture name is "valid"
  */
-int InvalidTextureName(const char *name)
+bool InvalidTextureName(const char *name)
 {
-    return ((name[0] == '-' && name[1] == 0) || name[0] == 0);
+    if ((name[0] == '-' && name[1] == 0) || name[0] == 0)
+        return true;
+    else
+    {
+        /* Check for name that consists only of whitespace */
+        const char *c = name;
+        while (*c)
+        {
+            if (isspace(*c))
+                c++;
+            else
+                return false;
+        }
+        return true;
+    }
 }
 
-int ValidTextureName(const char *name)
+bool ValidTextureName(const char *name)
 {
     return !InvalidTextureName(name);
 }
--- a/src/textures.h	Mon Sep 26 11:23:55 2011 +0300
+++ b/src/textures.h	Mon Sep 26 12:47:29 2011 +0300
@@ -16,7 +16,7 @@
 void ChooseWallTexture(int, int, const char *, int, char **, char *);
 void GetWallTextureSize(i16 *, i16 *, const char *);
 
-int  InvalidTextureName(const char *);
-int  ValidTextureName(const char *);
+bool InvalidTextureName(const char *);
+bool ValidTextureName(const char *);
 
 #endif