]> git.tdb.fi Git - libs/core.git/blobdiff - source/regex.cpp
Fix octal escape generation in c_escape
[libs/core.git] / source / regex.cpp
index a1babf46d019b77a1db433a92ed447a0fbd2d6a2..9ba089d09008c7fd1c23a9d700051984eab11362 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=='(')
@@ -106,13 +116,15 @@ Regex::Code Regex::compile(const string &expr, string::const_iterator &iter, uns
                        }
                        --level;
                }
-               else if(*end=='|')
+               else if(*end=='|' && level==0)
                {
                        if(branch)
                                break;
-                       else if(level==0)
+                       else
                                has_branches=true;
                }
+               else if(*end=='[')
+                       bracket=1;
        }
 
        if(level>0)
@@ -312,7 +324,7 @@ Regex::Code Regex::parse_brackets(const string &str, string::const_iterator &ite
        if(end==str.end())
                throw InvalidParameterValue("Unmatched '['");
 
-       uint8_t mask[32]={0};
+       unsigned char mask[32]={0};
        unsigned type=0;
        bool range=false;
        unsigned char first=0, last=0;
@@ -456,11 +468,13 @@ bool Regex::run(const string &str, const string::const_iterator &begin, RegMatch
                                        }
                                        else if(instr==MATCH_MASK)
                                        {
-                                               uint8_t mask[32];
-                                               for(unsigned k=0; k<32; ++k)
-                                                       mask[k]=*j->citer++;
-                                               match_result=mask[c>>3]&(1<<(c&7));
-                                               input_consumed=true;
+                                               if(c>=0 && c<=0xFF)
+                                               {
+                                                       unsigned char m=*(j->citer+(c>>3));
+                                                       match_result=m&(1<<(c&7));
+                                                       input_consumed=true;
+                                                       j->citer+=32;
+                                               }
                                        }
                                        else if(instr==MATCH_ANY)
                                        {