]> git.tdb.fi Git - libs/core.git/blobdiff - source/regex.cpp
Add specialization for lexical_cast<std::string> to avoid borking with spaces
[libs/core.git] / source / regex.cpp
index 48fe4a7c3422fb027c40481d1f7d39b8fc7010d3..c2590f2c8f8d9109606d06499da24b6b51c87e80 100644 (file)
@@ -4,7 +4,9 @@ This file is part of libmspstrings
 Copyright © 2007 Mikko Rasa
 Distributed under the LGPL
 */
+
 #include <stack>
+#include <limits>
 #include <msp/core/except.h>
 #include "formatter.h"
 #include "regex.h"
@@ -84,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=='(')
@@ -111,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)
@@ -306,7 +320,7 @@ Regex::Code Regex::parse_brackets(const string &str, string::const_iterator &ite
        }
 
        string::const_iterator end=iter;
-       for(; (end!=str.end() && (end==iter || *end!=']')); ++end);
+       for(; (end!=str.end() && (end==iter || *end!=']')); ++end) ;
        if(end==str.end())
                throw InvalidParameterValue("Unmatched '['");