[asterisk-scf-commits] asterisk-scf/integration/ice.git branch "iceutil-propertyhandler" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Tue Mar 15 17:26:42 CDT 2011


branch "iceutil-propertyhandler" has been updated
       via  7d3fe1b27c0a03ecb242e6af8e195ab5f557ed2b (commit)
      from  1221a61e1fe215fadb0f571f6dfb45be1e4e922b (commit)

Summary of changes:
 cpp/include/IceUtil/PropertiesHandler.h |    9 ++
 cpp/src/Ice/PropertiesI.cpp             |  199 ++++---------------------------
 cpp/src/Ice/PropertiesI.h               |    2 -
 cpp/src/IceUtil/PropertiesHandler.cpp   |  196 ++++++++++++++++++++++++++++++
 4 files changed, 228 insertions(+), 178 deletions(-)


- Log -----------------------------------------------------------------
commit 7d3fe1b27c0a03ecb242e6af8e195ab5f557ed2b
Author: Kevin P. Fleming <kpfleming at digium.com>
Date:   Tue Mar 15 17:26:10 2011 -0500

    Move parseLine() over to PropertiesHandler, leaving the Ice-specific bits
    behind.

diff --git a/cpp/include/IceUtil/PropertiesHandler.h b/cpp/include/IceUtil/PropertiesHandler.h
index 06f1fa7..34c3a99 100644
--- a/cpp/include/IceUtil/PropertiesHandler.h
+++ b/cpp/include/IceUtil/PropertiesHandler.h
@@ -61,6 +61,15 @@ private:
 
     friend class Ice::PropertiesI;
 
+    enum ParseLineResult
+    {
+        ParseLineOK,
+        ParseLineSkip,
+        ParseLineInvalid
+    };
+
+    ParseLineResult parseLine(const std::string&, std::pair<std::string, std::string>&);
+
     struct PropertyValue
     {
         PropertyValue() :
diff --git a/cpp/src/Ice/PropertiesI.cpp b/cpp/src/Ice/PropertiesI.cpp
index 9152590..e995e8b 100644
--- a/cpp/src/Ice/PropertiesI.cpp
+++ b/cpp/src/Ice/PropertiesI.cpp
@@ -181,7 +181,11 @@ Ice::PropertiesI::parseCommandLineOptions(const string& prefix, const StringSeq&
                 opt += "=1";
             }
             
-            parseLine(opt.substr(2), 0);
+            pair<string, string> keyval;
+            if(_propertiesHandler->parseLine(opt.substr(2), keyval) == IceUtilInternal::PropertiesHandler::ParseLineOK)
+            {
+                setProperty(keyval.first, keyval.second);
+            }
         }
         else
         {
@@ -319,7 +323,19 @@ Ice::PropertiesI::load(const std::string& file)
         string line;
         while(getline(in, line))
         {
-            parseLine(line, _converter);
+            pair<string, string> keyval;
+            switch(_propertiesHandler->parseLine(line, keyval))
+            {
+            case IceUtilInternal::PropertiesHandler::ParseLineOK:
+                setProperty(Ice::UTF8ToNative(_converter, keyval.first),
+                            Ice::UTF8ToNative(_converter, keyval.second));
+                break;
+            case IceUtilInternal::PropertiesHandler::ParseLineSkip:
+                continue;
+            case IceUtilInternal::PropertiesHandler::ParseLineInvalid:
+                getProcessLogger()->warning("invalid config file entry: \"" + line + "\"");
+                break;
+            }
         }
     }
 }
@@ -394,7 +410,11 @@ Ice::PropertiesI::PropertiesI(StringSeq& args, const PropertiesPtr& defaults, co
             {
                 s += "=1";
             }
-            parseLine(s.substr(2), 0);
+            pair<string, string> keyval;
+            if(_propertiesHandler->parseLine(s.substr(2), keyval) == IceUtilInternal::PropertiesHandler::ParseLineOK)
+            {
+                setProperty(keyval.first, keyval.second);
+            }
             loadConfigFiles = true;
         }
         else
@@ -422,179 +442,6 @@ Ice::PropertiesI::PropertiesI(StringSeq& args, const PropertiesPtr& defaults, co
 }
 
 void
