summaryrefslogtreecommitdiff
path: root/cpp/src/slice2java/Gen.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/slice2java/Gen.cpp')
-rw-r--r--cpp/src/slice2java/Gen.cpp41
1 files changed, 27 insertions, 14 deletions
diff --git a/cpp/src/slice2java/Gen.cpp b/cpp/src/slice2java/Gen.cpp
index 3f2b833b817..5c0bf6b3cbf 100644
--- a/cpp/src/slice2java/Gen.cpp
+++ b/cpp/src/slice2java/Gen.cpp
@@ -1252,27 +1252,27 @@ Slice::JavaVisitor::writeConstantValue(Output& out, const TypePtr& type, const S
{
case Builtin::KindString:
{
+ //
+ // Expand strings into the basic source character set. We can't use isalpha() and the like
+ // here because they are sensitive to the current locale.
+ //
+ static const string basicSourceChars = "abcdefghijklmnopqrstuvwxyz"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "0123456789"
+ "_{}[]#()<>%:;.?*+-/^&|~!=,\\\"' ";
+ static const set<char> charSet(basicSourceChars.begin(), basicSourceChars.end());
out << "\"";
for(string::const_iterator c = value.begin(); c != value.end(); ++c)
{
- if(isascii(static_cast<unsigned char>(*c)) && isprint(static_cast<unsigned char>(*c)))
- {
- switch(*c)
- {
- case '\\':
- case '"':
- {
- out << "\\";
- break;
- }
- }
- out << *c;
- }
- else
+ if(charSet.find(*c) == charSet.end())
{
switch(*c)
{
+ //
+ // Java doesn't want '\n' or '\r\n' encoded as universal
+ // characters, that gives an error "unclosed string literal"
+ //
case '\r':
{
out << "\\r";
@@ -1297,6 +1297,19 @@ Slice::JavaVisitor::writeConstantValue(Output& out, const TypePtr& type, const S
}
}
}
+ else
+ {
+ switch(*c)
+ {
+ case '\\':
+ case '"':
+ {
+ out << "\\";
+ break;
+ }
+ }
+ out << *c;
+ }
}
out << "\"";