Browse Source

strip comment from the middle of the line too

David Rose 23 years ago
parent
commit
734ab0dcd1
2 changed files with 22 additions and 7 deletions
  1. 21 7
      dtool/src/dconfig/configTable.cxx
  2. 1 0
      dtool/src/dconfig/configTable.h

+ 21 - 7
dtool/src/dconfig/configTable.cxx

@@ -50,15 +50,28 @@ void ConfigTable::CropString(ConfigString& S) {
     S.erase(0, ConfigString::npos);
     S.erase(0, ConfigString::npos);
 }
 }
 
 
+void ConfigTable::DeComment(ConfigString& S) {
+  // If the comment delimiter appears in the line followed by
+  // whitespace, strip that part of the line out.
+
+  size_t i = S.find(configcmt);
+  while (i != ConfigString::npos) {
+    if (i + configcmt.length() < S.length() && 
+        isspace(S[i + configcmt.length()])) {
+      // Here's a comment.
+      S.erase(i, ConfigString::npos);
+      return;
+    }
+
+    i = S.find(configcmt, i + 1);
+  }
+}
+
 bool ConfigTable::IsComment(const ConfigString& S)
 bool ConfigTable::IsComment(const ConfigString& S)
 {
 {
-  if (!S.empty()) {
-    for (ConfigString::iterator i=configcmt.begin();
-         i!=configcmt.end(); ++i)
-      if (S[0] == (*i))
-        return true;
-  }
-  return false;
+  // Returns true if the line begins with the comment delimiter,
+  // whether or not the delimiter is followed by whitespace.
+  return (S.substr(0, configcmt.length()) == configcmt);
 }
 }
 
 
 void ConfigTable::UpCase(ConfigString& S)
 void ConfigTable::UpCase(ConfigString& S)
@@ -89,6 +102,7 @@ void ConfigTable::ParseConfigFile(istream& is, const ConfigString& Filename)
       if (microconfig_cat->is_spam())
       if (microconfig_cat->is_spam())
          microconfig_cat->spam() << "read from " << Filename << ": '" << line
          microconfig_cat->spam() << "read from " << Filename << ": '" << line
                                  << "'" << endl;
                                  << "'" << endl;
+      DeComment(line);
       CropString(line);
       CropString(line);
       if (microconfig_cat->is_spam())
       if (microconfig_cat->is_spam())
          microconfig_cat->spam() << "cropped line to: '" << line << "'"
          microconfig_cat->spam() << "cropped line to: '" << line << "'"

+ 1 - 0
dtool/src/dconfig/configTable.h

@@ -56,6 +56,7 @@ class EXPCL_DTOOLCONFIG ConfigTable {
       ConfigString commandstub;
       ConfigString commandstub;
 
 
       static void CropString(ConfigString& S);
       static void CropString(ConfigString& S);
+      void DeComment(ConfigString& S);
       bool IsComment(const ConfigString&);
       bool IsComment(const ConfigString&);
       static void UpCase(ConfigString&);
       static void UpCase(ConfigString&);
       ConfigString NextWord(const ConfigString& S);
       ConfigString NextWord(const ConfigString& S);