]> git.tdb.fi Git - libs/core.git/blobdiff - source/regex.cpp
Fix a bug in Regex with brackets
[libs/core.git] / source / regex.cpp
index 839435ef3bf62fd9c95134efd005e97d307dc011..320705e8e33dc1cecbca03a26adab78e9d498805 100644 (file)
@@ -1,3 +1,9 @@
+/* $Id$
+
+This file is part of libmspstrings
+Copyright © 2007 Mikko Rasa
+Distributed under the LGPL
+*/
 #include <stack>
 #include <msp/core/error.h>
 #include "formatter.h"
@@ -5,8 +11,6 @@
 
 using namespace std;
 
-#include <iostream>
-
 namespace {
 
 /**
@@ -303,14 +307,14 @@ Regex::Code Regex::parse_brackets(const string &str, string::const_iterator &ite
        }
 
        string::const_iterator end=iter;
-       for(; (end!=str.end() && *end!=']'); ++end);
+       for(; (end!=str.end() && (end==iter || *end!=']')); ++end);
        if(end==str.end())
                throw InvalidParameterValue("Unmatched '['");
 
        uint8_t mask[32]={0};
        unsigned type=0;
        bool range=false;
-       unsigned char first, last;
+       unsigned char first=0, last=0;
        for(string::const_iterator i=iter; i!=end; ++i)
        {
                unsigned char c=*i;
@@ -496,7 +500,7 @@ bool Regex::group_compare(const RegMatch::Group &g1, const RegMatch::Group &g2)
 {
        if(!g1.match)
                return false;
-       
+
        // Any match is better than no match
        if(!g2.match)
                return true;