]> git.tdb.fi Git - libs/core.git/blobdiff - source/strings/regex.cpp
Add move semantics to Variant
[libs/core.git] / source / strings / regex.cpp
index 9167c6b8a9e6ae0f75fd52206bb96efe45a9424b..5307c6990286ba373291281fb4ee230ff81d2d07 100644 (file)
@@ -1,6 +1,8 @@
 #include <limits>
 #include <list>
 #include <stack>
+#include <vector>
+#include <msp/core/except.h>
 #include "format.h"
 #include "regex.h"
 
@@ -55,7 +57,6 @@ string bad_regex::make_where(const string &e, const string::const_iterator &i)
 
 Regex::Regex(const string &expr)
 {
-       n_groups = 0;
        auto iter = expr.begin();
        code = compile(expr, iter, n_groups, false);
        ++n_groups;
@@ -129,7 +130,8 @@ Regex::Code Regex::compile(const string &expr, string::const_iterator &iter, uns
 
                        Count repeat_min = 1;
                        Count repeat_max = 1;
-                       parse_repeat(expr, i, repeat_min, repeat_max);
+                       if(i!=end)
+                               parse_repeat(expr, i, repeat_min, repeat_max);
 
                        for(unsigned j=0; j<repeat_min; ++j)
                                result += atom;
@@ -142,7 +144,7 @@ Regex::Code Regex::compile(const string &expr, string::const_iterator &iter, uns
                                        result += atom;
                                }
                                result += ND_JUMP;
-                               write_int<Offset>(-(atom.size()+jump_size), result);
+                               write_int<Offset>(-static_cast<Offset>(atom.size()+jump_size), result);
                        }
                        else if(repeat_max>repeat_min)
                        {
@@ -157,7 +159,7 @@ Regex::Code Regex::compile(const string &expr, string::const_iterator &iter, uns
        }
        else
        {
-               list<Code> branches;
+               vector<Code> branches;
                for(auto i=iter;;)
                {
                        branches.push_back(compile(expr, i, group, true));
@@ -476,7 +478,7 @@ bool Regex::run(const string &str, const string::const_iterator &begin, vector<R
                                                input_consumed = true;
                                        }
                                        else
-                                               throw logic_error("invalid instruction in regex bytecode");
+                                               throw internal_error("invalid instruction in regex bytecode");
 
                                        if(match_result==negate_match)
                                                terminate = true;