aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGExpr.cpp
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2012-07-03 02:24:52 +0000
committerNico Weber <nicolasweber@gmx.de>2012-07-03 02:24:52 +0000
commit941e47cef26fb6300a8d3e366f7c5694277e5849 (patch)
treee945a9199490fafc296ef2fcece986ab53a6b2bd /lib/CodeGen/CGExpr.cpp
parent7c81b43bef441960e921e0eb72d249369b7dd96c (diff)
Share ConvertUTF8toWide() between Lex and CodeGen.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159634 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExpr.cpp')
-rw-r--r--lib/CodeGen/CGExpr.cpp39
1 files changed, 2 insertions, 37 deletions
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index 5f708d7a73..7fbe0d02b5 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -1732,47 +1732,12 @@ GetAddrOfConstantWideString(StringRef Str,
return GV;
}
-// FIXME: Mostly copied from StringLiteralParser::CopyStringFragment
static void ConvertUTF8ToWideString(unsigned CharByteWidth, StringRef Source,
SmallString<32>& Target) {
Target.resize(CharByteWidth * (Source.size() + 1));
char* ResultPtr = &Target[0];
-
- assert(CharByteWidth==1 || CharByteWidth==2 || CharByteWidth==4);
- ConversionResult result = conversionOK;
- // Copy the character span over.
- if (CharByteWidth == 1) {
- if (!isLegalUTF8String(reinterpret_cast<const UTF8*>(&*Source.begin()),
- reinterpret_cast<const UTF8*>(&*Source.end())))
- result = sourceIllegal;
- memcpy(ResultPtr, Source.data(), Source.size());
- ResultPtr += Source.size();
- } else if (CharByteWidth == 2) {
- UTF8 const *sourceStart = (UTF8 const *)Source.data();
- // FIXME: Make the type of the result buffer correct instead of
- // using reinterpret_cast.
- UTF16 *targetStart = reinterpret_cast<UTF16*>(ResultPtr);
- ConversionFlags flags = strictConversion;
- result = ConvertUTF8toUTF16(
- &sourceStart,sourceStart + Source.size(),
- &targetStart,targetStart + 2*Source.size(),flags);
- if (result==conversionOK)
- ResultPtr = reinterpret_cast<char*>(targetStart);
- } else if (CharByteWidth == 4) {
- UTF8 const *sourceStart = (UTF8 const *)Source.data();
- // FIXME: Make the type of the result buffer correct instead of
- // using reinterpret_cast.
- UTF32 *targetStart = reinterpret_cast<UTF32*>(ResultPtr);
- ConversionFlags flags = strictConversion;
- result = ConvertUTF8toUTF32(
- &sourceStart,sourceStart + Source.size(),
- &targetStart,targetStart + 4*Source.size(),flags);
- if (result==conversionOK)
- ResultPtr = reinterpret_cast<char*>(targetStart);
- }
- assert((result != targetExhausted)
- && "ConvertUTF8toUTFXX exhausted target buffer");
- assert(result == conversionOK);
+ bool success = ConvertUTF8toWide(CharByteWidth, Source, ResultPtr);
+ assert(success);
Target.resize(ResultPtr - &Target[0]);
}