From: Andy Heninger Date: Mon, 16 May 2016 23:58:50 +0000 (+0000) Subject: ICU-12451 CStr class, fix UCONFIG_NO_CONVERSION conditionals, add invariant conversio... X-Git-Tag: milestone-59-0-1~430 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3f14902d295a1e7b3669f5d50380de8bad489ec4;p=icu ICU-12451 CStr class, fix UCONFIG_NO_CONVERSION conditionals, add invariant conversion for use when no other is available. X-SVN-Rev: 38748 --- diff --git a/icu4c/source/common/cstr.cpp b/icu4c/source/common/cstr.cpp index c30719361ea..da5b1e5de26 100644 --- a/icu4c/source/common/cstr.cpp +++ b/icu4c/source/common/cstr.cpp @@ -6,22 +6,40 @@ * file name: charstr.cpp */ #include "unicode/utypes.h" +#include "unicode/putil.h" #include "unicode/unistr.h" -#include "charstr.h" #include "cstr.h" +#include "charstr.h" +#include "uinvchar.h" + U_NAMESPACE_BEGIN CStr::CStr(const UnicodeString &in) { UErrorCode status = U_ZERO_ERROR; - int32_t length = in.extract(0, in.length(), NULL, (uint32_t)0); +#if !UCONFIG_NO_CONVERSION || U_CHARSET_IS_UTF8 + int32_t length = in.extract(0, in.length(), static_cast(NULL), static_cast(0)); int32_t resultCapacity = 0; char *buf = s.getAppendBuffer(length, length, resultCapacity, status); if (U_SUCCESS(status)) { in.extract(0, in.length(), buf, resultCapacity); s.append(buf, length, status); } +#else + // No conversion available. Convert any invariant characters; substitute '?' for the rest. + // Note: can't just call u_UCharsToChars() or CharString.appendInvariantChars() on the + // whole string because they require that the entire input be invariant. + char buf[2]; + for (int i=0; i