Browse Source

read blank lines as comments (#2247) [ci skip]

Alec Jacobson 2 years ago
parent
commit
b1fe6ba49c
1 changed files with 24 additions and 1 deletions
  1. 24 1
      include/igl/readMESH.cpp

+ 24 - 1
include/igl/readMESH.cpp

@@ -45,10 +45,33 @@ IGL_INLINE bool igl::readMESH(
   {
     bool still_comments= true;
     bool has_line = false;
+
+    const auto is_comment_line = [&](char * line)->bool
+    {
+      if(line[0] == '#' || line[0] == '\n' || line[0] == '\r')
+      {
+        return true;
+      }
+      // or if line is all whitespace
+      for(int i = 0;i<LINE_MAX;i++)
+      {
+        if(line[i] == '\0')
+        {
+          return true;
+        }
+        if(!isspace(line[i]))
+        {
+          return false;
+        }
+      }
+      return false;
+    };
+
     while(still_comments)
     {
       has_line = fgets(line,LINE_MAX,mesh_file) != NULL;
-      still_comments = has_line && (line[0] == '#' || line[0] == '\n' || line[0] == '\r');
+
+      still_comments = has_line && is_comment_line(line);
     }
     return has_line;
   };