diff --git a/src/api/api_seq.cpp b/src/api/api_seq.cpp index 19e298ee8..0b4bd4348 100644 --- a/src/api/api_seq.cpp +++ b/src/api/api_seq.cpp @@ -55,6 +55,20 @@ extern "C" { Z3_CATCH_RETURN(nullptr); } + + Z3_ast Z3_API Z3_mk_lstring(Z3_context c, unsigned sz, Z3_string str) { + Z3_TRY; + LOG_Z3_mk_string(c, str); + RESET_ERROR_CODE(); + unsigned_vector chs; + for (unsigned i = 0; i < sz; ++i) chs.push_back(str[i]); + zstring s(sz, chs.c_ptr(), zstring::ascii); + app* a = mk_c(c)->sutil().str.mk_string(s); + mk_c(c)->save_ast_trail(a); + RETURN_Z3(of_ast(a)); + Z3_CATCH_RETURN(nullptr); + } + Z3_sort Z3_API Z3_mk_string_sort(Z3_context c) { Z3_TRY; LOG_Z3_mk_string_sort(c); diff --git a/src/api/python/z3/z3.py b/src/api/python/z3/z3.py index 2a3348ed9..f31df5a4f 100644 --- a/src/api/python/z3/z3.py +++ b/src/api/python/z3/z3.py @@ -10006,7 +10006,7 @@ def is_string_value(a): def StringVal(s, ctx=None): """create a string expression""" ctx = _get_ctx(ctx) - return SeqRef(Z3_mk_string(ctx.ref(), s), ctx) + return SeqRef(Z3_mk_lstring(ctx.ref(), len(s), s), ctx) def String(name, ctx=None): """Return a string constant named `name`. If `ctx=None`, then the global context is used. diff --git a/src/api/z3_api.h b/src/api/z3_api.h index e1710b499..ce59210f1 100644 --- a/src/api/z3_api.h +++ b/src/api/z3_api.h @@ -3327,6 +3327,15 @@ extern "C" { */ Z3_ast Z3_API Z3_mk_string(Z3_context c, Z3_string s); + /** + \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. + + def_API('Z3_mk_lstring' ,AST ,(_in(CONTEXT), _in(UINT), _in(STRING))) + */ + Z3_ast Z3_API Z3_mk_lstring(Z3_context c, unsigned len, Z3_string s); + /** \brief Determine if \c s is a string constant.