1*b1cdbd2cSJim Jagielski /**************************************************************
2*b1cdbd2cSJim Jagielski *
3*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one
4*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file
5*b1cdbd2cSJim Jagielski * distributed with this work for additional information
6*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file
7*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the
8*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance
9*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at
10*b1cdbd2cSJim Jagielski *
11*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0
12*b1cdbd2cSJim Jagielski *
13*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing,
14*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an
15*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the
17*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations
18*b1cdbd2cSJim Jagielski * under the License.
19*b1cdbd2cSJim Jagielski *
20*b1cdbd2cSJim Jagielski *************************************************************/
21*b1cdbd2cSJim Jagielski
22*b1cdbd2cSJim Jagielski
23*b1cdbd2cSJim Jagielski
24*b1cdbd2cSJim Jagielski // no include "precompiled_tools.hxx" because this is included in other cxx files.
25*b1cdbd2cSJim Jagielski
26*b1cdbd2cSJim Jagielski // =======================================================================
27*b1cdbd2cSJim Jagielski
InitStringRes(const char * pUTF8Str,sal_Int32 nLen)28*b1cdbd2cSJim Jagielski void UniString::InitStringRes( const char* pUTF8Str, sal_Int32 nLen )
29*b1cdbd2cSJim Jagielski {
30*b1cdbd2cSJim Jagielski DBG_CTOR( UniString, DbgCheckUniString );
31*b1cdbd2cSJim Jagielski OSL_ENSURE(nLen <= STRING_MAXLEN, "Overflowing UniString");
32*b1cdbd2cSJim Jagielski
33*b1cdbd2cSJim Jagielski mpData = NULL;
34*b1cdbd2cSJim Jagielski rtl_string2UString( (rtl_uString **)(&mpData),
35*b1cdbd2cSJim Jagielski pUTF8Str, nLen,
36*b1cdbd2cSJim Jagielski RTL_TEXTENCODING_UTF8,
37*b1cdbd2cSJim Jagielski RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_MAPTOPRIVATE |
38*b1cdbd2cSJim Jagielski RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_DEFAULT |
39*b1cdbd2cSJim Jagielski RTL_TEXTTOUNICODE_FLAGS_INVALID_DEFAULT );
40*b1cdbd2cSJim Jagielski }
41*b1cdbd2cSJim Jagielski
42*b1cdbd2cSJim Jagielski // =======================================================================
43*b1cdbd2cSJim Jagielski
UniString(const ByteString & rByteStr,rtl_TextEncoding eTextEncoding,sal_uInt32 nCvtFlags)44*b1cdbd2cSJim Jagielski UniString::UniString( const ByteString& rByteStr, rtl_TextEncoding eTextEncoding, sal_uInt32 nCvtFlags )
45*b1cdbd2cSJim Jagielski {
46*b1cdbd2cSJim Jagielski DBG_CTOR( UniString, DbgCheckUniString );
47*b1cdbd2cSJim Jagielski DBG_CHKOBJ( &rByteStr, ByteString, DbgCheckByteString );
48*b1cdbd2cSJim Jagielski
49*b1cdbd2cSJim Jagielski mpData = NULL;
50*b1cdbd2cSJim Jagielski rtl_string2UString( (rtl_uString **)(&mpData),
51*b1cdbd2cSJim Jagielski rByteStr.mpData->maStr, rByteStr.mpData->mnLen,
52*b1cdbd2cSJim Jagielski eTextEncoding, nCvtFlags );
53*b1cdbd2cSJim Jagielski }
54*b1cdbd2cSJim Jagielski
55*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------
56*b1cdbd2cSJim Jagielski
UniString(const ByteString & rByteStr,xub_StrLen nPos,xub_StrLen nLen,rtl_TextEncoding eTextEncoding,sal_uInt32 nCvtFlags)57*b1cdbd2cSJim Jagielski UniString::UniString( const ByteString& rByteStr, xub_StrLen nPos, xub_StrLen nLen,
58*b1cdbd2cSJim Jagielski rtl_TextEncoding eTextEncoding, sal_uInt32 nCvtFlags )
59*b1cdbd2cSJim Jagielski {
60*b1cdbd2cSJim Jagielski DBG_CTOR( UniString, DbgCheckUniString );
61*b1cdbd2cSJim Jagielski DBG_CHKOBJ( &rByteStr, ByteString, DbgCheckByteString );
62*b1cdbd2cSJim Jagielski
63*b1cdbd2cSJim Jagielski // Stringlaenge ermitteln
64*b1cdbd2cSJim Jagielski if ( nPos > rByteStr.mpData->mnLen )
65*b1cdbd2cSJim Jagielski nLen = 0;
66*b1cdbd2cSJim Jagielski else
67*b1cdbd2cSJim Jagielski {
68*b1cdbd2cSJim Jagielski // Laenge korrigieren, wenn noetig
69*b1cdbd2cSJim Jagielski sal_Int32 nMaxLen = rByteStr.mpData->mnLen-nPos;
70*b1cdbd2cSJim Jagielski if ( nLen > nMaxLen )
71*b1cdbd2cSJim Jagielski nLen = static_cast< xub_StrLen >(nMaxLen);
72*b1cdbd2cSJim Jagielski }
73*b1cdbd2cSJim Jagielski
74*b1cdbd2cSJim Jagielski mpData = NULL;
75*b1cdbd2cSJim Jagielski rtl_string2UString( (rtl_uString **)(&mpData),
76*b1cdbd2cSJim Jagielski rByteStr.mpData->maStr+nPos, nLen,
77*b1cdbd2cSJim Jagielski eTextEncoding, nCvtFlags );
78*b1cdbd2cSJim Jagielski }
79*b1cdbd2cSJim Jagielski
80*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------
81*b1cdbd2cSJim Jagielski
UniString(const char * pByteStr,rtl_TextEncoding eTextEncoding,sal_uInt32 nCvtFlags)82*b1cdbd2cSJim Jagielski UniString::UniString( const char* pByteStr,
83*b1cdbd2cSJim Jagielski rtl_TextEncoding eTextEncoding, sal_uInt32 nCvtFlags )
84*b1cdbd2cSJim Jagielski {
85*b1cdbd2cSJim Jagielski DBG_CTOR( UniString, DbgCheckUniString );
86*b1cdbd2cSJim Jagielski DBG_ASSERT( pByteStr, "UniString::UniString() - pByteStr is NULL" );
87*b1cdbd2cSJim Jagielski
88*b1cdbd2cSJim Jagielski mpData = NULL;
89*b1cdbd2cSJim Jagielski rtl_string2UString( (rtl_uString **)(&mpData),
90*b1cdbd2cSJim Jagielski pByteStr, ImplStringLen( pByteStr ),
91*b1cdbd2cSJim Jagielski eTextEncoding, nCvtFlags );
92*b1cdbd2cSJim Jagielski }
93*b1cdbd2cSJim Jagielski
94*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------
95*b1cdbd2cSJim Jagielski
UniString(const char * pByteStr,xub_StrLen nLen,rtl_TextEncoding eTextEncoding,sal_uInt32 nCvtFlags)96*b1cdbd2cSJim Jagielski UniString::UniString( const char* pByteStr, xub_StrLen nLen,
97*b1cdbd2cSJim Jagielski rtl_TextEncoding eTextEncoding, sal_uInt32 nCvtFlags )
98*b1cdbd2cSJim Jagielski {
99*b1cdbd2cSJim Jagielski DBG_CTOR( UniString, DbgCheckUniString );
100*b1cdbd2cSJim Jagielski DBG_ASSERT( pByteStr, "UniString::UniString() - pByteStr is NULL" );
101*b1cdbd2cSJim Jagielski
102*b1cdbd2cSJim Jagielski if ( nLen == STRING_LEN )
103*b1cdbd2cSJim Jagielski nLen = ImplStringLen( pByteStr );
104*b1cdbd2cSJim Jagielski
105*b1cdbd2cSJim Jagielski mpData = NULL;
106*b1cdbd2cSJim Jagielski rtl_string2UString( (rtl_uString **)(&mpData),
107*b1cdbd2cSJim Jagielski pByteStr, nLen,
108*b1cdbd2cSJim Jagielski eTextEncoding, nCvtFlags );
109*b1cdbd2cSJim Jagielski }
110*b1cdbd2cSJim Jagielski
111*b1cdbd2cSJim Jagielski // =======================================================================
112*b1cdbd2cSJim Jagielski
UniString(const rtl::OUString & rStr)113*b1cdbd2cSJim Jagielski UniString::UniString( const rtl::OUString& rStr )
114*b1cdbd2cSJim Jagielski : mpData(NULL)
115*b1cdbd2cSJim Jagielski {
116*b1cdbd2cSJim Jagielski DBG_CTOR( UniString, DbgCheckUniString );
117*b1cdbd2cSJim Jagielski
118*b1cdbd2cSJim Jagielski OSL_ENSURE(rStr.pData->length < STRING_MAXLEN,
119*b1cdbd2cSJim Jagielski "Overflowing rtl::OUString -> UniString cut to zero length");
120*b1cdbd2cSJim Jagielski
121*b1cdbd2cSJim Jagielski
122*b1cdbd2cSJim Jagielski if (rStr.pData->length < STRING_MAXLEN)
123*b1cdbd2cSJim Jagielski {
124*b1cdbd2cSJim Jagielski mpData = reinterpret_cast< UniStringData * >(const_cast< rtl::OUString & >(rStr).pData);
125*b1cdbd2cSJim Jagielski STRING_ACQUIRE((STRING_TYPE *)mpData);
126*b1cdbd2cSJim Jagielski }
127*b1cdbd2cSJim Jagielski else
128*b1cdbd2cSJim Jagielski {
129*b1cdbd2cSJim Jagielski STRING_NEW((STRING_TYPE **)&mpData);
130*b1cdbd2cSJim Jagielski }
131*b1cdbd2cSJim Jagielski }
132*b1cdbd2cSJim Jagielski
133*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------
134*b1cdbd2cSJim Jagielski
Assign(const rtl::OUString & rStr)135*b1cdbd2cSJim Jagielski UniString& UniString::Assign( const rtl::OUString& rStr )
136*b1cdbd2cSJim Jagielski {
137*b1cdbd2cSJim Jagielski DBG_CHKTHIS( UniString, DbgCheckUniString );
138*b1cdbd2cSJim Jagielski
139*b1cdbd2cSJim Jagielski OSL_ENSURE(rStr.pData->length < STRING_MAXLEN,
140*b1cdbd2cSJim Jagielski "Overflowing rtl::OUString -> UniString cut to zero length");
141*b1cdbd2cSJim Jagielski
142*b1cdbd2cSJim Jagielski
143*b1cdbd2cSJim Jagielski if (rStr.pData->length < STRING_MAXLEN)
144*b1cdbd2cSJim Jagielski {
145*b1cdbd2cSJim Jagielski STRING_RELEASE((STRING_TYPE *)mpData);
146*b1cdbd2cSJim Jagielski mpData = reinterpret_cast< UniStringData * >(const_cast< rtl::OUString & >(rStr).pData);
147*b1cdbd2cSJim Jagielski STRING_ACQUIRE((STRING_TYPE *)mpData);
148*b1cdbd2cSJim Jagielski }
149*b1cdbd2cSJim Jagielski else
150*b1cdbd2cSJim Jagielski {
151*b1cdbd2cSJim Jagielski STRING_NEW((STRING_TYPE **)&mpData);
152*b1cdbd2cSJim Jagielski }
153*b1cdbd2cSJim Jagielski
154*b1cdbd2cSJim Jagielski return *this;
155*b1cdbd2cSJim Jagielski }
156*b1cdbd2cSJim Jagielski
intern() const157*b1cdbd2cSJim Jagielski UniString UniString::intern() const
158*b1cdbd2cSJim Jagielski {
159*b1cdbd2cSJim Jagielski UniString aStr;
160*b1cdbd2cSJim Jagielski
161*b1cdbd2cSJim Jagielski rtl_uString_intern( reinterpret_cast<rtl_uString **>(&aStr.mpData),
162*b1cdbd2cSJim Jagielski (rtl_uString *)(mpData) );
163*b1cdbd2cSJim Jagielski
164*b1cdbd2cSJim Jagielski return aStr;
165*b1cdbd2cSJim Jagielski }
166*b1cdbd2cSJim Jagielski
167*b1cdbd2cSJim Jagielski // =======================================================================
168*b1cdbd2cSJim Jagielski
169*b1cdbd2cSJim Jagielski #include <tools/rc.hxx>
170*b1cdbd2cSJim Jagielski #include <tools/rcid.h>
171*b1cdbd2cSJim Jagielski
UniString(const ResId & rResId)172*b1cdbd2cSJim Jagielski UniString::UniString( const ResId& rResId )
173*b1cdbd2cSJim Jagielski {
174*b1cdbd2cSJim Jagielski rResId.SetRT( RSC_STRING );
175*b1cdbd2cSJim Jagielski ResMgr* pResMgr = rResId.GetResMgr();
176*b1cdbd2cSJim Jagielski mpData = NULL;
177*b1cdbd2cSJim Jagielski if ( pResMgr && pResMgr->GetResource( rResId ) )
178*b1cdbd2cSJim Jagielski {
179*b1cdbd2cSJim Jagielski // String laden
180*b1cdbd2cSJim Jagielski RSHEADER_TYPE * pResHdr = (RSHEADER_TYPE*)pResMgr->GetClass();
181*b1cdbd2cSJim Jagielski //sal_uInt32 nLen = pResHdr->GetLocalOff() - sizeof( RSHEADER_TYPE );
182*b1cdbd2cSJim Jagielski
183*b1cdbd2cSJim Jagielski sal_Int32 nStringLen = rtl_str_getLength( (char*)(pResHdr+1) );
184*b1cdbd2cSJim Jagielski InitStringRes( (const char*)(pResHdr+1), nStringLen );
185*b1cdbd2cSJim Jagielski
186*b1cdbd2cSJim Jagielski sal_uInt32 nSize = sizeof( RSHEADER_TYPE )
187*b1cdbd2cSJim Jagielski + sal::static_int_cast< sal_uInt32 >(nStringLen) + 1;
188*b1cdbd2cSJim Jagielski nSize += nSize % 2;
189*b1cdbd2cSJim Jagielski pResMgr->Increment( nSize );
190*b1cdbd2cSJim Jagielski }
191*b1cdbd2cSJim Jagielski else
192*b1cdbd2cSJim Jagielski {
193*b1cdbd2cSJim Jagielski STRING_NEW((STRING_TYPE **)&mpData);
194*b1cdbd2cSJim Jagielski
195*b1cdbd2cSJim Jagielski #if OSL_DEBUG_LEVEL > 0
196*b1cdbd2cSJim Jagielski *this = UniString::CreateFromAscii( "<resource id " );
197*b1cdbd2cSJim Jagielski Append( UniString::CreateFromInt32( rResId.GetId() ) );
198*b1cdbd2cSJim Jagielski AppendAscii( " not found>" );
199*b1cdbd2cSJim Jagielski #endif
200*b1cdbd2cSJim Jagielski if( pResMgr )
201*b1cdbd2cSJim Jagielski pResMgr->PopContext();
202*b1cdbd2cSJim Jagielski }
203*b1cdbd2cSJim Jagielski
204*b1cdbd2cSJim Jagielski
205*b1cdbd2cSJim Jagielski ResHookProc pImplResHookProc = ResMgr::GetReadStringHook();
206*b1cdbd2cSJim Jagielski if ( pImplResHookProc )
207*b1cdbd2cSJim Jagielski pImplResHookProc( *this );
208*b1cdbd2cSJim Jagielski }
209*b1cdbd2cSJim Jagielski
210