Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape ["] character in generated tests #1201

Merged
merged 2 commits into from
Aug 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/solvers/refinement/string_constraint_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ exprt get_numeric_value_from_character(
unsigned long radix=36ul);
size_t max_printed_string_length(const typet &type, unsigned long radix);
unsigned long to_integer_or_default(const exprt &expr, unsigned long def);
std::string utf16_constant_array_to_ascii(
std::string utf16_constant_array_to_java(
const array_exprt &arr, unsigned length);

#endif
6 changes: 3 additions & 3 deletions src/solvers/refinement/string_constraint_generator_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ string_exprt string_constraint_generatort::add_axioms_for_format(
/// \param length: an unsigned value representing the length of the array
/// \return String of length `length` represented by the array assuming each
/// field in `arr` represents a character.
std::string utf16_constant_array_to_ascii(
std::string utf16_constant_array_to_java(
const array_exprt &arr, unsigned int length)
{
std::wstring out(length, '?');
Expand All @@ -399,7 +399,7 @@ std::string utf16_constant_array_to_ascii(
INVARIANT(!conversion_failed, "constant should be convertible to unsigned");
out[i]=c;
}
return utf16_little_endian_to_ascii(out);
return utf16_little_endian_to_java(out);
}

/// Add axioms to specify the Java String.format function.
Expand All @@ -423,7 +423,7 @@ string_exprt string_constraint_generatort::add_axioms_for_format(
s1.content().id()==ID_array &&
!to_unsigned_integer(to_constant_expr(s1.length()), length))
{
std::string s=utf16_constant_array_to_ascii(
std::string s=utf16_constant_array_to_java(
to_array_expr(s1.content()), length);
// List of arguments after s
std::vector<exprt> args(
Expand Down
2 changes: 1 addition & 1 deletion src/solvers/refinement/string_refinement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ std::string string_refinementt::string_of_array(const array_exprt &arr)
exprt size_expr=to_array_type(arr.type()).size();
PRECONDITION(size_expr.id()==ID_constant);
to_unsigned_integer(to_constant_expr(size_expr), n);
return utf16_constant_array_to_ascii(arr, n);
return utf16_constant_array_to_java(arr, n);
}

/// Display part of the current model by mapping the variables created by the
Expand Down
25 changes: 17 additions & 8 deletions src/util/unicode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,37 +272,46 @@ std::wstring utf8_to_utf16(const std::string& in, bool swap_bytes)

/// \par parameters: String in UTF-8 format
/// \return String in UTF-16BE format
std::wstring utf8_to_utf16_big_endian(const std::string& in)
std::wstring utf8_to_utf16_big_endian(const std::string &in)
{
bool swap_bytes=is_little_endian_arch();
return utf8_to_utf16(in, swap_bytes);
}

/// \par parameters: String in UTF-8 format
/// \return String in UTF-16LE format
std::wstring utf8_to_utf16_little_endian(const std::string& in)
std::wstring utf8_to_utf16_little_endian(const std::string &in)
{
bool swap_bytes=!is_little_endian_arch();
return utf8_to_utf16(in, swap_bytes);
}

/// \par parameters: String in UTF-16LE format
/// \return String in US-ASCII format, with \uxxxx escapes for other characters
std::string utf16_little_endian_to_ascii(const std::wstring& in)
std::string utf16_little_endian_to_java(const std::wstring &in)
{
std::ostringstream result;
std::locale loc;
for(const auto c : in)
const std::locale loc;
for(const auto ch : in)
{
if(c<=255 && isprint(c, loc))
result << (unsigned char)c;
if(ch=='\n')
result << "\\n";
else if(ch=='\r')
result << "\\r";
else if(ch<=255 && isprint(ch, loc))
{
const auto uch=static_cast<unsigned char>(ch);
if(uch=='"')
result << '\\';
result << uch;
}
else
{
result << "\\u"
<< std::hex
<< std::setw(4)
<< std::setfill('0')
<< (unsigned int)c;
<< static_cast<unsigned int>(ch);
}
}
return result.str();
Expand Down
2 changes: 1 addition & 1 deletion src/util/unicode.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ std::string utf32_to_utf8(const std::basic_string<unsigned int> &s);

std::wstring utf8_to_utf16_big_endian(const std::string &);
std::wstring utf8_to_utf16_little_endian(const std::string &);
std::string utf16_little_endian_to_ascii(const std::wstring &in);
std::string utf16_little_endian_to_java(const std::wstring &in);

const char **narrow_argv(int argc, const wchar_t **argv_wide);

Expand Down