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