summaryrefslogtreecommitdiff
path: root/src/api/cvc4cpp.cpp
diff options
context:
space:
mode:
authormudathirmahgoub <mudathirmahgoub@gmail.com>2021-01-28 14:51:28 -0600
committerGitHub <noreply@github.com>2021-01-28 14:51:28 -0600
commit2f4bae4b4ffe6e913925f3d8f2c857a01aeea3bd (patch)
tree09aa68a87615a64766aa4ce5240771cf9444b974 /src/api/cvc4cpp.cpp
parente234ff58f561ac97642df15c698962faa9d1e5e4 (diff)
Remove regex header from cvc4cpp.cpp (#5826)
This PR replaces the heavy hammer std::regex_match for checking numbers with string operations
Diffstat (limited to 'src/api/cvc4cpp.cpp')
-rw-r--r--src/api/cvc4cpp.cpp42
1 files changed, 39 insertions, 3 deletions
diff --git a/src/api/cvc4cpp.cpp b/src/api/cvc4cpp.cpp
index abec4d8dd..541c5f5a5 100644
--- a/src/api/cvc4cpp.cpp
+++ b/src/api/cvc4cpp.cpp
@@ -34,7 +34,6 @@
#include "api/cvc4cpp.h"
#include <cstring>
-#include <regex>
#include <sstream>
#include "base/check.h"
@@ -3924,11 +3923,48 @@ Term Solver::mkPi() const
CVC4_API_SOLVER_TRY_CATCH_END;
}
+bool Solver::isValidInteger(const std::string& s) const
+{
+ if (s.length() == 0)
+ {
+ // string should not be empty
+ return false;
+ }
+
+ size_t index = 0;
+ if (s[index] == '-')
+ {
+ if (s.length() == 1)
+ {
+ // negative integers should contain at least one digit
+ return false;
+ }
+ index = 1;
+ }
+
+ if (s[index] == '0' && s.length() > (index + 1))
+ {
+ // From SMT-Lib 2.6: A〈numeral〉is the digit 0 or a non-empty sequence of
+ // digits not starting with 0. So integers like 001, 000 are not allowed
+ return false;
+ }
+
+ // all remaining characters should be decimal digits
+ for (; index < s.length(); ++index)
+ {
+ if (!std::isdigit(s[index]))
+ {
+ return false;
+ }
+ }
+
+ return true;
+}
+
Term Solver::mkInteger(const std::string& s) const
{
CVC4_API_SOLVER_TRY_CATCH_BEGIN;
- CVC4_API_ARG_CHECK_EXPECTED(std::regex_match(s, std::regex("-?\\d+")), s)
- << " an integer ";
+ CVC4_API_ARG_CHECK_EXPECTED(isValidInteger(s), s) << " an integer ";
Term integer = mkRealFromStrHelper(s);
CVC4_API_ARG_CHECK_EXPECTED(integer.getSort() == getIntegerSort(), s)
<< " an integer";
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback