summaryrefslogtreecommitdiff
path: root/cpp/src/slice2cpp/Gen.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/slice2cpp/Gen.cpp')
-rw-r--r--cpp/src/slice2cpp/Gen.cpp255
1 files changed, 2 insertions, 253 deletions
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index 582f6edf732..978ab8114f2 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -13,8 +13,6 @@
#include <Slice/CPlusPlusUtil.h>
#include <IceUtil/Functional.h>
#include <IceUtil/Iterator.h>
-#include <IceUtil/InputUtil.h>
-#include <IceUtil/StringConverter.h>
#include <IceUtil/StringUtil.h>
#include <Slice/Checksum.h>
#include <Slice/FileTracker.h>
@@ -81,64 +79,6 @@ isConstexprType(const TypePtr& type)
}
}
-string
-u32CodePoint(unsigned int value, bool cpp11)
-{
- ostringstream s;
- //
- // COMPILERFIX:
- // With VC++ < 140 characters in the range of 0 to 0x9f cannot be represented
- // with a universal character name (UCN).
- //
- if(!cpp11 && value <= 0x9f)
- {
- switch(value)
- {
- case 0x22:
- {
- s << "\\\"";
- break;
- }
- case 0x5c:
- {
- s << "\\\\";
- break;
- }
- default:
- {
- s << "\\";
- s << oct;
- s.width(3);
- s.fill('0');
- s << value;
- break;
- }
- }
- }
- //
- // UCN valid characters
- //
- else
- {
- s << "\\U";
- s << hex;
- s.width(8);
- s.fill('0');
- s << value;
- }
- return s.str();
-}
-
-void
-writeU8Buffer(const vector<unsigned char>& u8buffer, ::IceUtilInternal::Output& out, bool cpp11)
-{
- vector<unsigned int> u32buffer = toUTF32(u8buffer);
-
- for(vector<unsigned int>::const_iterator c = u32buffer.begin(); c != u32buffer.end(); ++c)
- {
- out << u32CodePoint(*c, cpp11);
- }
-}
string
getDeprecateSymbol(const ContainedPtr& p1, const ContainedPtr& p2)
@@ -171,207 +111,16 @@ writeConstantValue(IceUtilInternal::Output& out, const TypePtr& type, const Synt
BuiltinPtr bp = BuiltinPtr::dynamicCast(type);
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());
bool wide = (useWstring & TypeContextUseWstring) || findMetaData(metaData) == "wstring";
if(wide || cpp11)
{
- //
- // Wide strings or C++11 narrow string
- //
- vector<unsigned char> u8buffer; // Buffer to convert multibyte characters
out << (wide ? "L\"" : "u8\"");
- 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
- {
- out << u32CodePoint(static_cast<unsigned char>(value[i]), cpp11);
- }
- else
- {
- u8buffer.push_back(value[i]);
- }
- }
- else
- {
- //
- // Write any padding characters in the utf8 buffer
- //
- if(!u8buffer.empty())
- {
- writeU8Buffer(u8buffer, out, cpp11);
- 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 characters
- //
- // \\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'))
- {
- //
- // Convert codepoint to UTF8 bytes and write the escaped bytes
- //
- out << s.substr(0, s.size() - 1);
-
- size_t sz = value[j] == 'U' ? 8 : 4;
- string codepoint = value.substr(j + 1, sz);
- assert(codepoint.size() == sz);
-
- IceUtil::Int64 v = IceUtilInternal::strToInt64(codepoint.c_str(), 0, 16);
- out << u32CodePoint(static_cast<unsigned int>(v), cpp11);
-
- 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 padding characters in the utf8 buffer
- //
- if(!u8buffer.empty())
- {
- writeU8Buffer(u8buffer, out, cpp11);
- u8buffer.clear();
- }
+ out << toStringLiteral(value, "\a\b\f\n\r\t\v", "?", UCN, cpp11 ? 0 : 0x9F + 1);
out << "\"";
}
else // C++98 narrow strings
{
- out << "\""; // Opening "
-
- for(size_t i = 0; i < value.size();)
- {
- if(charSet.find(value[i]) == charSet.end())
- {
- unsigned char uc = value[i]; // char may be signed, so make it positive
- ostringstream s;
- s << "\\"; // Print as octal if not in basic source character set
- s.width(3);
- s.fill('0');
- s << oct;
- s << static_cast<unsigned>(uc);
- out << s.str();
- }
- else
- {
- 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'))
- {
- //
- // Convert codepoint to UTF8 bytes and write the escaped bytes
- //
- out << s.substr(0, s.size() - 1);
-
- size_t sz = value[j] == 'U' ? 8 : 4;
- string codepoint = value.substr(j + 1, sz);
- assert(codepoint.size() == sz);
-
- IceUtil::Int64 v = IceUtilInternal::strToInt64(codepoint.c_str(), 0, 16);
-
-
- vector<unsigned int> u32buffer;
- u32buffer.push_back(static_cast<unsigned int>(v));
-
- vector<unsigned char> u8buffer = fromUTF32(u32buffer);
-
- ostringstream s;
- for(vector<unsigned char>::const_iterator q = u8buffer.begin(); q != u8buffer.end(); ++q)
- {
- s << "\\";
- s.fill('0');
- s.width(3);
- s << oct;
- s << static_cast<unsigned int>(*q);
- }
- out << s.str();
-
- 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;
- }
- out << "\""; // Closing "
+ out << "\"" << toStringLiteral(value, "\a\b\f\n\r\t\v", "?", Octal, 0) << "\"";
}
}
else if(bp && bp->kind() == Builtin::KindLong)