1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others. 2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html 3*0e209d39SAndroid Build Coastguard Worker /* 4*0e209d39SAndroid Build Coastguard Worker ****************************************************************************** 5*0e209d39SAndroid Build Coastguard Worker * 6*0e209d39SAndroid Build Coastguard Worker * Copyright (C) 2016, International Business Machines 7*0e209d39SAndroid Build Coastguard Worker * Corporation and others. All Rights Reserved. 8*0e209d39SAndroid Build Coastguard Worker * 9*0e209d39SAndroid Build Coastguard Worker ****************************************************************************** 10*0e209d39SAndroid Build Coastguard Worker * 11*0e209d39SAndroid Build Coastguard Worker * File: cstr.h 12*0e209d39SAndroid Build Coastguard Worker */ 13*0e209d39SAndroid Build Coastguard Worker 14*0e209d39SAndroid Build Coastguard Worker #ifndef CSTR_H 15*0e209d39SAndroid Build Coastguard Worker #define CSTR_H 16*0e209d39SAndroid Build Coastguard Worker 17*0e209d39SAndroid Build Coastguard Worker #include "unicode/unistr.h" 18*0e209d39SAndroid Build Coastguard Worker #include "unicode/uobject.h" 19*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h" 20*0e209d39SAndroid Build Coastguard Worker 21*0e209d39SAndroid Build Coastguard Worker #include "charstr.h" 22*0e209d39SAndroid Build Coastguard Worker 23*0e209d39SAndroid Build Coastguard Worker /** 24*0e209d39SAndroid Build Coastguard Worker * ICU-internal class CStr, a small helper class to facilitate passing UnicodeStrings 25*0e209d39SAndroid Build Coastguard Worker * to functions needing (const char *) strings, such as printf(). 26*0e209d39SAndroid Build Coastguard Worker * 27*0e209d39SAndroid Build Coastguard Worker * It is intended primarily for use in debugging or in tests. Uses platform 28*0e209d39SAndroid Build Coastguard Worker * default code page conversion, which will do the best job possible, 29*0e209d39SAndroid Build Coastguard Worker * but may be lossy, depending on the platform. 30*0e209d39SAndroid Build Coastguard Worker * 31*0e209d39SAndroid Build Coastguard Worker * If no other conversion is available, use invariant conversion and substitute 32*0e209d39SAndroid Build Coastguard Worker * '?' for non-invariant characters. 33*0e209d39SAndroid Build Coastguard Worker * 34*0e209d39SAndroid Build Coastguard Worker * Example Usage: 35*0e209d39SAndroid Build Coastguard Worker * UnicodeString s = whatever; 36*0e209d39SAndroid Build Coastguard Worker * printf("%s", CStr(s)()); 37*0e209d39SAndroid Build Coastguard Worker * 38*0e209d39SAndroid Build Coastguard Worker * The explicit call to the CStr() constructor creates a temporary object. 39*0e209d39SAndroid Build Coastguard Worker * Operator () on the temporary object returns a (const char *) pointer. 40*0e209d39SAndroid Build Coastguard Worker * The lifetime of the (const char *) data is that of the temporary object, 41*0e209d39SAndroid Build Coastguard Worker * which works well when passing it as a parameter to another function, such as printf. 42*0e209d39SAndroid Build Coastguard Worker */ 43*0e209d39SAndroid Build Coastguard Worker 44*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN 45*0e209d39SAndroid Build Coastguard Worker 46*0e209d39SAndroid Build Coastguard Worker class U_COMMON_API CStr : public UMemory { 47*0e209d39SAndroid Build Coastguard Worker public: 48*0e209d39SAndroid Build Coastguard Worker CStr(const UnicodeString &in); 49*0e209d39SAndroid Build Coastguard Worker ~CStr(); 50*0e209d39SAndroid Build Coastguard Worker const char * operator ()() const; 51*0e209d39SAndroid Build Coastguard Worker 52*0e209d39SAndroid Build Coastguard Worker private: 53*0e209d39SAndroid Build Coastguard Worker CharString s; 54*0e209d39SAndroid Build Coastguard Worker CStr(const CStr &other) = delete; // Forbid copying of this class. 55*0e209d39SAndroid Build Coastguard Worker CStr &operator =(const CStr &other) = delete; // Forbid assignment. 56*0e209d39SAndroid Build Coastguard Worker }; 57*0e209d39SAndroid Build Coastguard Worker 58*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END 59*0e209d39SAndroid Build Coastguard Worker 60*0e209d39SAndroid Build Coastguard Worker #endif 61