]> git.tdb.fi Git - libs/core.git/blobdiff - source/strings/regex.cpp
Use C++11 features with containers
[libs/core.git] / source / strings / regex.cpp
index 68cf374dcd2544064e45ce661ddb01768f962f1d..9167c6b8a9e6ae0f75fd52206bb96efe45a9424b 100644 (file)
@@ -56,7 +56,7 @@ string bad_regex::make_where(const string &e, const string::const_iterator &i)
 Regex::Regex(const string &expr)
 {
        n_groups = 0;
-       string::const_iterator iter = expr.begin();
+       auto iter = expr.begin();
        code = compile(expr, iter, n_groups, false);
        ++n_groups;
 }
@@ -123,7 +123,7 @@ Regex::Code Regex::compile(const string &expr, string::const_iterator &iter, uns
 
        if(!has_branches)
        {
-               for(string::const_iterator i=iter; i!=end;)
+               for(auto i=iter; i!=end;)
                {
                        Code atom = parse_atom(expr, i, group);
 
@@ -158,7 +158,7 @@ Regex::Code Regex::compile(const string &expr, string::const_iterator &iter, uns
        else
        {
                list<Code> branches;
-               for(string::const_iterator i=iter;;)
+               for(auto i=iter;;)
                {
                        branches.push_back(compile(expr, i, group, true));
                        if(i==end)
@@ -169,14 +169,14 @@ Regex::Code Regex::compile(const string &expr, string::const_iterator &iter, uns
                unsigned n_branches = branches.size();
 
                Offset offset = (n_branches-1)*jump_size+branches.front().size();
-               for(list<Code>::iterator i=++branches.begin(); i!=branches.end(); ++i)
+               for(auto i=++branches.begin(); i!=branches.end(); ++i)
                {
                        result += ND_JUMP;
                        write_int<Offset>(offset, result);
                        offset += i->size();
                }
 
-               for(list<Code>::iterator i=branches.begin(); i!=branches.end();)
+               for(auto i=branches.begin(); i!=branches.end();)
                {
                        result += *i;
                        offset -= i->size()+jump_size;
@@ -258,7 +258,7 @@ bool Regex::parse_repeat(const string &expr, string::const_iterator &i, Count &r
                rmin = 0;
        if(*i=='{')
        {
-               string::const_iterator begin = i;
+               auto begin = i;
 
                rmin = 0;
                for(++i; isdigit(*i); ++i)
@@ -291,7 +291,7 @@ bool Regex::parse_repeat(const string &expr, string::const_iterator &i, Count &r
 
 Regex::Code Regex::parse_brackets(const string &str, string::const_iterator &iter)
 {
-       string::const_iterator begin = iter;
+       auto begin = iter;
        Code result;
 
        ++iter;
@@ -302,7 +302,7 @@ Regex::Code Regex::parse_brackets(const string &str, string::const_iterator &ite
                ++iter;
        }
 
-       string::const_iterator end = iter;
+       auto end = iter;
        for(; (end!=str.end() && (end==iter || *end!=']')); ++end) ;
        if(end==str.end())
                throw bad_regex("unmatched '['", str, begin);
@@ -311,7 +311,7 @@ Regex::Code Regex::parse_brackets(const string &str, string::const_iterator &ite
        unsigned type = 0;
        bool range = false;
        unsigned char first = 0, last = 0;
-       for(string::const_iterator i=iter; i!=end; ++i)
+       for(auto i=iter; i!=end; ++i)
        {
                unsigned char c = *i;
                if(range)
@@ -364,16 +364,16 @@ Regex::Code Regex::parse_brackets(const string &str, string::const_iterator &ite
 
 RegMatch Regex::match(const string &str) const
 {
-       RegMatch::GroupArray groups(n_groups);
+       vector<RegMatch::Group> groups(n_groups);
 
-       for(string::const_iterator i=str.begin(); i!=str.end(); ++i)
+       for(auto i=str.begin(); i!=str.end(); ++i)
                if(run(str, i, groups))
                        return RegMatch(str, groups);
 
        return RegMatch();
 }
 
-bool Regex::run(const string &str, const string::const_iterator &begin, RegMatch::GroupArray &groups) const
+bool Regex::run(const string &str, const string::const_iterator &begin, vector<RegMatch::Group> &groups) const
 {
        bool result = false;
        list<RunContext> ctx;
@@ -381,7 +381,7 @@ bool Regex::run(const string &str, const string::const_iterator &begin, RegMatch
        ctx.front().citer = code.begin();
        ctx.front().groups.resize(groups.size());
 
-       for(string::const_iterator i=begin;;)
+       for(auto i=begin;;)
        {
                int c;
                if(i!=str.end())
@@ -389,7 +389,7 @@ bool Regex::run(const string &str, const string::const_iterator &begin, RegMatch
                else
                        c = -1;
 
-               for(list<RunContext>::iterator j=ctx.begin(); j!=ctx.end();)
+               for(auto j=ctx.begin(); j!=ctx.end();)
                {
                        bool terminate = false;
                        bool negate_match = false;
@@ -524,9 +524,9 @@ string Regex::disassemble() const
 {
        string result;
 
-       for(Code::const_iterator i=code.begin(); i!=code.end();)
+       for(auto i=code.begin(); i!=code.end();)
        {
-               Code::const_iterator j = i;
+               auto j = i;
                Offset offset = i-code.begin();
                string decompiled = disassemble_instruction(i);
                string bytes;