diff options
author | ajreynol <andrew.j.reynolds@gmail.com> | 2016-08-10 17:36:45 -0500 |
---|---|---|
committer | ajreynol <andrew.j.reynolds@gmail.com> | 2016-08-10 17:36:58 -0500 |
commit | e8598e2420e2ee2c75abfb6629818299c7ab40f6 (patch) | |
tree | a727400a683fff8e2455e44dc04de68d94e08c6a /src/util | |
parent | 841acca266b026c9c1d20cb1adf0e73da15a0c10 (diff) |
Improvements to strings: work on propagations for reverse normal form processing. Better handling of disequalities, constant splitting and neg contain approximation. Introduce proxy vars for replace. Refactoring.
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/regexp.cpp | 11 | ||||
-rw-r--r-- | src/util/regexp.h | 33 |
2 files changed, 29 insertions, 15 deletions
diff --git a/src/util/regexp.cpp b/src/util/regexp.cpp index d211aaf1b..a6f0de4b3 100644 --- a/src/util/regexp.cpp +++ b/src/util/regexp.cpp @@ -110,6 +110,17 @@ std::size_t String::overlap(String &y) const { } return i; } +std::size_t String::roverlap(String &y) const { + std::size_t i = d_str.size() < y.size() ? d_str.size() : y.size(); + for(; i>0; i--) { + String s = prefix(i); + String p = y.suffix(i); + if(s == p) { + return i; + } + } + return i; +} std::string String::toString() const { std::string str; diff --git a/src/util/regexp.h b/src/util/regexp.h index 2cfcbc4e4..06766e046 100644 --- a/src/util/regexp.h +++ b/src/util/regexp.h @@ -239,24 +239,25 @@ public: if(d_str.size() < y.d_str.size() + start) return std::string::npos; if(y.d_str.size() == 0) return start; if(d_str.size() == 0) return std::string::npos; - std::size_t ret = std::string::npos; - /*for(std::size_t i = start; i <= d_str.size() - y.d_str.size(); i++) { - if(d_str[i] == y.d_str[0]) { - std::size_t j=0; - for(; j<y.d_str.size(); j++) { - if(d_str[i+j] != y.d_str[j]) break; - } - if(j == y.d_str.size()) { - ret = i; - break; - } - } - }*/ std::vector<unsigned>::const_iterator itr = std::search(d_str.begin() + start, d_str.end(), y.d_str.begin(), y.d_str.end()); if(itr != d_str.end()) { - ret = itr - d_str.begin(); + return itr - d_str.begin(); + }else{ + return std::string::npos; + } + } + + std::size_t rfind( String &y, const std::size_t start = 0) { + std::reverse( d_str.begin(), d_str.end() ); + std::reverse( y.d_str.begin(), y.d_str.end() ); + std::size_t f = find( y, start ); + std::reverse( d_str.begin(), d_str.end() ); + std::reverse( y.d_str.begin(), y.d_str.end() ); + if( f==std::string::npos ){ + return std::string::npos; + }else{ + return f; } - return ret; } String replace(const String &s, const String &t) const { @@ -295,6 +296,8 @@ public: } // if y=y1...yn and overlap returns m, then this is x1...y1...ym std::size_t overlap(String &y) const; + // if y=y1...yn and overlap returns m, then this is y(n+1-m)...yn...xk + std::size_t roverlap(String &y) const; bool isNumber() const { if(d_str.size() == 0) return false; |