[cfe-commits] r160890 - in /cfe/trunk: include/clang/Basic/ConvertUTF.h lib/Basic/ConvertUTF.c lib/Basic/ConvertUTFWrapper.cpp
Dmitri Gribenko
gribozavr at gmail.com
Fri Jul 27 13:36:22 PDT 2012
Author: gribozavr
Date: Fri Jul 27 15:36:22 2012
New Revision: 160890
URL: http://llvm.org/viewvc/llvm-project?rev=160890&view=rev
Log:
Add a function to convert a single Unicode code point to a UTF8 sequence.
Modified:
cfe/trunk/include/clang/Basic/ConvertUTF.h
cfe/trunk/lib/Basic/ConvertUTF.c
cfe/trunk/lib/Basic/ConvertUTFWrapper.cpp
Modified: cfe/trunk/include/clang/Basic/ConvertUTF.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/ConvertUTF.h?rev=160890&r1=160889&r2=160890&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/ConvertUTF.h (original)
+++ cfe/trunk/include/clang/Basic/ConvertUTF.h Fri Jul 27 15:36:22 2012
@@ -110,6 +110,8 @@
#define UNI_MAX_UTF32 (UTF32)0x7FFFFFFF
#define UNI_MAX_LEGAL_UTF32 (UTF32)0x0010FFFF
+#define UNI_MAX_UTF8_BYTES_PER_CODE_POINT 4
+
typedef enum {
conversionOK, /* conversion successful */
sourceExhausted, /* partial character in source, but hit end */
@@ -139,11 +141,13 @@
ConversionResult ConvertUTF16toUTF8 (
const UTF16** sourceStart, const UTF16* sourceEnd,
UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags);
+#endif
ConversionResult ConvertUTF32toUTF8 (
const UTF32** sourceStart, const UTF32* sourceEnd,
UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags);
+#ifdef CLANG_NEEDS_THESE_ONE_DAY
ConversionResult ConvertUTF16toUTF32 (
const UTF16** sourceStart, const UTF16* sourceEnd,
UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags);
@@ -177,6 +181,18 @@
bool ConvertUTF8toWide(unsigned WideCharWidth, llvm::StringRef Source,
char *&ResultPtr);
+/**
+ * Convert an Unicode code point to UTF8 sequence.
+ *
+ * \param Source a Unicode code point.
+ * \param [in,out] ResultPtr pointer to the output buffer, needs to be at least
+ * \c UNI_MAX_UTF8_BYTES_PER_CODE_POINT bytes. On success \c ResultPtr is
+ * updated one past end of the converted sequence.
+ *
+ * \returns true on success.
+ */
+bool ConvertCodePointToUTF8(unsigned Source, char *&ResultPtr);
+
}
#endif
Modified: cfe/trunk/lib/Basic/ConvertUTF.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/ConvertUTF.c?rev=160890&r1=160889&r2=160890&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/ConvertUTF.c (original)
+++ cfe/trunk/lib/Basic/ConvertUTF.c Fri Jul 27 15:36:22 2012
@@ -285,6 +285,7 @@
*targetStart = target;
return result;
}
+#endif
/* --------------------------------------------------------------------- */
@@ -339,8 +340,6 @@
return result;
}
-#endif
-
/* --------------------------------------------------------------------- */
/*
Modified: cfe/trunk/lib/Basic/ConvertUTFWrapper.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/ConvertUTFWrapper.cpp?rev=160890&r1=160889&r2=160890&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/ConvertUTFWrapper.cpp (original)
+++ cfe/trunk/lib/Basic/ConvertUTFWrapper.cpp Fri Jul 27 15:36:22 2012
@@ -51,4 +51,20 @@
return result == conversionOK;
}
+bool ConvertCodePointToUTF8(unsigned Source, char *&ResultPtr) {
+ const UTF32 *SourceStart = &Source;
+ const UTF32 *SourceEnd = SourceStart + 1;
+ UTF8 *TargetStart = reinterpret_cast<UTF8 *>(ResultPtr);
+ UTF8 *TargetEnd = TargetStart + 4;
+ ConversionResult CR = ConvertUTF32toUTF8(&SourceStart, SourceEnd,
+ &TargetStart, TargetEnd,
+ strictConversion);
+ if (CR != conversionOK)
+ return false;
+
+ ResultPtr = reinterpret_cast<char*>(TargetStart);
+ return true;
}
+
+} // end namespace clang
+
More information about the cfe-commits
mailing list