Add specialization for lexical_cast<std::string> to avoid borking with spaces
authorMikko Rasa <tdb@tdb.fi>
Wed, 6 Aug 2008 19:34:49 +0000 (19:34 +0000)
committerMikko Rasa <tdb@tdb.fi>
Wed, 6 Aug 2008 19:34:49 +0000 (19:34 +0000)
Fix handling of parentheses inside bracker expressions in RegEx
Update ignores

source/lexicalcast.h
source/regex.cpp

index e67f361faa24429189027515f403f0604c9a0650..a2bb43953d43d764e24ff517d62e1ffd0052f6ee 100644 (file)
@@ -36,6 +36,12 @@ T lexical_cast(const std::string &s)
        return tmp;
 }
 
+template<>
+inline std::string lexical_cast<std::string>(const std::string &s)
+{
+       return s;
+}
+
 template<typename T>
 std::string lexical_cast(const T &v, const Fmt &f=Fmt())
 {
index a1babf46d019b77a1db433a92ed447a0fbd2d6a2..c2590f2c8f8d9109606d06499da24b6b51c87e80 100644 (file)
@@ -86,11 +86,21 @@ Regex::Code Regex::compile(const string &expr, string::const_iterator &iter, uns
        bool has_branches=false;
        unsigned level=0;
        bool escape=false;
+       unsigned bracket=0;
        string::const_iterator end;
        for(end=iter; end!=expr.end(); ++end)
        {
                if(escape)
                        escape=false;
+               else if(bracket)
+               {
+                       if(bracket==3 && *end==']')
+                               bracket=0;
+                       else if(bracket==1 && *end=='^')
+                               bracket=2;
+                       else
+                               bracket=3;
+               }
                else if(*end=='\\')
                        escape=true;
                else if(*end=='(')
@@ -113,6 +123,8 @@ Regex::Code Regex::compile(const string &expr, string::const_iterator &iter, uns
                        else if(level==0)
                                has_branches=true;
                }
+               else if(*end=='[')
+                       bracket=1;
        }
 
        if(level>0)