]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/cstr.h
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 ******************************************************************************
6 * Copyright (C) 2016, International Business Machines
7 * Corporation and others. All Rights Reserved.
9 ******************************************************************************
17 #include "unicode/unistr.h"
18 #include "unicode/uobject.h"
19 #include "unicode/utypes.h"
24 * ICU-internal class CStr, a small helper class to facilitate passing UnicodeStrings
25 * to functions needing (const char *) strings, such as printf().
27 * It is intended primarily for use in debugging or in tests. Uses platform
28 * default code page conversion, which will do the best job possible,
29 * but may be lossy, depending on the platform.
31 * If no other conversion is available, use invariant conversion and substitue
32 * '?' for non-invariant characters.
35 * UnicodeString s = whatever;
36 * printf("%s", CStr(s)());
38 * The explicit call to the CStr() constructor creates a temporary object.
39 * Operator () on the temporary object returns a (const char *) pointer.
40 * The lifetime of the (const char *) data is that of the temporary object,
41 * which works well when passing it as a parameter to another function, such as printf.
46 class U_COMMON_API CStr
: public UMemory
{
48 CStr(const UnicodeString
&in
);
50 const char * operator ()() const;
54 CStr(const CStr
&other
); // Forbid copying of this class.
55 CStr
&operator =(const CStr
&other
); // Forbid assignment.