3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-15 05:18:44 +00:00
z3/src/util/smt2_util.cpp
Leonardo de Moura d8cd3fc3ab Reorganizing the code
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2012-10-20 19:54:08 -07:00

63 lines
1.4 KiB
C++

/*++
Copyright (c) 2011 Microsoft Corporation
Module Name:
smt2_util.cpp
Abstract:
Goodies for SMT2 standard
Author:
Leonardo (leonardo) 2012-10-20
Notes:
--*/
#include"smt2_util.h"
bool is_smt2_simple_symbol_char(char s) {
return
('0' <= s && s <= '9') ||
('a' <= s && s <= 'z') ||
('A' <= s && s <= 'Z') ||
s == '~' || s == '!' || s == '@' || s == '$' || s == '%' || s == '^' || s == '&' ||
s == '*' || s == '_' || s == '-' || s == '+' || s == '=' || s == '<' || s == '>' ||
s == '.' || s == '?' || s == '/';
}
bool is_smt2_quoted_symbol(char const * s) {
if (s == 0)
return false;
if ('0' <= s[0] && s[0] <= '9')
return true;
unsigned len = static_cast<unsigned>(strlen(s));
for (unsigned i = 0; i < len; i++)
if (!is_smt2_simple_symbol_char(s[i]))
return true;
return false;
}
bool is_smt2_quoted_symbol(symbol const & s) {
if (s.is_numerical())
return false;
return is_smt2_quoted_symbol(s.bare_str());
}
std::string mk_smt2_quoted_symbol(symbol const & s) {
SASSERT(is_smt2_quoted_symbol(s));
string_buffer<> buffer;
buffer.append('|');
char const * str = s.bare_str();
while (*str) {
if (*str == '|' || *str == '\\')
buffer.append('\\');
buffer.append(*str);
str++;
}
buffer.append('|');
return std::string(buffer.c_str());
}