-Ice::PropertiesI::parseLine(const string& line, const StringConverterPtr& converter)
-{
-    string key;
-    string value;
-    
-    enum ParseState { Key , Value };
-    ParseState state = Key;
-
-    string whitespace;
-    string escapedspace;
-    bool finished = false;
-    for(string::size_type i = 0; i < line.size(); ++i)
-    {
-        char c = line[i];
-        switch(state)
-        {
-          case Key:
-          {
-            switch(c)
-            {
-              case '\\':
-                if(i < line.length() - 1)
-                {
-                    c = line[++i];
-                    switch(c)
-                    {
-                      case '\\':
-                      case '#':
-                      case '=':
-                        key += whitespace;
-                        whitespace.clear();
-                        key += c; 
-                        break;
-
-                      case ' ':
-                        if(key.length() != 0)
-                        {
-                            whitespace += c;
-                        }
-                        break;
-
-                      default:
-                        key += whitespace;
-                        whitespace.clear();
-                        key += '\\';
-                        key += c;
-                        break;
-                    }
-                }
-                else
-                {
-                    key += whitespace;
-                    key += c;
-                }
-                break;
-
-              case ' ':
-              case '\t':
-              case '\r':
-              case '\n':
-                  if(key.length() != 0)
-                  {
-                      whitespace += c;
-                  }
-                  break;
-
-              case '=':
-                  whitespace.clear();
-                  state = Value;
-                  break;
-
-              case '#':
-                  finished = true;
-                  break;
-              
-              default:
-                  key += whitespace;
-                  whitespace.clear();
-                  key += c;
-                  break;
-            }
-            break;
-          }
-
-          case Value:
-          {
-            switch(c)
-            {
-              case '\\':
-                if(i < line.length() - 1)
-                {
-                    c = line[++i];
-                    switch(c)
-                    {
-                      case '\\':
-                      case '#':
-                      case '=':
-                        value += value.length() == 0 ? escapedspace : whitespace;
-                        whitespace.clear();
-                        escapedspace.clear();
-                        value += c; 
-                        break;
-
-                      case ' ':
-                        whitespace += c;
-                        escapedspace += c;
-                        break;
-
-                      default:
-                        value += value.length() == 0 ? escapedspace : whitespace;
-                        whitespace.clear();
-                        escapedspace.clear();
-                        value += '\\';
-                        value += c;
-                        break;
-                    }
-                }
-                else
-                {
-                    value += value.length() == 0 ? escapedspace : whitespace;
-                      value += c;
-                }
-                break;
-
-              case ' ':
-              case '\t':
-              case '\r':
-              case '\n':
-                  if(value.length() != 0)
-                  {
-                      whitespace += c;
-                  }
-                  break;
-
-              case '#':
-                  value += escapedspace;
-                  finished = true;
-                  break;
-              
-              default:
-                  value += value.length() == 0 ? escapedspace : whitespace;
-                  whitespace.clear();
-                  escapedspace.clear();
-                  value += c;
-                  break;
-            }
-            break;
-          }
-        }
-        if(finished)
-        {
-            break;
-        }
-    }
-    value += escapedspace;
-
-    if((state == Key && key.length() != 0) || (state == Value && key.length() == 0))
-    {
-        getProcessLogger()->warning("invalid config file entry: \"" + line + "\"");
-        return;
-    }
-    else if(key.length() == 0)
-    {
-        return;
-    }
-
-    key = Ice::UTF8ToNative(converter, key);
-    value = Ice::UTF8ToNative(converter, value);
-
-    setProperty(key, value);
-}
-
-void
 Ice::PropertiesI::loadConfig()
 {
     string value = getProperty("Ice.Config");
diff --git a/cpp/src/Ice/PropertiesI.h b/cpp/src/Ice/PropertiesI.h
index 7e346c5..fc580a2 100644
--- a/cpp/src/Ice/PropertiesI.h
+++ b/cpp/src/Ice/PropertiesI.h
@@ -50,8 +50,6 @@ private:
     friend ICE_API PropertiesPtr createProperties(StringSeq&, const PropertiesPtr&, const StringConverterPtr&);
     friend ICE_API PropertiesPtr createProperties(int&, char*[], const PropertiesPtr&, const StringConverterPtr&);
 
-    void parseLine(const std::string&, const StringConverterPtr&);
-
     void loadConfig();
 
     struct PropertyValue
diff --git a/cpp/src/IceUtil/PropertiesHandler.cpp b/cpp/src/IceUtil/PropertiesHandler.cpp
index 85efb95..b4bf6af 100644
--- a/cpp/src/IceUtil/PropertiesHandler.cpp
+++ b/cpp/src/IceUtil/PropertiesHandler.cpp
@@ -9,6 +9,7 @@
 
 #include <IceUtil/DisableWarnings.h>
 #include <IceUtil/StringUtil.h>
+#include <IceUtil/FileUtil.h>
 #include <IceUtil/PropertiesHandler.h>
 
 using namespace std;
@@ -156,3 +157,198 @@ IceUtilInternal::PropertiesHandler::getUnusedProperties()
     }
     return unusedProperties;
 }
