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