diff options
author | Jose <jose@zeroc.com> | 2011-04-13 13:12:11 +0200 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2011-04-13 13:12:11 +0200 |
commit | ff77cd1e6d0d3c972db43e3f4064937e251dbe13 (patch) | |
tree | 79e6a0db64ef51070e053d28a74b05aca602f485 /cpp/src/slice2java/Gen.cpp | |
parent | 5009 - appName incosistence (diff) | |
download | ice-ff77cd1e6d0d3c972db43e3f4064937e251dbe13.tar.bz2 ice-ff77cd1e6d0d3c972db43e3f4064937e251dbe13.tar.xz ice-ff77cd1e6d0d3c972db43e3f4064937e251dbe13.zip |
4851 - slice2cpp bug for string literals
Diffstat (limited to 'cpp/src/slice2java/Gen.cpp')
-rw-r--r-- | cpp/src/slice2java/Gen.cpp | 41 |
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 << "\""; |