]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/charstr.h
2 **********************************************************************
3 * Copyright (c) 2001, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
6 * Date Name Description
7 * 11/19/2001 aliu Creation.
8 **********************************************************************
11 #include "unicode/utypes.h"
12 #include "unicode/uobject.h"
13 #include "unicode/unistr.h"
16 //--------------------------------------------------------------------
19 // This is a tiny wrapper class that is used internally to make a
20 // UnicodeString look like a const char*. It can be allocated on the
21 // stack. It only creates a heap buffer if it needs to.
22 //--------------------------------------------------------------------
26 class U_COMMON_API CharString
: public UMemory
{
28 inline CharString(const UnicodeString
& str
);
30 inline operator const char*() const { return ptr
; }
36 CharString(const CharString
&other
); // forbid copying of this class
37 CharString
&operator=(const CharString
&other
); // forbid copying of this class
40 inline CharString::CharString(const UnicodeString
& str
) {
41 // Invariant converter should create str.length() chars
42 if (str
.length() >= (int32_t)sizeof(buf
)) {
43 ptr
= (char *)uprv_malloc(str
.length() + 8);
47 str
.extract(0, 0x7FFFFFFF, ptr
, "");
50 inline CharString::~CharString() {