Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / intl / icu / source / common / cstr.h
blobbe21d910bb475e5dfb71c1e67300de7a0cab4c52
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 ******************************************************************************
6 * Copyright (C) 2016, International Business Machines
7 * Corporation and others. All Rights Reserved.
9 ******************************************************************************
11 * File: cstr.h
14 #ifndef CSTR_H
15 #define CSTR_H
17 #include "unicode/unistr.h"
18 #include "unicode/uobject.h"
19 #include "unicode/utypes.h"
21 #include "charstr.h"
23 /**
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 substitute
32 * '?' for non-invariant characters.
34 * Example Usage:
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.
44 U_NAMESPACE_BEGIN
46 class U_COMMON_API CStr : public UMemory {
47 public:
48 CStr(const UnicodeString &in);
49 ~CStr();
50 const char * operator ()() const;
52 private:
53 CharString s;
54 CStr(const CStr &other) = delete; // Forbid copying of this class.
55 CStr &operator =(const CStr &other) = delete; // Forbid assignment.
58 U_NAMESPACE_END
60 #endif