X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fstrings%2Fregex.cpp;h=9167c6b8a9e6ae0f75fd52206bb96efe45a9424b;hp=60b8ed10294aa1e83b399cb3605a3ef9750b597b;hb=f24e7b96e76b63c9b9b8a6bce4c7a9db64276ea8;hpb=c7afef88380ebebc8c2b04e48664d73281ec8848 diff --git a/source/strings/regex.cpp b/source/strings/regex.cpp index 60b8ed1..9167c6b 100644 --- a/source/strings/regex.cpp +++ b/source/strings/regex.cpp @@ -10,7 +10,7 @@ namespace { /** Writes an integer to a Regex code string, in little-endian order. */ template -void write_int(T n, Msp::Regex::Code &code) +void write_int(T n, basic_string &code) { for(unsigned i=0; i>(i*8))&0xFF; @@ -18,7 +18,7 @@ void write_int(T n, Msp::Regex::Code &code) /** Reads an integer from a Regex code string, in little-endian order. */ template -T read_int(Msp::Regex::Code::const_iterator &c) +T read_int(basic_string::const_iterator &c) { T result = 0; for(unsigned i=0; i 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::iterator i=++branches.begin(); i!=branches.end(); ++i) + for(auto i=++branches.begin(); i!=branches.end(); ++i) { result += ND_JUMP; write_int(offset, result); offset += i->size(); } - for(list::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); @@ -310,8 +310,8 @@ Regex::Code Regex::parse_brackets(const string &str, string::const_iterator &ite unsigned char mask[32] = {0}; unsigned type = 0; bool range = false; - unsigned char first=0, last = 0; - for(string::const_iterator i=iter; i!=end; ++i) + unsigned char first = 0, last = 0; + 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 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 &groups) const { bool result = false; list 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::iterator j=ctx.begin(); j!=ctx.end();) + for(auto j=ctx.begin(); j!=ctx.end();) { bool terminate = false; bool negate_match = false; @@ -513,7 +513,7 @@ bool Regex::group_compare(const RegMatch::Group &g1, const RegMatch::Group &g2) // Earlier match is better if(g1.beging2.begin) + if(g1.begin>g2.begin) return false; // Longer match at same position is better @@ -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;