diff options
author | Andrew Reynolds <andrew.j.reynolds@gmail.com> | 2018-07-04 16:34:17 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-04 16:34:17 +0100 |
commit | 8494e02bf31a08a686e1cf990e512250a9210acc (patch) | |
tree | c94bd7a5658dfd978cafb13b2b3547e15d790c50 /src/util | |
parent | 3e9c44a361d287d30d4aa9771f77677a025a766e (diff) |
More cleanup in strings (#2138)
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/regexp.cpp | 17 | ||||
-rw-r--r-- | src/util/regexp.h | 9 |
2 files changed, 13 insertions, 13 deletions
diff --git a/src/util/regexp.cpp b/src/util/regexp.cpp index 8589c6993..93178b948 100644 --- a/src/util/regexp.cpp +++ b/src/util/regexp.cpp @@ -421,18 +421,11 @@ size_t String::maxSize() { return std::numeric_limits<size_t>::max(); } - -int String::toNumber() const { - if (isNumber()) { - int ret = 0; - for (unsigned int i = 0; i < size(); ++i) { - unsigned char c = convertUnsignedIntToChar(d_str[i]); - ret = ret * 10 + (int)c - (int)'0'; - } - return ret; - } else { - return -1; - } +Rational String::toNumber() const +{ + // when smt2 standard for strings is set, this may change, based on the + // semantics of str.from.int for leading zeros + return Rational(toString()); } unsigned char String::hexToDec(unsigned char c) { diff --git a/src/util/regexp.h b/src/util/regexp.h index e2d07111d..e91ca61e2 100644 --- a/src/util/regexp.h +++ b/src/util/regexp.h @@ -25,6 +25,7 @@ #include <ostream> #include <string> #include <vector> +#include "util/rational.h" namespace CVC4 { @@ -178,8 +179,14 @@ class CVC4_PUBLIC String { */ std::size_t roverlap(const String& y) const; + /** + * Returns true if this string corresponds in text to a number, for example + * this returns true for strings "7", "12", "004", "0" and false for strings + * "abc", "4a", "-4", "". + */ bool isNumber() const; - int toNumber() const; + /** Returns the corresponding rational for the text of this string. */ + Rational toNumber() const; const std::vector<unsigned>& getVec() const { return d_str; } /** is the unsigned a digit? |