summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorAndrew Reynolds <andrew.j.reynolds@gmail.com>2019-07-31 00:24:25 -0500
committerGitHub <noreply@github.com>2019-07-31 00:24:25 -0500
commited2ed9dffb709c9120890f665983abc594bdc0e5 (patch)
tree7f2df131caa95b5261899a613733587fa4b43482 /src/util
parent49853e244323fa1964d69621506aa5daf8177a9c (diff)
Eager conflict detection in strings based on constant prefix/suffix (#3110)
Diffstat (limited to 'src/util')
-rw-r--r--src/util/regexp.cpp37
-rw-r--r--src/util/regexp.h4
2 files changed, 41 insertions, 0 deletions
diff --git a/src/util/regexp.cpp b/src/util/regexp.cpp
index ed9455e6d..a76e9084b 100644
--- a/src/util/regexp.cpp
+++ b/src/util/regexp.cpp
@@ -394,6 +394,43 @@ std::size_t String::rfind(const String &y, const std::size_t start) const {
return std::string::npos;
}
+bool String::hasPrefix(const String& y) const
+{
+ size_t s = size();
+ size_t ys = y.size();
+ if (ys > s)
+ {
+ return false;
+ }
+ for (size_t i = 0; i < ys; i++)
+ {
+ if (d_str[i] != y.d_str[i])
+ {
+ return false;
+ }
+ }
+ return true;
+}
+
+bool String::hasSuffix(const String& y) const
+{
+ size_t s = size();
+ size_t ys = y.size();
+ if (ys > s)
+ {
+ return false;
+ }
+ size_t idiff = s - ys;
+ for (size_t i = 0; i < ys; i++)
+ {
+ if (d_str[i + idiff] != y.d_str[i])
+ {
+ return false;
+ }
+ }
+ return true;
+}
+
String String::replace(const String &s, const String &t) const {
std::size_t ret = find(s);
if (ret != std::string::npos) {
diff --git a/src/util/regexp.h b/src/util/regexp.h
index f7c6fb2ae..d1cb197fb 100644
--- a/src/util/regexp.h
+++ b/src/util/regexp.h
@@ -142,6 +142,10 @@ class CVC4_PUBLIC String {
std::size_t find(const String& y, const std::size_t start = 0) const;
std::size_t rfind(const String& y, const std::size_t start = 0) const;
+ /** Returns true if y is a prefix of this */
+ bool hasPrefix(const String& y) const;
+ /** Returns true if y is a suffix of this */
+ bool hasSuffix(const String& y) const;
String replace(const String& s, const String& t) const;
String substr(std::size_t i) const;
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback