1*9ee13d13SAndrew Rist /************************************************************** 2*9ee13d13SAndrew Rist * 3*9ee13d13SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*9ee13d13SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*9ee13d13SAndrew Rist * distributed with this work for additional information 6*9ee13d13SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*9ee13d13SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*9ee13d13SAndrew Rist * "License"); you may not use this file except in compliance 9*9ee13d13SAndrew Rist * with the License. You may obtain a copy of the License at 10*9ee13d13SAndrew Rist * 11*9ee13d13SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*9ee13d13SAndrew Rist * 13*9ee13d13SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*9ee13d13SAndrew Rist * software distributed under the License is distributed on an 15*9ee13d13SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9ee13d13SAndrew Rist * KIND, either express or implied. See the License for the 17*9ee13d13SAndrew Rist * specific language governing permissions and limitations 18*9ee13d13SAndrew Rist * under the License. 19*9ee13d13SAndrew Rist * 20*9ee13d13SAndrew Rist *************************************************************/ 21*9ee13d13SAndrew Rist 22cdf0e10cSrcweir #ifndef _RPTSHARED_CONSTASCIISTRING_HXX_ 23cdf0e10cSrcweir #define _RPTSHARED_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 //------------------------------------------------------------ 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 //------------------------------------------------------------ 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 // _RPTSHARED_CONSTASCIISTRING_HXX_ 83