diff options
Diffstat (limited to 'cpp/src/slice2java/GenCompat.cpp')
-rw-r--r-- | cpp/src/slice2java/GenCompat.cpp | 187 |
1 files changed, 2 insertions, 185 deletions
diff --git a/cpp/src/slice2java/GenCompat.cpp b/cpp/src/slice2java/GenCompat.cpp index 2fef3bf1d63..205d4093750 100644 --- a/cpp/src/slice2java/GenCompat.cpp +++ b/cpp/src/slice2java/GenCompat.cpp @@ -12,9 +12,8 @@ #include <Slice/Util.h> #include <IceUtil/Functional.h> #include <IceUtil/Iterator.h> -#include <IceUtil/StringUtil.h> #include <IceUtil/InputUtil.h> -#include <IceUtil/StringConverter.h> +#include <IceUtil/StringUtil.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; @@ -1716,166 +1692,7 @@ Slice::JavaCompatVisitor::writeConstantValue(Output& out, const TypePtr& type, c { 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: |