1 #ifndef _DBASHARED_CONSTASCIISTRING_HXX_ 2 #define _DBASHARED_CONSTASCIISTRING_HXX_ 3 4 #ifndef CONSTASCII_INCLUDED_INDIRECT 5 #error "don't include this file directly! use stringconstants.hrc instead!" 6 #endif 7 8 // no namespaces. This file is included from several other files _within_ a namespace. 9 10 //============================================================ 11 //= a helper for static ascii pseudo-unicode strings 12 //============================================================ 13 // string constants 14 struct ConstAsciiString 15 { 16 const sal_Char* ascii; 17 sal_Int32 length; 18 19 inline operator const ::rtl::OUString& () const; 20 inline operator const sal_Char* () const { return ascii; } 21 22 inline ConstAsciiString(const sal_Char* _pAsciiZeroTerminated, const sal_Int32 _nLength); 23 inline ~ConstAsciiString(); 24 25 private: 26 mutable ::rtl::OUString* ustring; 27 }; 28 29 //------------------------------------------------------------ 30 inline ConstAsciiString::ConstAsciiString(const sal_Char* _pAsciiZeroTerminated, const sal_Int32 _nLength) 31 :ascii(_pAsciiZeroTerminated) 32 ,length(_nLength) 33 ,ustring(NULL) 34 { 35 } 36 37 //------------------------------------------------------------ 38 inline ConstAsciiString::~ConstAsciiString() 39 { 40 delete ustring; 41 ustring = NULL; 42 } 43 44 //------------------------------------------------------------ 45 inline ConstAsciiString::operator const ::rtl::OUString& () const 46 { 47 if (!ustring) 48 ustring = new ::rtl::OUString(ascii, length, RTL_TEXTENCODING_ASCII_US); 49 return *ustring; 50 } 51 52 //============================================================ 53 54 #define DECLARE_CONSTASCII_USTRING( name ) \ 55 extern const ConstAsciiString name 56 57 #define IMPLEMENT_CONSTASCII_USTRING( name, string ) \ 58 const ConstAsciiString name(string, sizeof(string)-1) 59 60 61 #endif // _DBASHARED_CONSTASCIISTRING_HXX_ 62