]> git.saurik.com Git - apple/icu.git/blame - icuSources/common/cstr.h
ICU-57163.0.1.tar.gz
[apple/icu.git] / icuSources / common / cstr.h
CommitLineData
2ca993e8
A
1/*
2******************************************************************************
3*
4* Copyright (C) 2015, International Business Machines
5* Corporation and others. All Rights Reserved.
6*
7******************************************************************************
8*
9* File: cstr.h
10*/
11
12#ifndef CSTR_H
13#define CSTR_H
14
15#include "unicode/unistr.h"
16#include "unicode/uobject.h"
17#include "unicode/utypes.h"
18
19#include "charstr.h"
20
21/**
22 * ICU-internal class CStr, a small helper class to facilitate passing UnicodStrings
23 * to functions needing (const char *) strings, such as printf().
24 *
25 * It is intended primarily for use in debugging or in tests. Uses platform
26 * default code page conversion, which will do the best job possible,
27 * but may be lossy, depending on the platform.
28 *
29 * Example Usage:
30 * UnicodeString s = whatever;
31 * printf("%s", CStr(s)());
32 *
33 * The explicit call to the CStr() constructor creates a temporary object.
34 * Operator () on the temporary object returns a (const char *) pointer.
35 * The lifetime of the (const char *) data is that of the temporary object,
36 * which works well when passing it as a parameter to another function, such as printf.
37 */
38
39U_NAMESPACE_BEGIN
40
41class U_COMMON_API CStr : public UMemory {
42 public:
43 CStr(const UnicodeString &in);
44 ~CStr();
45 const char * operator ()() const;
46
47 private:
48 CharString s;
49 CStr(const CStr &other); // Forbid copying of this class.
50 CStr &operator =(const CStr &other); // Forbid assignment.
51};
52
53U_NAMESPACE_END
54
55#endif