]> 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 ae3576ce5423930c4cfb225a51fbe42f649d3141..320705e8e33dc1cecbca03a26adab78e9d498805 100644 (file)
@@ -11,8 +11,6 @@ Distributed under the LGPL
 
 using namespace std;
 
-#include <iostream>
-
 namespace {
 
 /**
@@ -309,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;
@@ -502,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;