X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/f59164e3d128c7675a4d3934206346a3384e53a5..f3c0d7a59d99c2a94c6b8822291f0e42be3773c9:/icuSources/common/cstr.cpp diff --git a/icuSources/common/cstr.cpp b/icuSources/common/cstr.cpp index c3071936..24654f8f 100644 --- a/icuSources/common/cstr.cpp +++ b/icuSources/common/cstr.cpp @@ -1,3 +1,5 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html /* ******************************************************************************* * Copyright (C) 2015-2016, International Business Machines @@ -6,22 +8,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