diff options
author | Bernard Normier <bernard@zeroc.com> | 2016-10-25 18:35:15 -0400 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2016-10-25 18:35:15 -0400 |
commit | 95624751e9d98d1265e0a007e7d7a1186036750b (patch) | |
tree | d13da90f17629496d13d5badb32b04803239d662 /cpp/src/slice2cs | |
parent | Nuget package updates (diff) | |
download | ice-95624751e9d98d1265e0a007e7d7a1186036750b.tar.bz2 ice-95624751e9d98d1265e0a007e7d7a1186036750b.tar.xz ice-95624751e9d98d1265e0a007e7d7a1186036750b.zip |
Refactored string literal generation and updated identityToString format
Diffstat (limited to 'cpp/src/slice2cs')
-rw-r--r-- | cpp/src/slice2cs/Gen.cpp | 147 |
1 files changed, 1 insertions, 146 deletions
diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp index 313c04ea229..1fe547582ab 100644 --- a/cpp/src/slice2cs/Gen.cpp +++ b/cpp/src/slice2cs/Gen.cpp @@ -10,7 +10,6 @@ #include <IceUtil/DisableWarnings.h> #include <IceUtil/Functional.h> #include <IceUtil/StringUtil.h> -#include <IceUtil/InputUtil.h> #include <IceUtil/FileUtil.h> #include <Gen.h> @@ -23,7 +22,6 @@ #include <IceUtil/Iterator.h> #include <IceUtil/UUID.h> -#include <IceUtil/StringConverter.h> #include <Slice/Checksum.h> #include <Slice/FileTracker.h> #include <Slice/Util.h> @@ -39,30 +37,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; @@ -1298,126 +1272,7 @@ Slice::CsVisitor::writeConstantValue(const TypePtr& type, const SyntaxTreeBasePt EnumPtr ep; if(bp && bp->kind() == 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 << "\""; // Opening " - - vector<unsigned char> u8buffer; // Buffer to convert multibyte characters - - for(size_t i = 0; i < value.size();) - { - if(charSet.find(value[i]) == charSet.end()) - { - if(static_cast<unsigned char>(value[i]) < 128) // Single byte character - { - // - // Print as unicode if not in basic source character set - // - _out << u16CodePoint(static_cast<unsigned int>(value[i])); - } - 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') - { - _out << s.substr(0, s.size() - 1); - i = j + 1; - - string codepoint = value.substr(j + 1, 8); - assert(codepoint.size() == 8); - - IceUtil::Int64 v = IceUtilInternal::strToInt64(codepoint.c_str(), 0, 16); - - - // - // 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. - // - 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 << "\\U" << codepoint; - } - - i = j + 1 + 8; - } - 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 << "\""; // Closing " + _out << "\"" << toStringLiteral(value, "\a\b\f\n\r\t\v\0", "", UCN, 0) << "\""; } else if(bp && bp->kind() == Builtin::KindLong) { |