summaryrefslogtreecommitdiff
path: root/cpp/src/slice2java/Gen.cpp
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2016-10-25 18:35:15 -0400
committerBernard Normier <bernard@zeroc.com>2016-10-25 18:35:15 -0400
commit95624751e9d98d1265e0a007e7d7a1186036750b (patch)
treed13da90f17629496d13d5badb32b04803239d662 /cpp/src/slice2java/Gen.cpp
parentNuget package updates (diff)
downloadice-95624751e9d98d1265e0a007e7d7a1186036750b.tar.bz2
ice-95624751e9d98d1265e0a007e7d7a1186036750b.tar.xz
ice-95624751e9d98d1265e0a007e7d7a1186036750b.zip
Refactored string literal generation and updated identityToString format
Diffstat (limited to 'cpp/src/slice2java/Gen.cpp')
-rw-r--r--cpp/src/slice2java/Gen.cpp187
1 files changed, 1 insertions, 186 deletions
diff --git a/cpp/src/slice2java/Gen.cpp b/cpp/src/slice2java/Gen.cpp
index c767febeb3a..8c3769c0fb6 100644
--- a/cpp/src/slice2java/Gen.cpp
+++ b/cpp/src/slice2java/Gen.cpp
@@ -14,7 +14,6 @@
#include <IceUtil/Iterator.h>
#include <IceUtil/StringUtil.h>
#include <IceUtil/InputUtil.h>
-#include <IceUtil/StringConverter.h>
#include <cstring>
#include <limits>
@@ -28,29 +27,6 @@ namespace
{
string
-u16CodePoint(unsigned short value)
-{
- ostringstream s;
- s << "\\u";
- s << hex;
- s.width(4);
- s.fill('0');
- s << value;
- return s.str();
-}
-
-void
-writeU8Buffer(const vector<unsigned char>& u8buffer, ::IceUtilInternal::Output& out)
-{
- vector<unsigned short> u16buffer = toUTF16(u8buffer);
-
- for(vector<unsigned short>::const_iterator c = u16buffer.begin(); c != u16buffer.end(); ++c)
- {
- out << u16CodePoint(*c);
- }
-}
-
-string
sliceModeToIceMode(Operation::Mode opMode)
{
string mode = "com.zeroc.Ice.OperationMode.";
@@ -1505,168 +1481,7 @@ 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 << "\"";
-
- vector<unsigned char> u8buffer; // Buffer to convert multibyte characters
-
- for(size_t i = 0; i < value.size();)
- {
- if(charSet.find(value[i]) == charSet.end())
- {
- char c = value[i];
- if(static_cast<unsigned char>(c) < 128) // Single byte character
- {
- //
- // Print as unicode if not in basic source character set
- //
- 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";
- break;
- }
- case '\n':
- {
- out << "\\n";
- break;
- }
- default:
- {
- out << u16CodePoint(c);
- break;
- }
- }
- }
- else
- {
- u8buffer.push_back(value[i]);
- }
- }
- else
- {
- //
- // Write any pedding characters in the utf8 buffer
- //
- if(!u8buffer.empty())
- {
- writeU8Buffer(u8buffer, out);
- u8buffer.clear();
- }
- switch(value[i])
- {
- case '\\':
- {
- string s = "\\";
- size_t j = i + 1;
- for(; j < value.size(); ++j)
- {
- if(value[j] != '\\')
- {
- break;
- }
- s += "\\";
- }
-
- //
- // An even number of slash \ will escape the backslash and
- // the codepoint will be interpreted as its charaters
- //
- // \\U00000041 - ['\\', 'U', '0', '0', '0', '0', '0', '0', '4', '1']
- // \\\U00000041 - ['\\', 'A'] (41 is the codepoint for 'A')
- //
- if(s.size() % 2 != 0 && (value[j] == 'U' || value[j] == 'u'))
- {
- size_t sz = value[j] == 'U' ? 8 : 4;
- out << s.substr(0, s.size() - 1);
- i = j + 1;
-
- string codepoint = value.substr(j + 1, sz);
- assert(codepoint.size() == sz);
-
- IceUtil::Int64 v = IceUtilInternal::strToInt64(codepoint.c_str(), 0, 16);
-
-
- //
- // Java doesn't like this special characters encoded as universal characters
- //
- if(v == 0x5c)
- {
- out << "\\\\";
- }
- else if(v == 0xa)
- {
- out << "\\n";
- }
- else if(v == 0xd)
- {
- out << "\\r";
- }
- else if(v == 0x22)
- {
- out << "\\\"";
- }
- //
- // Unicode character in the range U+10000 to U+10FFFF is not permitted in a
- // character literal and is represented using a Unicode surrogate pair.
- //
- else if(v > 0xFFFF)
- {
- unsigned int high =
- ((static_cast<unsigned int>(v) - 0x10000) / 0x400) + 0xD800;
- unsigned int low =
- ((static_cast<unsigned int>(v) - 0x10000) % 0x400) + 0xDC00;
- out << u16CodePoint(high);
- out << u16CodePoint(low);
- }
- else
- {
- out << u16CodePoint(static_cast<unsigned int>(v));
- }
-
- i = j + 1 + sz;
- }
- else
- {
- out << s;
- i = j;
- }
- continue;
- }
- case '"':
- {
- out << "\\";
- break;
- }
- }
- out << value[i]; // Print normally if in basic source character set
- }
- i++;
- }
-
- //
- // Write any pedding characters in the utf8 buffer
- //
- if(!u8buffer.empty())
- {
- writeU8Buffer(u8buffer, out);
- u8buffer.clear();
- }
-
- out << "\"";
+ out << "\"" << toStringLiteral(value, "\b\f\n\r\t", "", ShortUCN, 0) << "\"";
break;
}
case Builtin::KindByte: