mirror of
https://github.com/Z3Prover/z3
synced 2025-06-20 04:43:39 +00:00
add get_lstring per #2286
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
112e13eeea
commit
b2845d888e
11 changed files with 64 additions and 10 deletions
|
@ -166,6 +166,12 @@ namespace api {
|
|||
m_string_buffer = str?str:"";
|
||||
return const_cast<char *>(m_string_buffer.c_str());
|
||||
}
|
||||
|
||||
char * context::mk_external_string(char const * str, unsigned n) {
|
||||
m_string_buffer.clear();
|
||||
m_string_buffer.append(str, n);
|
||||
return const_cast<char *>(m_string_buffer.c_str());
|
||||
}
|
||||
|
||||
char * context::mk_external_string(std::string && str) {
|
||||
m_string_buffer = std::move(str);
|
||||
|
|
|
@ -181,6 +181,7 @@ namespace api {
|
|||
|
||||
// Store a copy of str in m_string_buffer, and return a reference to it.
|
||||
// This method is used to communicate local/internal strings with the "external world"
|
||||
char * mk_external_string(char const * str, unsigned n);
|
||||
char * mk_external_string(char const * str);
|
||||
char * mk_external_string(std::string && str);
|
||||
|
||||
|
|
|
@ -150,6 +150,25 @@ extern "C" {
|
|||
Z3_CATCH_RETURN("");
|
||||
}
|
||||
|
||||
Z3_string Z3_API Z3_get_lstring(Z3_context c, Z3_ast s, unsigned* length) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_get_lstring(c, s, length);
|
||||
RESET_ERROR_CODE();
|
||||
zstring str;
|
||||
if (!length) {
|
||||
SET_ERROR_CODE(Z3_INVALID_ARG, "length argument is null");
|
||||
return "";
|
||||
}
|
||||
if (!mk_c(c)->sutil().str.is_string(to_expr(s), str)) {
|
||||
SET_ERROR_CODE(Z3_INVALID_ARG, "expression is not a string literal");
|
||||
return "";
|
||||
}
|
||||
std::string s = str.as_string();
|
||||
*length = static_cast<unsigned>(s.size());
|
||||
return mk_c(c)->mk_external_string(s.c_str(), s.size());
|
||||
Z3_CATCH_RETURN("");
|
||||
}
|
||||
|
||||
#define MK_SORTED(NAME, FN ) \
|
||||
Z3_ast Z3_API NAME(Z3_context c, Z3_sort s) { \
|
||||
Z3_TRY; \
|
||||
|
|
|
@ -3375,7 +3375,7 @@ extern "C" {
|
|||
/**
|
||||
\brief Create a string constant out of the string that is passed in
|
||||
It takes the length of the string as well to take into account
|
||||
0 characters.
|
||||
0 characters. The string is unescaped.
|
||||
|
||||
def_API('Z3_mk_lstring' ,AST ,(_in(CONTEXT), _in(UINT), _in(STRING)))
|
||||
*/
|
||||
|
@ -3397,6 +3397,15 @@ extern "C" {
|
|||
*/
|
||||
Z3_string Z3_API Z3_get_string(Z3_context c, Z3_ast s);
|
||||
|
||||
/**
|
||||
\brief Retrieve the unescaped string constant stored in \c s.
|
||||
|
||||
\pre Z3_is_string(c, s)
|
||||
|
||||
def_API('Z3_get_lstring' ,STRING ,(_in(CONTEXT), _in(AST), _out(UINT)))
|
||||
*/
|
||||
Z3_string Z3_API Z3_get_lstring(Z3_context c, Z3_ast s, unsigned* length);
|
||||
|
||||
/**
|
||||
\brief Create an empty sequence of the sequence sort \c seq.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue