Skip to content

Commit 05f62fd

Browse files
Merge pull request #1201 from LAJW/test-gen-escape-quota
Escape ["] character in generated tests
2 parents 591aea0 + 21735a0 commit 05f62fd

File tree

5 files changed

+23
-14
lines changed

5 files changed

+23
-14
lines changed

src/solvers/refinement/string_constraint_generator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ exprt get_numeric_value_from_character(
375375
unsigned long radix=36ul);
376376
size_t max_printed_string_length(const typet &type, unsigned long ul_radix);
377377
unsigned long to_integer_or_default(const exprt &expr, unsigned long def);
378-
std::string utf16_constant_array_to_ascii(
378+
std::string utf16_constant_array_to_java(
379379
const array_exprt &arr, unsigned length);
380380

381381
#endif

src/solvers/refinement/string_constraint_generator_format.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ string_exprt string_constraint_generatort::add_axioms_for_format(
386386
/// \param length: an unsigned value representing the length of the array
387387
/// \return String of length `length` represented by the array assuming each
388388
/// field in `arr` represents a character.
389-
std::string utf16_constant_array_to_ascii(
389+
std::string utf16_constant_array_to_java(
390390
const array_exprt &arr, unsigned int length)
391391
{
392392
std::wstring out(length, '?');
@@ -399,7 +399,7 @@ std::string utf16_constant_array_to_ascii(
399399
INVARIANT(!conversion_failed, "constant should be convertible to unsigned");
400400
out[i]=c;
401401
}
402-
return utf16_little_endian_to_ascii(out);
402+
return utf16_little_endian_to_java(out);
403403
}
404404

405405
/// Add axioms to specify the Java String.format function.
@@ -423,7 +423,7 @@ string_exprt string_constraint_generatort::add_axioms_for_format(
423423
s1.content().id()==ID_array &&
424424
!to_unsigned_integer(to_constant_expr(s1.length()), length))
425425
{
426-
std::string s=utf16_constant_array_to_ascii(
426+
std::string s=utf16_constant_array_to_java(
427427
to_array_expr(s1.content()), length);
428428
// List of arguments after s
429429
std::vector<exprt> args(

src/solvers/refinement/string_refinement.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ std::string string_refinementt::string_of_array(const array_exprt &arr)
799799
exprt size_expr=to_array_type(arr.type()).size();
800800
PRECONDITION(size_expr.id()==ID_constant);
801801
to_unsigned_integer(to_constant_expr(size_expr), n);
802-
return utf16_constant_array_to_ascii(arr, n);
802+
return utf16_constant_array_to_java(arr, n);
803803
}
804804

805805
/// Display part of the current model by mapping the variables created by the

src/util/unicode.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,37 +272,46 @@ std::wstring utf8_to_utf16(const std::string& in, bool swap_bytes)
272272

273273
/// \par parameters: String in UTF-8 format
274274
/// \return String in UTF-16BE format
275-
std::wstring utf8_to_utf16_big_endian(const std::string& in)
275+
std::wstring utf8_to_utf16_big_endian(const std::string &in)
276276
{
277277
bool swap_bytes=is_little_endian_arch();
278278
return utf8_to_utf16(in, swap_bytes);
279279
}
280280

281281
/// \par parameters: String in UTF-8 format
282282
/// \return String in UTF-16LE format
283-
std::wstring utf8_to_utf16_little_endian(const std::string& in)
283+
std::wstring utf8_to_utf16_little_endian(const std::string &in)
284284
{
285285
bool swap_bytes=!is_little_endian_arch();
286286
return utf8_to_utf16(in, swap_bytes);
287287
}
288288

289289
/// \par parameters: String in UTF-16LE format
290290
/// \return String in US-ASCII format, with \uxxxx escapes for other characters
291-
std::string utf16_little_endian_to_ascii(const std::wstring& in)
291+
std::string utf16_little_endian_to_java(const std::wstring &in)
292292
{
293293
std::ostringstream result;
294-
std::locale loc;
295-
for(const auto c : in)
294+
const std::locale loc;
295+
for(const auto ch : in)
296296
{
297-
if(c<=255 && isprint(c, loc))
298-
result << (unsigned char)c;
297+
if(ch=='\n')
298+
result << "\\n";
299+
else if(ch=='\r')
300+
result << "\\r";
301+
else if(ch<=255 && isprint(ch, loc))
302+
{
303+
const auto uch=static_cast<unsigned char>(ch);
304+
if(uch=='"')
305+
result << '\\';
306+
result << uch;
307+
}
299308
else
300309
{
301310
result << "\\u"
302311
<< std::hex
303312
<< std::setw(4)
304313
<< std::setfill('0')
305-
<< (unsigned int)c;
314+
<< static_cast<unsigned int>(ch);
306315
}
307316
}
308317
return result.str();

src/util/unicode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ std::string utf32_to_utf8(const std::basic_string<unsigned int> &s);
2424

2525
std::wstring utf8_to_utf16_big_endian(const std::string &);
2626
std::wstring utf8_to_utf16_little_endian(const std::string &);
27-
std::string utf16_little_endian_to_ascii(const std::wstring &in);
27+
std::string utf16_little_endian_to_java(const std::wstring &in);
2828

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

0 commit comments

Comments
 (0)