Skip to content

Commit 8ed1023

Browse files
committed
Use UTF-16 conversion function in expr2java
newline and carriage return need to be printed as \n and \r in Java code, respectively (as opposed to \u000a and \u000d). ' and \ need to be escaped. The previous implementation was missing those cases. In addition to that, a call to an existing function is a cleaner way of writing this.
1 parent a53f5bf commit 8ed1023

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

src/java_bytecode/expr2java.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Author: Daniel Kroening, kroening@cs.cmu.edu
1515
#include <util/std_types.h>
1616
#include <util/std_expr.h>
1717
#include <util/symbol.h>
18+
#include <util/unicode.h>
1819
#include <util/arith_tools.h>
1920
#include <util/ieee_float.h>
2021

@@ -191,20 +192,7 @@ std::string expr2javat::convert_constant(
191192
if(to_integer(src, int_value))
192193
UNREACHABLE;
193194

194-
dest+="(char)'";
195-
196-
if(int_value>=' ' && int_value<127)
197-
dest+=static_cast<char>(int_value.to_long());
198-
else
199-
{
200-
std::string hex=integer2string(int_value, 16);
201-
while(hex.size()<4) hex='0'+hex;
202-
dest+='\\';
203-
dest+='u';
204-
dest+=hex;
205-
}
206-
207-
dest+='\'';
195+
dest += "(char)'" + utf16_little_endian_to_java(int_value.to_long()) + '\'';
208196
return dest;
209197
}
210198
else if(src.type()==java_byte_type())

0 commit comments

Comments
 (0)