]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/cstr.cpp
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
5 * Copyright (C) 2015-2016, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
8 * file name: charstr.cpp
10 #include "unicode/utypes.h"
11 #include "unicode/putil.h"
12 #include "unicode/unistr.h"
21 CStr::CStr(const UnicodeString
&in
) {
22 UErrorCode status
= U_ZERO_ERROR
;
23 #if !UCONFIG_NO_CONVERSION || U_CHARSET_IS_UTF8
24 int32_t length
= in
.extract(0, in
.length(), static_cast<char *>(NULL
), static_cast<uint32_t>(0));
25 int32_t resultCapacity
= 0;
26 char *buf
= s
.getAppendBuffer(length
, length
, resultCapacity
, status
);
27 if (U_SUCCESS(status
)) {
28 in
.extract(0, in
.length(), buf
, resultCapacity
);
29 s
.append(buf
, length
, status
);
32 // No conversion available. Convert any invariant characters; substitute '?' for the rest.
33 // Note: can't just call u_UCharsToChars() or CharString.appendInvariantChars() on the
34 // whole string because they require that the entire input be invariant.
36 for (int i
=0; i
<in
.length(); i
= in
.moveIndex32(i
, 1)) {
37 if (uprv_isInvariantUString(in
.getBuffer()+i
, 1)) {
38 u_UCharsToChars(in
.getBuffer()+i
, buf
, 1);
42 s
.append(buf
, 1, status
);
50 const char * CStr::operator ()() const {