1*46dbaceeSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*46dbaceeSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*46dbaceeSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*46dbaceeSAndrew Rist  * distributed with this work for additional information
6*46dbaceeSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*46dbaceeSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*46dbaceeSAndrew Rist  * "License"); you may not use this file except in compliance
9*46dbaceeSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*46dbaceeSAndrew Rist  *
11*46dbaceeSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*46dbaceeSAndrew Rist  *
13*46dbaceeSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*46dbaceeSAndrew Rist  * software distributed under the License is distributed on an
15*46dbaceeSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*46dbaceeSAndrew Rist  * KIND, either express or implied.  See the License for the
17*46dbaceeSAndrew Rist  * specific language governing permissions and limitations
18*46dbaceeSAndrew Rist  * under the License.
19*46dbaceeSAndrew Rist  *
20*46dbaceeSAndrew Rist  *************************************************************/
21*46dbaceeSAndrew Rist 
22*46dbaceeSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _EXTENSIONS_FORMSCTRLR_STRINGDEFINE_HXX_
25cdf0e10cSrcweir #define _EXTENSIONS_FORMSCTRLR_STRINGDEFINE_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <rtl/ustring.hxx>
28cdf0e10cSrcweir #include <tools/string.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir //............................................................................
31cdf0e10cSrcweir namespace pcr
32cdf0e10cSrcweir {
33cdf0e10cSrcweir //............................................................................
34cdf0e10cSrcweir 
35cdf0e10cSrcweir 	//============================================================
36cdf0e10cSrcweir 	//= a helper for static ascii pseudo-unicode strings
37cdf0e10cSrcweir 	//============================================================
38cdf0e10cSrcweir 	struct ConstAsciiString
39cdf0e10cSrcweir 	{
40cdf0e10cSrcweir 		const sal_Char*	ascii;
41cdf0e10cSrcweir 		sal_Int32		length;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir 		inline	operator const ::rtl::OUString& () const;
44cdf0e10cSrcweir 		inline	operator const sal_Char* () const { return ascii; }
45cdf0e10cSrcweir 
46cdf0e10cSrcweir 		inline ConstAsciiString(const sal_Char* _pAsciiZeroTerminated, const sal_Int32 _nLength);
47cdf0e10cSrcweir 		inline ~ConstAsciiString();
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 	private:
50cdf0e10cSrcweir 		mutable ::rtl::OUString*	ustring;
51cdf0e10cSrcweir 	};
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 	//------------------------------------------------------------
ConstAsciiString(const sal_Char * _pAsciiZeroTerminated,const sal_Int32 _nLength)54cdf0e10cSrcweir 	inline ConstAsciiString::ConstAsciiString(const sal_Char* _pAsciiZeroTerminated, const sal_Int32 _nLength)
55cdf0e10cSrcweir 		:ascii(_pAsciiZeroTerminated)
56cdf0e10cSrcweir 		,length(_nLength)
57cdf0e10cSrcweir 		,ustring(NULL)
58cdf0e10cSrcweir 	{
59cdf0e10cSrcweir 	}
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 	//------------------------------------------------------------
~ConstAsciiString()62cdf0e10cSrcweir 	inline ConstAsciiString::~ConstAsciiString()
63cdf0e10cSrcweir 	{
64cdf0e10cSrcweir 		delete ustring;
65cdf0e10cSrcweir 		ustring = NULL;
66cdf0e10cSrcweir 	}
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 	//------------------------------------------------------------
69cdf0e10cSrcweir 	inline ConstAsciiString::operator const ::rtl::OUString& () const
70cdf0e10cSrcweir 	{
71cdf0e10cSrcweir 		if (!ustring)
72cdf0e10cSrcweir 			ustring = new ::rtl::OUString(ascii, length, RTL_TEXTENCODING_ASCII_US);
73cdf0e10cSrcweir 		return *ustring;
74cdf0e10cSrcweir 	}
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 	//============================================================
77cdf0e10cSrcweir 
78cdf0e10cSrcweir #define CONST_ASCII_LENGTH(c)	\
79cdf0e10cSrcweir 	(const sal_Char*)c, c.length()
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 	//============================================================
82cdf0e10cSrcweir 	//= concrete strings
83cdf0e10cSrcweir 	//============================================================
84cdf0e10cSrcweir 	#ifndef PCR_IMPLEMENT_STRINGS
85cdf0e10cSrcweir 	#define PCR_CONSTASCII_STRING(ident, string) extern const ConstAsciiString ident
86cdf0e10cSrcweir 	#else
87cdf0e10cSrcweir 	#define PCR_CONSTASCII_STRING(ident, string) extern const ConstAsciiString ident(string, sizeof(string)-1)
88cdf0e10cSrcweir 	#endif
89cdf0e10cSrcweir 
90cdf0e10cSrcweir //............................................................................
91cdf0e10cSrcweir } // namespace pcr
92cdf0e10cSrcweir //............................................................................
93cdf0e10cSrcweir 
94cdf0e10cSrcweir #endif // _EXTENSIONS_FORMSCTRLR_STRINGDEFINE_HXX_
95cdf0e10cSrcweir 
96