3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-23 17:15:31 +00:00

remove symbol -> zstring -> symbol round-trips

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2021-05-22 13:12:49 -07:00
parent 5cb0bac41d
commit 20a67e47ca
13 changed files with 68 additions and 62 deletions

View file

@ -33,7 +33,7 @@ static bool is_hex_digit(char ch, unsigned& d) {
return false;
}
bool zstring::is_escape_char(bool from_input, char const *& s, unsigned& result) {
bool zstring::is_escape_char(char const *& s, unsigned& result) {
unsigned d;
if (*s == '\\' && s[1] == 'u' && s[2] == '{' && s[3] != '}') {
result = 0;
@ -55,8 +55,6 @@ bool zstring::is_escape_char(bool from_input, char const *& s, unsigned& result)
}
return false;
}
if (!from_input)
return false;
unsigned d1, d2, d3, d4;
if (*s == '\\' && s[1] == 'u' &&
is_hex_digit(s[2], d1) &&
@ -75,10 +73,10 @@ bool zstring::is_escape_char(bool from_input, char const *& s, unsigned& result)
return false;
}
zstring::zstring(char const* s, bool from_input) {
zstring::zstring(char const* s) {
while (*s) {
unsigned ch = 0;
if (is_escape_char(from_input, s, ch)) {
if (is_escape_char(s, ch)) {
m_buffer.push_back(ch);
}
else {
@ -89,6 +87,7 @@ zstring::zstring(char const* s, bool from_input) {
SASSERT(well_formed());
}
bool zstring::uses_unicode() const {
return gparams::get_value("unicode") != "false";
}
@ -236,12 +235,17 @@ zstring zstring::extract(unsigned offset, unsigned len) const {
return result;
}
unsigned zstring::hash() const {
return unsigned_ptr_hash(m_buffer.data(), m_buffer.size(), 23);
}
zstring zstring::operator+(zstring const& other) const {
zstring result(*this);
result.m_buffer.append(other.m_buffer);
return result;
}
bool zstring::operator==(const zstring& other) const {
// two strings are equal iff they have the same length and characters
if (length() != other.length()) {

View file

@ -19,21 +19,23 @@ Author:
#include <string>
#include "util/vector.h"
#include "util/buffer.h"
#include "util/rational.h"
class zstring {
private:
buffer<unsigned> m_buffer;
bool well_formed() const;
bool uses_unicode() const;
bool is_escape_char(bool from_input, char const *& s, unsigned& result);
bool is_escape_char(char const *& s, unsigned& result);
public:
static unsigned unicode_max_char() { return 196607; }
static unsigned unicode_num_bits() { return 18; }
static unsigned ascii_max_char() { return 255; }
static unsigned ascii_num_bits() { return 8; }
zstring() {}
zstring(char const* s, bool from_input);
zstring(const std::string &str) : zstring(str.c_str(), false) {}
zstring(char const* s);
zstring(const std::string &str) : zstring(str.c_str()) {}
zstring(rational const& r): zstring(r.to_string()) {}
zstring(unsigned sz, unsigned const* s) { m_buffer.append(sz, s); SASSERT(well_formed()); }
zstring(unsigned ch);
zstring replace(zstring const& src, zstring const& dst) const;
@ -51,6 +53,7 @@ public:
zstring operator+(zstring const& other) const;
bool operator==(const zstring& other) const;
bool operator!=(const zstring& other) const;
unsigned hash() const;
friend std::ostream& operator<<(std::ostream &os, const zstring &str);
friend bool operator<(const zstring& lhs, const zstring& rhs);