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