+
+void
+IceUtilInternal::PropertiesHandler::load(const std::string& file)
+{
+    IceUtilInternal::ifstream in(file);
+    if(!in)
+    {
+        FileException ex(__FILE__, __LINE__);
+        ex.path = file;
+        ex.error = getSystemErrno();
+        throw ex;
+    }
+    
+    string line;
+    while(getline(in, line))
+    {
+        pair<string, string> keyval;
+        if(parseLine(line, keyval) == ParseLineOK)
+        {
+            setProperty(keyval.first, keyval.second);
+        }
+    }
+}
+
+IceUtilInternal::PropertiesHandler::ParseLineResult
+IceUtilInternal::PropertiesHandler::parseLine(const string& line, pair<string, string>& keyval)
+{
+    string key;
+    string value;
+    
+    enum ParseState { Key , Value };
+    ParseState state = Key;
+
+    string whitespace;
+    string escapedspace;
+    bool finished = false;
+    for(string::size_type i = 0; i < line.size(); ++i)
+    {
+        char c = line[i];
+        switch(state)
+        {
+          case Key:
+          {
+            switch(c)
+            {
+              case '\\':
+                if(i < line.length() - 1)
+                {
+                    c = line[++i];
+                    switch(c)
+                    {
+                      case '\\':
+                      case '#':
+                      case '=':
+                        key += whitespace;
+                        whitespace.clear();
+                        key += c; 
+                        break;
+
+                      case ' ':
+                        if(key.length() != 0)
+                        {
+                            whitespace += c;
+                        }
+                        break;
+
+                      default:
+                        key += whitespace;
+                        whitespace.clear();
+                        key += '\\';
+                        key += c;
+                        break;
+                    }
+                }
+                else
+                {
+                    key += whitespace;
+                    key += c;
+                }
+                break;
+
+              case ' ':
+              case '\t':
+              case '\r':
+              case '\n':
+                  if(key.length() != 0)
+                  {
+                      whitespace += c;
+                  }
+                  break;
+
+              case '=':
+                  whitespace.clear();
+                  state = Value;
+                  break;
+
+              case '#':
+                  finished = true;
+                  break;
+              
+              default:
+                  key += whitespace;
+                  whitespace.clear();
+                  key += c;
+                  break;
+            }
+            break;
+          }
+
+          case Value:
+          {
+            switch(c)
+            {
+              case '\\':
+                if(i < line.length() - 1)
+                {
+                    c = line[++i];
+                    switch(c)
+                    {
+                      case '\\':
+                      case '#':
+                      case '=':
+                        value += value.length() == 0 ? escapedspace : whitespace;
+                        whitespace.clear();
+                        escapedspace.clear();
+                        value += c; 
+                        break;
+
+                      case ' ':
+                        whitespace += c;
+                        escapedspace += c;
+                        break;
+
+                      default:
+                        value += value.length() == 0 ? escapedspace : whitespace;
+                        whitespace.clear();
+                        escapedspace.clear();
+                        value += '\\';
+                        value += c;
+                        break;
+                    }
+                }
+                else
+                {
+                    value += value.length() == 0 ? escapedspace : whitespace;
+                      value += c;
+                }
+                break;
+
+              case ' ':
+              case '\t':
+              case '\r':
+              case '\n':
+                  if(value.length() != 0)
+                  {
+                      whitespace += c;
+                  }
+                  break;
+
+              case '#':
+                  value += escapedspace;
+                  finished = true;
+                  break;
+              
+              default:
+                  value += value.length() == 0 ? escapedspace : whitespace;
+                  whitespace.clear();
+                  escapedspace.clear();
+                  value += c;
+                  break;
+            }
+            break;
+          }
+        }
+        if(finished)
+        {
+            break;
+        }
+    }
+    value += escapedspace;
+
+    if((state == Key && key.length() != 0) || (state == Value && key.length() == 0))
+    {
+        return ParseLineInvalid;
+    }
+    else if(key.length() == 0)
+    {
+        return ParseLineSkip;
+    }
+
+    keyval.first = key;
+    keyval.second = value;
+
+    return ParseLineOK;
+}

-----------------------------------------------------------------------


-- 
asterisk-scf/integration/ice.git



More information about the asterisk-scf-commits mailing list