xref: /AOO41X/main/tools/source/string/strimp.cxx (revision 4c90b64447d8b4dd5483d1f81d91722297945f4a)
189b56da7SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
389b56da7SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
489b56da7SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
589b56da7SAndrew Rist  * distributed with this work for additional information
689b56da7SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
789b56da7SAndrew Rist  * to you under the Apache License, Version 2.0 (the
889b56da7SAndrew Rist  * "License"); you may not use this file except in compliance
989b56da7SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
1189b56da7SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
1389b56da7SAndrew Rist  * Unless required by applicable law or agreed to in writing,
1489b56da7SAndrew Rist  * software distributed under the License is distributed on an
1589b56da7SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1689b56da7SAndrew Rist  * KIND, either express or implied.  See the License for the
1789b56da7SAndrew Rist  * specific language governing permissions and limitations
1889b56da7SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
2089b56da7SAndrew Rist  *************************************************************/
2189b56da7SAndrew Rist 
2289b56da7SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // no include "precompiled_tools.hxx" because this is included in other cxx files.
25cdf0e10cSrcweir 
26cdf0e10cSrcweir // =======================================================================
27cdf0e10cSrcweir 
ImplStringCompare(const STRCODE * pStr1,const STRCODE * pStr2)28cdf0e10cSrcweir static sal_Int32 ImplStringCompare( const STRCODE* pStr1, const STRCODE* pStr2 )
29cdf0e10cSrcweir {
30cdf0e10cSrcweir 	sal_Int32 nRet;
31cdf0e10cSrcweir 	while ( ((nRet = ((sal_Int32)((STRCODEU)*pStr1))-((sal_Int32)((STRCODEU)*pStr2))) == 0) &&
32cdf0e10cSrcweir 			*pStr2 )
33cdf0e10cSrcweir 	{
34cdf0e10cSrcweir 		++pStr1,
35cdf0e10cSrcweir 		++pStr2;
36cdf0e10cSrcweir 	}
37cdf0e10cSrcweir 
38cdf0e10cSrcweir 	return nRet;
39cdf0e10cSrcweir }
40cdf0e10cSrcweir 
41cdf0e10cSrcweir // -----------------------------------------------------------------------
42cdf0e10cSrcweir 
ImplStringCompare(const STRCODE * pStr1,const STRCODE * pStr2,xub_StrLen nCount)43cdf0e10cSrcweir static sal_Int32 ImplStringCompare( const STRCODE* pStr1, const STRCODE* pStr2,
44cdf0e10cSrcweir 									xub_StrLen nCount )
45cdf0e10cSrcweir {
46cdf0e10cSrcweir 	sal_Int32 nRet = 0;
47cdf0e10cSrcweir 	while ( nCount &&
48cdf0e10cSrcweir 			((nRet = ((sal_Int32)((STRCODEU)*pStr1))-((sal_Int32)((STRCODEU)*pStr2))) == 0) &&
49cdf0e10cSrcweir 			*pStr2 )
50cdf0e10cSrcweir 	{
51cdf0e10cSrcweir 		++pStr1,
52cdf0e10cSrcweir 		++pStr2,
53cdf0e10cSrcweir 		--nCount;
54cdf0e10cSrcweir 	}
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 	return nRet;
57cdf0e10cSrcweir }
58cdf0e10cSrcweir 
59cdf0e10cSrcweir // -----------------------------------------------------------------------
60cdf0e10cSrcweir 
ImplStringCompareWithoutZero(const STRCODE * pStr1,const STRCODE * pStr2,sal_Int32 nCount)61cdf0e10cSrcweir static sal_Int32 ImplStringCompareWithoutZero( const STRCODE* pStr1, const STRCODE* pStr2,
62cdf0e10cSrcweir 											   sal_Int32 nCount )
63cdf0e10cSrcweir {
64cdf0e10cSrcweir 	sal_Int32 nRet = 0;
65cdf0e10cSrcweir 	while ( nCount &&
66cdf0e10cSrcweir 			((nRet = ((sal_Int32)((STRCODEU)*pStr1))-((sal_Int32)((STRCODEU)*pStr2))) == 0) )
67cdf0e10cSrcweir 	{
68cdf0e10cSrcweir 		++pStr1,
69cdf0e10cSrcweir 		++pStr2,
70cdf0e10cSrcweir 		--nCount;
71cdf0e10cSrcweir 	}
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 	return nRet;
74cdf0e10cSrcweir }
75cdf0e10cSrcweir 
76cdf0e10cSrcweir // -----------------------------------------------------------------------
77cdf0e10cSrcweir 
ImplStringICompare(const STRCODE * pStr1,const STRCODE * pStr2)78cdf0e10cSrcweir static sal_Int32 ImplStringICompare( const STRCODE* pStr1, const STRCODE* pStr2 )
79cdf0e10cSrcweir {
80cdf0e10cSrcweir 	sal_Int32	nRet;
81cdf0e10cSrcweir 	STRCODE 	c1;
82cdf0e10cSrcweir 	STRCODE 	c2;
83cdf0e10cSrcweir 	do
84cdf0e10cSrcweir 	{
85cdf0e10cSrcweir 		// Ist das Zeichen zwischen 'A' und 'Z' dann umwandeln
86cdf0e10cSrcweir 		c1 = *pStr1;
87cdf0e10cSrcweir 		c2 = *pStr2;
88cdf0e10cSrcweir 		if ( (c1 >= 65) && (c1 <= 90) )
89cdf0e10cSrcweir 			c1 += 32;
90cdf0e10cSrcweir 		if ( (c2 >= 65) && (c2 <= 90) )
91cdf0e10cSrcweir 			c2 += 32;
92cdf0e10cSrcweir 		nRet = ((sal_Int32)((STRCODEU)c1))-((sal_Int32)((STRCODEU)c2));
93cdf0e10cSrcweir 		if ( nRet != 0 )
94cdf0e10cSrcweir 			break;
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 		++pStr1,
97cdf0e10cSrcweir 		++pStr2;
98cdf0e10cSrcweir 	}
99cdf0e10cSrcweir 	while ( c2 );
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 	return nRet;
102cdf0e10cSrcweir }
103cdf0e10cSrcweir 
104cdf0e10cSrcweir // -----------------------------------------------------------------------
105cdf0e10cSrcweir 
ImplStringICompare(const STRCODE * pStr1,const STRCODE * pStr2,xub_StrLen nCount)106cdf0e10cSrcweir static sal_Int32 ImplStringICompare( const STRCODE* pStr1, const STRCODE* pStr2,
107cdf0e10cSrcweir 									 xub_StrLen nCount )
108cdf0e10cSrcweir {
109cdf0e10cSrcweir 	sal_Int32	nRet = 0;
110cdf0e10cSrcweir 	STRCODE 	c1;
111cdf0e10cSrcweir 	STRCODE 	c2;
112cdf0e10cSrcweir 	do
113cdf0e10cSrcweir 	{
114cdf0e10cSrcweir 		if ( !nCount )
115cdf0e10cSrcweir 			break;
116cdf0e10cSrcweir 
117cdf0e10cSrcweir 		// Ist das Zeichen zwischen 'A' und 'Z' dann umwandeln
118cdf0e10cSrcweir 		c1 = *pStr1;
119cdf0e10cSrcweir 		c2 = *pStr2;
120cdf0e10cSrcweir 		if ( (c1 >= 65) && (c1 <= 90) )
121cdf0e10cSrcweir 			c1 += 32;
122cdf0e10cSrcweir 		if ( (c2 >= 65) && (c2 <= 90) )
123cdf0e10cSrcweir 			c2 += 32;
124cdf0e10cSrcweir 		nRet = ((sal_Int32)((STRCODEU)c1))-((sal_Int32)((STRCODEU)c2));
125cdf0e10cSrcweir 		if ( nRet != 0 )
126cdf0e10cSrcweir 			break;
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 		++pStr1,
129cdf0e10cSrcweir 		++pStr2,
130cdf0e10cSrcweir 		--nCount;
131cdf0e10cSrcweir 	}
132cdf0e10cSrcweir 	while ( c2 );
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 	return nRet;
135cdf0e10cSrcweir }
136cdf0e10cSrcweir 
137cdf0e10cSrcweir // -----------------------------------------------------------------------
138cdf0e10cSrcweir 
ImplStringICompareWithoutZero(const STRCODE * pStr1,const STRCODE * pStr2,sal_Int32 nCount)139cdf0e10cSrcweir static sal_Int32 ImplStringICompareWithoutZero( const STRCODE* pStr1, const STRCODE* pStr2,
140cdf0e10cSrcweir 												sal_Int32 nCount )
141cdf0e10cSrcweir {
142cdf0e10cSrcweir 	sal_Int32	nRet = 0;
143cdf0e10cSrcweir 	STRCODE 	c1;
144cdf0e10cSrcweir 	STRCODE 	c2;
145cdf0e10cSrcweir 	do
146cdf0e10cSrcweir 	{
147cdf0e10cSrcweir 		if ( !nCount )
148cdf0e10cSrcweir 			break;
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 		// Ist das Zeichen zwischen 'A' und 'Z' dann umwandeln
151cdf0e10cSrcweir 		c1 = *pStr1;
152cdf0e10cSrcweir 		c2 = *pStr2;
153cdf0e10cSrcweir 		if ( (c1 >= 65) && (c1 <= 90) )
154cdf0e10cSrcweir 			c1 += 32;
155cdf0e10cSrcweir 		if ( (c2 >= 65) && (c2 <= 90) )
156cdf0e10cSrcweir 			c2 += 32;
157cdf0e10cSrcweir 		nRet = ((sal_Int32)((STRCODEU)c1))-((sal_Int32)((STRCODEU)c2));
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 		++pStr1,
160cdf0e10cSrcweir 		++pStr2,
161cdf0e10cSrcweir 		--nCount;
162cdf0e10cSrcweir 	}
163cdf0e10cSrcweir 	while ( nRet == 0 );
164cdf0e10cSrcweir 
165cdf0e10cSrcweir 	return nRet;
166cdf0e10cSrcweir }
167cdf0e10cSrcweir 
168cdf0e10cSrcweir // =======================================================================
169cdf0e10cSrcweir 
170cdf0e10cSrcweir #ifdef DBG_UTIL
DBGCHECKSTRING(const void * pString)171cdf0e10cSrcweir const char* DBGCHECKSTRING( const void* pString )
172cdf0e10cSrcweir {
173cdf0e10cSrcweir 	STRING* p = (STRING*)pString;
174cdf0e10cSrcweir 
175cdf0e10cSrcweir 	if ( p->GetBuffer()[p->Len()] != 0 )
176cdf0e10cSrcweir 		return "String damaged: aStr[nLen] != 0";
177cdf0e10cSrcweir 
178cdf0e10cSrcweir 	return NULL;
179cdf0e10cSrcweir }
180cdf0e10cSrcweir #endif
181cdf0e10cSrcweir 
182cdf0e10cSrcweir // =======================================================================
183cdf0e10cSrcweir 
ImplAllocData(sal_Int32 nLen)184cdf0e10cSrcweir static STRINGDATA* ImplAllocData( sal_Int32 nLen )
185cdf0e10cSrcweir {
186cdf0e10cSrcweir 	// Dann kopiere die Daten
187cdf0e10cSrcweir 	STRINGDATA* pData	= (STRINGDATA*)rtl_allocateMemory( sizeof(STRINGDATA)+(nLen*sizeof( STRCODE )) );
188cdf0e10cSrcweir 	pData->mnRefCount	= 1;
189cdf0e10cSrcweir 	pData->mnLen		= nLen;
190cdf0e10cSrcweir 	pData->maStr[nLen]	= 0;
191cdf0e10cSrcweir 	return pData;
192cdf0e10cSrcweir }
193cdf0e10cSrcweir 
194cdf0e10cSrcweir // -----------------------------------------------------------------------
195cdf0e10cSrcweir 
_ImplCopyData(STRINGDATA * pData)196cdf0e10cSrcweir static STRINGDATA* _ImplCopyData( STRINGDATA* pData )
197cdf0e10cSrcweir {
198cdf0e10cSrcweir 	unsigned int	nSize		= sizeof(STRINGDATA)+(pData->mnLen*sizeof( STRCODE ));
199cdf0e10cSrcweir 	STRINGDATA* 	pNewData	= (STRINGDATA*)rtl_allocateMemory( nSize );
200cdf0e10cSrcweir 	memcpy( pNewData, pData, nSize );
201cdf0e10cSrcweir 	pNewData->mnRefCount = 1;
202cdf0e10cSrcweir 	STRING_RELEASE((STRING_TYPE *)pData);
203cdf0e10cSrcweir 	return pNewData;
204cdf0e10cSrcweir }
205cdf0e10cSrcweir 
206cdf0e10cSrcweir // -----------------------------------------------------------------------
207cdf0e10cSrcweir 
ImplCopyData()208cdf0e10cSrcweir inline void STRING::ImplCopyData()
209cdf0e10cSrcweir {
210cdf0e10cSrcweir 	DBG_ASSERT( (mpData->mnRefCount != 0), "String::ImplCopyData() - RefCount == 0" );
211cdf0e10cSrcweir 
212cdf0e10cSrcweir 	// ist es ein referenzierter String, dann die Daten abkoppeln
213cdf0e10cSrcweir 	if ( mpData->mnRefCount != 1 )
214cdf0e10cSrcweir 		mpData = _ImplCopyData( mpData );
215cdf0e10cSrcweir }
216cdf0e10cSrcweir 
217cdf0e10cSrcweir // -----------------------------------------------------------------------
218cdf0e10cSrcweir 
ImplCopyStringData(STRCODE * pStr)219cdf0e10cSrcweir inline STRCODE* STRING::ImplCopyStringData( STRCODE* pStr )
220cdf0e10cSrcweir {
221cdf0e10cSrcweir 	// Ist der Referenzzaehler groesser 0
222cdf0e10cSrcweir 	if ( mpData->mnRefCount != 1 ) {
223cdf0e10cSrcweir         DBG_ASSERT( (pStr >= mpData->maStr) &&
224cdf0e10cSrcweir                     ((pStr-mpData->maStr) < mpData->mnLen),
225cdf0e10cSrcweir                     "ImplCopyStringData - pStr from other String-Instanz" );
226cdf0e10cSrcweir         unsigned int nIndex = (unsigned int)(pStr-mpData->maStr);
227cdf0e10cSrcweir         mpData = _ImplCopyData( mpData );
228cdf0e10cSrcweir         pStr = mpData->maStr + nIndex;
229cdf0e10cSrcweir     }
230cdf0e10cSrcweir 	return pStr;
231cdf0e10cSrcweir }
232cdf0e10cSrcweir 
233cdf0e10cSrcweir // -----------------------------------------------------------------------
234cdf0e10cSrcweir 
ImplGetCopyLen(sal_Int32 nStrLen,sal_Int32 nCopyLen)235cdf0e10cSrcweir inline sal_Int32 ImplGetCopyLen( sal_Int32 nStrLen, sal_Int32 nCopyLen )
236cdf0e10cSrcweir {
237cdf0e10cSrcweir     OSL_ASSERT(nStrLen <= STRING_MAXLEN && nCopyLen <= STRING_MAXLEN);
238cdf0e10cSrcweir 	if ( nCopyLen > STRING_MAXLEN-nStrLen )
239cdf0e10cSrcweir 		nCopyLen = STRING_MAXLEN-nStrLen;
240cdf0e10cSrcweir 	return nCopyLen;
241cdf0e10cSrcweir }
242cdf0e10cSrcweir 
243cdf0e10cSrcweir // =======================================================================
244cdf0e10cSrcweir 
STRING()245cdf0e10cSrcweir STRING::STRING()
246cdf0e10cSrcweir 	: mpData(NULL)
247cdf0e10cSrcweir {
248cdf0e10cSrcweir 	DBG_CTOR( STRING, DBGCHECKSTRING );
249cdf0e10cSrcweir 
250cdf0e10cSrcweir 	STRING_NEW((STRING_TYPE **)&mpData);
251cdf0e10cSrcweir }
252cdf0e10cSrcweir 
253cdf0e10cSrcweir // -----------------------------------------------------------------------
254cdf0e10cSrcweir 
STRING(const STRING & rStr)255cdf0e10cSrcweir STRING::STRING( const STRING& rStr )
256cdf0e10cSrcweir {
257cdf0e10cSrcweir 	DBG_CTOR( STRING, DBGCHECKSTRING );
258cdf0e10cSrcweir 	DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING );
259cdf0e10cSrcweir 
260cdf0e10cSrcweir 	// Pointer auf die Daten des uebergebenen Strings setzen und
261cdf0e10cSrcweir 	// Referenzzaehler erhoehen
262cdf0e10cSrcweir 	STRING_ACQUIRE((STRING_TYPE *)rStr.mpData);
263cdf0e10cSrcweir 	mpData = rStr.mpData;
264cdf0e10cSrcweir }
265cdf0e10cSrcweir 
266cdf0e10cSrcweir // -----------------------------------------------------------------------
267cdf0e10cSrcweir 
STRING(const STRING & rStr,xub_StrLen nPos,xub_StrLen nLen)268cdf0e10cSrcweir STRING::STRING( const STRING& rStr, xub_StrLen nPos, xub_StrLen nLen )
269cdf0e10cSrcweir : mpData( NULL )
270cdf0e10cSrcweir {
271cdf0e10cSrcweir 	DBG_CTOR( STRING, DBGCHECKSTRING );
272cdf0e10cSrcweir 	DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING );
273cdf0e10cSrcweir 
274cdf0e10cSrcweir 	// Stringlaenge ermitteln
275cdf0e10cSrcweir 	if ( nPos > rStr.mpData->mnLen )
276cdf0e10cSrcweir 		nLen = 0;
277cdf0e10cSrcweir 	else
278cdf0e10cSrcweir 	{
279cdf0e10cSrcweir 		// Laenge korrigieren, wenn noetig
280cdf0e10cSrcweir 		sal_Int32 nMaxLen = rStr.mpData->mnLen-nPos;
281cdf0e10cSrcweir 		if ( nLen > nMaxLen )
282cdf0e10cSrcweir 			nLen = static_cast< xub_StrLen >(nMaxLen);
283cdf0e10cSrcweir 	}
284cdf0e10cSrcweir 
285cdf0e10cSrcweir 	// Ist es kein leerer String
286cdf0e10cSrcweir 	if ( nLen )
287cdf0e10cSrcweir 	{
288cdf0e10cSrcweir 		// Reicht ein einfaches erhoehen des Referenzcounters
289cdf0e10cSrcweir 		if ( (nPos == 0) && (nLen == rStr.mpData->mnLen) )
290cdf0e10cSrcweir 		{
291cdf0e10cSrcweir 			STRING_ACQUIRE((STRING_TYPE *)rStr.mpData);
292cdf0e10cSrcweir 			mpData = rStr.mpData;
293cdf0e10cSrcweir 		}
294cdf0e10cSrcweir 		else
295cdf0e10cSrcweir 		{
296cdf0e10cSrcweir 			// Verwaltungsdaten anlegen und String kopieren
297cdf0e10cSrcweir 			mpData = ImplAllocData( nLen );
298cdf0e10cSrcweir 			memcpy( mpData->maStr, rStr.mpData->maStr+nPos, nLen*sizeof( STRCODE ) );
299cdf0e10cSrcweir 		}
300cdf0e10cSrcweir 	}
301cdf0e10cSrcweir 	else
302cdf0e10cSrcweir 	{
303cdf0e10cSrcweir 		STRING_NEW((STRING_TYPE **)&mpData);
304cdf0e10cSrcweir 	}
305cdf0e10cSrcweir }
306cdf0e10cSrcweir 
307cdf0e10cSrcweir // -----------------------------------------------------------------------
308cdf0e10cSrcweir 
STRING(const STRCODE * pCharStr)309cdf0e10cSrcweir STRING::STRING( const STRCODE* pCharStr )
310cdf0e10cSrcweir 	: mpData(NULL)
311cdf0e10cSrcweir {
312cdf0e10cSrcweir 	DBG_CTOR( STRING, DBGCHECKSTRING );
313cdf0e10cSrcweir 
314cdf0e10cSrcweir 	// Stringlaenge ermitteln
315cdf0e10cSrcweir 	// Bei diesem Ctor darf NULL uebergeben werden
316cdf0e10cSrcweir 	xub_StrLen nLen;
317cdf0e10cSrcweir 	if ( pCharStr )
318cdf0e10cSrcweir 		nLen = ImplStringLen( pCharStr );
319cdf0e10cSrcweir 	else
320cdf0e10cSrcweir 		nLen = 0;
321cdf0e10cSrcweir 
322cdf0e10cSrcweir 	// Ist es kein leerer String
323cdf0e10cSrcweir 	if ( nLen )
324cdf0e10cSrcweir 	{
325cdf0e10cSrcweir 		// Verwaltungsdaten anlegen und String kopieren
326cdf0e10cSrcweir 		mpData = ImplAllocData( nLen );
327cdf0e10cSrcweir 		memcpy( mpData->maStr, pCharStr, nLen*sizeof( STRCODE ) );
328cdf0e10cSrcweir 	}
329cdf0e10cSrcweir 	else
330cdf0e10cSrcweir 	{
331cdf0e10cSrcweir 		STRING_NEW((STRING_TYPE **)&mpData);
332cdf0e10cSrcweir 	}
333cdf0e10cSrcweir }
334cdf0e10cSrcweir 
335cdf0e10cSrcweir // -----------------------------------------------------------------------
336cdf0e10cSrcweir 
STRING(const STRCODE * pCharStr,xub_StrLen nLen)337cdf0e10cSrcweir STRING::STRING( const STRCODE* pCharStr, xub_StrLen nLen )
338cdf0e10cSrcweir : mpData(NULL)
339cdf0e10cSrcweir {
340cdf0e10cSrcweir 	DBG_CTOR( STRING, DBGCHECKSTRING );
341cdf0e10cSrcweir 	DBG_ASSERT( pCharStr, "String::String() - pCharStr is NULL" );
342cdf0e10cSrcweir 
343cdf0e10cSrcweir 	if ( nLen == STRING_LEN )
344cdf0e10cSrcweir 		nLen = ImplStringLen( pCharStr );
345cdf0e10cSrcweir 
346cdf0e10cSrcweir #ifdef DBG_UTIL
347cdf0e10cSrcweir 	if ( DbgIsAssert() )
348cdf0e10cSrcweir 	{
349cdf0e10cSrcweir 		for ( xub_StrLen i = 0; i < nLen; i++ )
350cdf0e10cSrcweir 		{
351cdf0e10cSrcweir 			if ( !pCharStr[i] )
352cdf0e10cSrcweir 			{
353cdf0e10cSrcweir 				DBG_ERROR( "String::String() : nLen is wrong" );
354cdf0e10cSrcweir 			}
355cdf0e10cSrcweir 		}
356cdf0e10cSrcweir 	}
357cdf0e10cSrcweir #endif
358cdf0e10cSrcweir 
359cdf0e10cSrcweir 	// Ist es kein leerer String
360cdf0e10cSrcweir 	if ( nLen )
361cdf0e10cSrcweir 	{
362cdf0e10cSrcweir 		// Verwaltungsdaten anlegen und String kopieren
363cdf0e10cSrcweir 		mpData = ImplAllocData( nLen );
364cdf0e10cSrcweir 		memcpy( mpData->maStr, pCharStr, nLen*sizeof( STRCODE ) );
365cdf0e10cSrcweir 	}
366cdf0e10cSrcweir 	else
367cdf0e10cSrcweir 	{
368cdf0e10cSrcweir 		STRING_NEW((STRING_TYPE **)&mpData);
369cdf0e10cSrcweir 	}
370cdf0e10cSrcweir }
371cdf0e10cSrcweir 
372cdf0e10cSrcweir // -----------------------------------------------------------------------
373cdf0e10cSrcweir 
STRING(STRCODE c)374cdf0e10cSrcweir STRING::STRING( STRCODE c )
375cdf0e10cSrcweir {
376cdf0e10cSrcweir 	DBG_CTOR( STRING, DBGCHECKSTRING );
377cdf0e10cSrcweir 	DBG_ASSERT( c, "String::String() - c is 0" );
378cdf0e10cSrcweir 
379cdf0e10cSrcweir 	// Verwaltungsdaten anlegen und initialisieren
380cdf0e10cSrcweir 	mpData = ImplAllocData( 1 );
381cdf0e10cSrcweir 	mpData->maStr[0] = c;
382cdf0e10cSrcweir }
383cdf0e10cSrcweir 
384cdf0e10cSrcweir // -----------------------------------------------------------------------
385cdf0e10cSrcweir 
~STRING()386cdf0e10cSrcweir STRING::~STRING()
387cdf0e10cSrcweir {
388cdf0e10cSrcweir 	DBG_DTOR( STRING, DBGCHECKSTRING );
389cdf0e10cSrcweir 
390cdf0e10cSrcweir 	// Daten loeschen
391cdf0e10cSrcweir 	STRING_RELEASE((STRING_TYPE *)mpData);
392cdf0e10cSrcweir }
393cdf0e10cSrcweir 
394cdf0e10cSrcweir // -----------------------------------------------------------------------
395cdf0e10cSrcweir 
Assign(const STRING & rStr)396cdf0e10cSrcweir STRING& STRING::Assign( const STRING& rStr )
397cdf0e10cSrcweir {
398cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
399cdf0e10cSrcweir 	DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING );
400cdf0e10cSrcweir 
401cdf0e10cSrcweir 	STRING_ACQUIRE((STRING_TYPE *)rStr.mpData);
402cdf0e10cSrcweir 	STRING_RELEASE((STRING_TYPE *)mpData);
403cdf0e10cSrcweir 	mpData = rStr.mpData;
404cdf0e10cSrcweir 	return *this;
405cdf0e10cSrcweir }
406cdf0e10cSrcweir 
407cdf0e10cSrcweir // -----------------------------------------------------------------------
408cdf0e10cSrcweir 
Assign(const STRCODE * pCharStr)409cdf0e10cSrcweir STRING& STRING::Assign( const STRCODE* pCharStr )
410cdf0e10cSrcweir {
411cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
412cdf0e10cSrcweir 	DBG_ASSERT( pCharStr, "String::Assign() - pCharStr is NULL" );
413cdf0e10cSrcweir 
414cdf0e10cSrcweir 	// Stringlaenge ermitteln
415cdf0e10cSrcweir 	xub_StrLen nLen = ImplStringLen( pCharStr );
416cdf0e10cSrcweir 
417cdf0e10cSrcweir 	if ( !nLen )
418cdf0e10cSrcweir 	{
419cdf0e10cSrcweir 		STRING_NEW((STRING_TYPE **)&mpData);
420cdf0e10cSrcweir 	}
421cdf0e10cSrcweir 	else
422cdf0e10cSrcweir 	{
423cdf0e10cSrcweir 		// Wenn String genauso lang ist, wie der String, dann direkt kopieren
424cdf0e10cSrcweir 		if ( (nLen == mpData->mnLen) && (mpData->mnRefCount == 1) )
425cdf0e10cSrcweir 			memcpy( mpData->maStr, pCharStr, nLen*sizeof( STRCODE ) );
426cdf0e10cSrcweir 		else
427cdf0e10cSrcweir 		{
428cdf0e10cSrcweir 			// Alte Daten loeschen
429cdf0e10cSrcweir 			STRING_RELEASE((STRING_TYPE *)mpData);
430cdf0e10cSrcweir 
431cdf0e10cSrcweir 			// Daten initialisieren und String kopieren
432cdf0e10cSrcweir 			mpData = ImplAllocData( nLen );
433cdf0e10cSrcweir 			memcpy( mpData->maStr, pCharStr, nLen*sizeof( STRCODE ) );
434cdf0e10cSrcweir 		}
435cdf0e10cSrcweir 	}
436cdf0e10cSrcweir 
437cdf0e10cSrcweir 	return *this;
438cdf0e10cSrcweir }
439cdf0e10cSrcweir 
440cdf0e10cSrcweir // -----------------------------------------------------------------------
441cdf0e10cSrcweir 
Assign(const STRCODE * pCharStr,xub_StrLen nLen)442cdf0e10cSrcweir STRING& STRING::Assign( const STRCODE* pCharStr, xub_StrLen nLen )
443cdf0e10cSrcweir {
444cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
445cdf0e10cSrcweir 	DBG_ASSERT( pCharStr, "String::Assign() - pCharStr is NULL" );
446cdf0e10cSrcweir 
447cdf0e10cSrcweir 	if ( nLen == STRING_LEN )
448cdf0e10cSrcweir 		nLen = ImplStringLen( pCharStr );
449cdf0e10cSrcweir 
450cdf0e10cSrcweir #ifdef DBG_UTIL
451cdf0e10cSrcweir 	if ( DbgIsAssert() )
452cdf0e10cSrcweir 	{
453cdf0e10cSrcweir 		for ( xub_StrLen i = 0; i < nLen; i++ )
454cdf0e10cSrcweir 		{
455cdf0e10cSrcweir 			if ( !pCharStr[i] )
456cdf0e10cSrcweir 			{
457cdf0e10cSrcweir 				DBG_ERROR( "String::Assign() : nLen is wrong" );
458cdf0e10cSrcweir 			}
459cdf0e10cSrcweir 		}
460cdf0e10cSrcweir 	}
461cdf0e10cSrcweir #endif
462cdf0e10cSrcweir 
463cdf0e10cSrcweir 	if ( !nLen )
464cdf0e10cSrcweir 	{
465cdf0e10cSrcweir 		STRING_NEW((STRING_TYPE **)&mpData);
466cdf0e10cSrcweir 	}
467cdf0e10cSrcweir 	else
468cdf0e10cSrcweir 	{
469cdf0e10cSrcweir 		// Wenn String genauso lang ist, wie der String, dann direkt kopieren
470cdf0e10cSrcweir 		if ( (nLen == mpData->mnLen) && (mpData->mnRefCount == 1) )
471cdf0e10cSrcweir 			memcpy( mpData->maStr, pCharStr, nLen*sizeof( STRCODE ) );
472cdf0e10cSrcweir 		else
473cdf0e10cSrcweir 		{
474cdf0e10cSrcweir 			// Alte Daten loeschen
475cdf0e10cSrcweir 			STRING_RELEASE((STRING_TYPE *)mpData);
476cdf0e10cSrcweir 
477cdf0e10cSrcweir 			// Daten initialisieren und String kopieren
478cdf0e10cSrcweir 			mpData = ImplAllocData( nLen );
479cdf0e10cSrcweir 			memcpy( mpData->maStr, pCharStr, nLen*sizeof( STRCODE ) );
480cdf0e10cSrcweir 		}
481cdf0e10cSrcweir 	}
482cdf0e10cSrcweir 
483cdf0e10cSrcweir 	return *this;
484cdf0e10cSrcweir }
485cdf0e10cSrcweir 
486cdf0e10cSrcweir // -----------------------------------------------------------------------
487cdf0e10cSrcweir 
Assign(STRCODE c)488cdf0e10cSrcweir STRING& STRING::Assign( STRCODE c )
489cdf0e10cSrcweir {
490cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
491cdf0e10cSrcweir 	DBG_ASSERT( c, "String::Assign() - c is 0" );
492cdf0e10cSrcweir 
493cdf0e10cSrcweir 	// Verwaltungsdaten anlegen und initialisieren
494cdf0e10cSrcweir 	STRING_RELEASE((STRING_TYPE *)mpData);
495cdf0e10cSrcweir 	mpData = ImplAllocData( 1 );
496cdf0e10cSrcweir 	mpData->maStr[0] = c;
497cdf0e10cSrcweir 	return *this;
498cdf0e10cSrcweir }
499cdf0e10cSrcweir 
500cdf0e10cSrcweir // -----------------------------------------------------------------------
501cdf0e10cSrcweir 
Append(const STRING & rStr)502cdf0e10cSrcweir STRING& STRING::Append( const STRING& rStr )
503cdf0e10cSrcweir {
504cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
505cdf0e10cSrcweir 	DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING );
506cdf0e10cSrcweir 
507cdf0e10cSrcweir 	// Wenn String leer, dann reicht eine Zuweisung
508cdf0e10cSrcweir 	sal_Int32 nLen = mpData->mnLen;
509cdf0e10cSrcweir 	if ( !nLen )
510cdf0e10cSrcweir 	{
511cdf0e10cSrcweir 		STRING_ACQUIRE((STRING_TYPE *)rStr.mpData);
512cdf0e10cSrcweir 		STRING_RELEASE((STRING_TYPE *)mpData);
513cdf0e10cSrcweir 		mpData = rStr.mpData;
514cdf0e10cSrcweir 	}
515cdf0e10cSrcweir 	else
516cdf0e10cSrcweir 	{
517cdf0e10cSrcweir 		// Ueberlauf abfangen
518cdf0e10cSrcweir 		sal_Int32 nCopyLen = ImplGetCopyLen( nLen, rStr.mpData->mnLen );
519cdf0e10cSrcweir 
520cdf0e10cSrcweir 		// Ist der uebergebene String kein Leerstring
521cdf0e10cSrcweir 		if ( nCopyLen )
522cdf0e10cSrcweir 		{
523cdf0e10cSrcweir 			// Neue Datenstruktur und neuen String erzeugen
524cdf0e10cSrcweir 			STRINGDATA* pNewData = ImplAllocData( nLen+nCopyLen );
525cdf0e10cSrcweir 
526cdf0e10cSrcweir 			// String kopieren
527cdf0e10cSrcweir 			memcpy( pNewData->maStr, mpData->maStr, nLen*sizeof( STRCODE ) );
528cdf0e10cSrcweir 			memcpy( pNewData->maStr+nLen, rStr.mpData->maStr, nCopyLen*sizeof( STRCODE ) );
529cdf0e10cSrcweir 
530cdf0e10cSrcweir 			// Alte Daten loeschen und Neue zuweisen
531cdf0e10cSrcweir 			STRING_RELEASE((STRING_TYPE *)mpData);
532cdf0e10cSrcweir 			mpData = pNewData;
533cdf0e10cSrcweir 		}
534cdf0e10cSrcweir 	}
535cdf0e10cSrcweir 
536cdf0e10cSrcweir 	return *this;
537cdf0e10cSrcweir }
538cdf0e10cSrcweir 
539cdf0e10cSrcweir // -----------------------------------------------------------------------
540cdf0e10cSrcweir 
Append(const STRCODE * pCharStr)541cdf0e10cSrcweir STRING& STRING::Append( const STRCODE* pCharStr )
542cdf0e10cSrcweir {
543cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
544cdf0e10cSrcweir 	DBG_ASSERT( pCharStr, "String::Append() - pCharStr is NULL" );
545cdf0e10cSrcweir 
546cdf0e10cSrcweir 	// Stringlaenge ermitteln
547cdf0e10cSrcweir 	sal_Int32 nLen = mpData->mnLen;
548cdf0e10cSrcweir 	sal_Int32 nCopyLen = ImplStringLen( pCharStr );
549cdf0e10cSrcweir 
550cdf0e10cSrcweir 	// Ueberlauf abfangen
551cdf0e10cSrcweir 	nCopyLen = ImplGetCopyLen( nLen, nCopyLen );
552cdf0e10cSrcweir 
553cdf0e10cSrcweir 	// Ist es kein leerer String
554cdf0e10cSrcweir 	if ( nCopyLen )
555cdf0e10cSrcweir 	{
556cdf0e10cSrcweir 		// Neue Datenstruktur und neuen String erzeugen
557cdf0e10cSrcweir 		STRINGDATA* pNewData = ImplAllocData( nLen+nCopyLen );
558cdf0e10cSrcweir 
559cdf0e10cSrcweir 		// String kopieren
560cdf0e10cSrcweir 		memcpy( pNewData->maStr, mpData->maStr, nLen*sizeof( STRCODE ) );
561cdf0e10cSrcweir 		memcpy( pNewData->maStr+nLen, pCharStr, nCopyLen*sizeof( STRCODE ) );
562cdf0e10cSrcweir 
563cdf0e10cSrcweir 		// Alte Daten loeschen und Neue zuweisen
564cdf0e10cSrcweir 		STRING_RELEASE((STRING_TYPE *)mpData);
565cdf0e10cSrcweir 		mpData = pNewData;
566cdf0e10cSrcweir 	}
567cdf0e10cSrcweir 
568cdf0e10cSrcweir 	return *this;
569cdf0e10cSrcweir }
570cdf0e10cSrcweir 
571cdf0e10cSrcweir // -----------------------------------------------------------------------
572cdf0e10cSrcweir 
Append(const STRCODE * pCharStr,xub_StrLen nCharLen)573cdf0e10cSrcweir STRING& STRING::Append( const STRCODE* pCharStr, xub_StrLen nCharLen )
574cdf0e10cSrcweir {
575cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
576cdf0e10cSrcweir 	DBG_ASSERT( pCharStr, "String::Append() - pCharStr is NULL" );
577cdf0e10cSrcweir 
578cdf0e10cSrcweir 	if ( nCharLen == STRING_LEN )
579cdf0e10cSrcweir 		nCharLen = ImplStringLen( pCharStr );
580cdf0e10cSrcweir 
581cdf0e10cSrcweir #ifdef DBG_UTIL
582cdf0e10cSrcweir 	if ( DbgIsAssert() )
583cdf0e10cSrcweir 	{
584cdf0e10cSrcweir 		for ( xub_StrLen i = 0; i < nCharLen; i++ )
585cdf0e10cSrcweir 		{
586cdf0e10cSrcweir 			if ( !pCharStr[i] )
587cdf0e10cSrcweir 			{
588cdf0e10cSrcweir 				DBG_ERROR( "String::Append() : nLen is wrong" );
589cdf0e10cSrcweir 			}
590cdf0e10cSrcweir 		}
591cdf0e10cSrcweir 	}
592cdf0e10cSrcweir #endif
593cdf0e10cSrcweir 
594cdf0e10cSrcweir 	// Ueberlauf abfangen
595cdf0e10cSrcweir 	sal_Int32 nLen = mpData->mnLen;
596cdf0e10cSrcweir 	sal_Int32 nCopyLen = ImplGetCopyLen( nLen, nCharLen );
597cdf0e10cSrcweir 
598cdf0e10cSrcweir 	// Ist es kein leerer String
599cdf0e10cSrcweir 	if ( nCopyLen )
600cdf0e10cSrcweir 	{
601cdf0e10cSrcweir 		// Neue Datenstruktur und neuen String erzeugen
602cdf0e10cSrcweir 		STRINGDATA* pNewData = ImplAllocData( nLen+nCopyLen );
603cdf0e10cSrcweir 
604cdf0e10cSrcweir 		// String kopieren
605cdf0e10cSrcweir 		memcpy( pNewData->maStr, mpData->maStr, nLen*sizeof( STRCODE ) );
606cdf0e10cSrcweir 		memcpy( pNewData->maStr+nLen, pCharStr, nCopyLen*sizeof( STRCODE ) );
607cdf0e10cSrcweir 
608cdf0e10cSrcweir 		// Alte Daten loeschen und Neue zuweisen
609cdf0e10cSrcweir 		STRING_RELEASE((STRING_TYPE *)mpData);
610cdf0e10cSrcweir 		mpData = pNewData;
611cdf0e10cSrcweir 	}
612cdf0e10cSrcweir 
613cdf0e10cSrcweir 	return *this;
614cdf0e10cSrcweir }
615cdf0e10cSrcweir 
616cdf0e10cSrcweir // -----------------------------------------------------------------------
617cdf0e10cSrcweir 
Append(STRCODE c)618cdf0e10cSrcweir STRING& STRING::Append( STRCODE c )
619cdf0e10cSrcweir {
620cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
621cdf0e10cSrcweir 
622cdf0e10cSrcweir 	// kein 0-Character und maximale Stringlaenge nicht ueberschreiten
623cdf0e10cSrcweir 	sal_Int32 nLen = mpData->mnLen;
624cdf0e10cSrcweir 	if ( c && (nLen < STRING_MAXLEN) )
625cdf0e10cSrcweir 	{
626cdf0e10cSrcweir 		// Neue Datenstruktur und neuen String erzeugen
627cdf0e10cSrcweir 		STRINGDATA* pNewData = ImplAllocData( nLen+1 );
628cdf0e10cSrcweir 
629cdf0e10cSrcweir 		// String kopieren
630cdf0e10cSrcweir 		memcpy( pNewData->maStr, mpData->maStr, nLen*sizeof( STRCODE ) );
631cdf0e10cSrcweir 		pNewData->maStr[nLen] = c;
632cdf0e10cSrcweir 
633cdf0e10cSrcweir 		// Alte Daten loeschen und Neue zuweisen
634cdf0e10cSrcweir 		STRING_RELEASE((STRING_TYPE *)mpData);
635cdf0e10cSrcweir 		mpData = pNewData;
636cdf0e10cSrcweir 	}
637cdf0e10cSrcweir 
638cdf0e10cSrcweir 	return *this;
639cdf0e10cSrcweir }
640cdf0e10cSrcweir 
641cdf0e10cSrcweir // -----------------------------------------------------------------------
642cdf0e10cSrcweir 
SetChar(xub_StrLen nIndex,STRCODE c)643cdf0e10cSrcweir void STRING::SetChar( xub_StrLen nIndex, STRCODE c )
644cdf0e10cSrcweir {
645cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
646cdf0e10cSrcweir 	DBG_ASSERT( nIndex < mpData->mnLen, "String::SetChar() - nIndex > String.Len()" );
647cdf0e10cSrcweir 
648cdf0e10cSrcweir 	// Daten kopieren, wenn noetig und Character zuweisen
649cdf0e10cSrcweir 	ImplCopyData();
650cdf0e10cSrcweir 	mpData->maStr[nIndex] = c;
651cdf0e10cSrcweir }
652cdf0e10cSrcweir 
653cdf0e10cSrcweir // -----------------------------------------------------------------------
654cdf0e10cSrcweir 
Insert(const STRING & rStr,xub_StrLen nIndex)655cdf0e10cSrcweir STRING& STRING::Insert( const STRING& rStr, xub_StrLen nIndex )
656cdf0e10cSrcweir {
657cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
658cdf0e10cSrcweir 	DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING );
659cdf0e10cSrcweir 
660cdf0e10cSrcweir 	// Ueberlauf abfangen
661cdf0e10cSrcweir 	sal_Int32 nCopyLen = ImplGetCopyLen( mpData->mnLen, rStr.mpData->mnLen );
662cdf0e10cSrcweir 
663cdf0e10cSrcweir 	// Ist der einzufuegende String ein Leerstring
664cdf0e10cSrcweir 	if ( !nCopyLen )
665cdf0e10cSrcweir 		return *this;
666cdf0e10cSrcweir 
667cdf0e10cSrcweir 	// Index groesser als Laenge
668cdf0e10cSrcweir 	if ( nIndex > mpData->mnLen )
669cdf0e10cSrcweir 		nIndex = static_cast< xub_StrLen >(mpData->mnLen);
670cdf0e10cSrcweir 
671cdf0e10cSrcweir 	// Neue Laenge ermitteln und neuen String anlegen
672cdf0e10cSrcweir 	STRINGDATA* pNewData = ImplAllocData( mpData->mnLen+nCopyLen );
673cdf0e10cSrcweir 
674cdf0e10cSrcweir 	// String kopieren
675cdf0e10cSrcweir 	memcpy( pNewData->maStr, mpData->maStr, nIndex*sizeof( STRCODE ) );
676cdf0e10cSrcweir 	memcpy( pNewData->maStr+nIndex, rStr.mpData->maStr, nCopyLen*sizeof( STRCODE ) );
677cdf0e10cSrcweir 	memcpy( pNewData->maStr+nIndex+nCopyLen, mpData->maStr+nIndex,
678cdf0e10cSrcweir 			(mpData->mnLen-nIndex)*sizeof( STRCODE ) );
679cdf0e10cSrcweir 
680cdf0e10cSrcweir 	// Alte Daten loeschen und Neue zuweisen
681cdf0e10cSrcweir 	STRING_RELEASE((STRING_TYPE *)mpData);
682cdf0e10cSrcweir 	mpData = pNewData;
683cdf0e10cSrcweir 
684cdf0e10cSrcweir 	return *this;
685cdf0e10cSrcweir }
686cdf0e10cSrcweir 
687cdf0e10cSrcweir // -----------------------------------------------------------------------
688cdf0e10cSrcweir 
Insert(const STRING & rStr,xub_StrLen nPos,xub_StrLen nLen,xub_StrLen nIndex)689cdf0e10cSrcweir STRING& STRING::Insert( const STRING& rStr, xub_StrLen nPos, xub_StrLen nLen,
690cdf0e10cSrcweir 						xub_StrLen nIndex )
691cdf0e10cSrcweir {
692cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
693cdf0e10cSrcweir 	DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING );
694cdf0e10cSrcweir 
695cdf0e10cSrcweir 	// Stringlaenge ermitteln
696cdf0e10cSrcweir 	if ( nPos > rStr.mpData->mnLen )
697cdf0e10cSrcweir 		nLen = 0;
698cdf0e10cSrcweir 	else
699cdf0e10cSrcweir 	{
700cdf0e10cSrcweir 		// Laenge korrigieren, wenn noetig
701cdf0e10cSrcweir 		sal_Int32 nMaxLen = rStr.mpData->mnLen-nPos;
702cdf0e10cSrcweir 		if ( nLen > nMaxLen )
703cdf0e10cSrcweir 			nLen = static_cast< xub_StrLen >(nMaxLen);
704cdf0e10cSrcweir 	}
705cdf0e10cSrcweir 
706cdf0e10cSrcweir 	// Ueberlauf abfangen
707cdf0e10cSrcweir 	sal_Int32 nCopyLen = ImplGetCopyLen( mpData->mnLen, nLen );
708cdf0e10cSrcweir 
709cdf0e10cSrcweir 	// Ist der einzufuegende String ein Leerstring
710cdf0e10cSrcweir 	if ( !nCopyLen )
711cdf0e10cSrcweir 		return *this;
712cdf0e10cSrcweir 
713cdf0e10cSrcweir 	// Index groesser als Laenge
714cdf0e10cSrcweir 	if ( nIndex > mpData->mnLen )
715cdf0e10cSrcweir 		nIndex = static_cast< xub_StrLen >(mpData->mnLen);
716cdf0e10cSrcweir 
717cdf0e10cSrcweir 	// Neue Laenge ermitteln und neuen String anlegen
718cdf0e10cSrcweir 	STRINGDATA* pNewData = ImplAllocData( mpData->mnLen+nCopyLen );
719cdf0e10cSrcweir 
720cdf0e10cSrcweir 	// String kopieren
721cdf0e10cSrcweir 	memcpy( pNewData->maStr, mpData->maStr, nIndex*sizeof( STRCODE ) );
722cdf0e10cSrcweir 	memcpy( pNewData->maStr+nIndex, rStr.mpData->maStr+nPos, nCopyLen*sizeof( STRCODE ) );
723cdf0e10cSrcweir 	memcpy( pNewData->maStr+nIndex+nCopyLen, mpData->maStr+nIndex,
724cdf0e10cSrcweir 			(mpData->mnLen-nIndex)*sizeof( STRCODE ) );
725cdf0e10cSrcweir 
726cdf0e10cSrcweir 	// Alte Daten loeschen und Neue zuweisen
727cdf0e10cSrcweir 	STRING_RELEASE((STRING_TYPE *)mpData);
728cdf0e10cSrcweir 	mpData = pNewData;
729cdf0e10cSrcweir 
730cdf0e10cSrcweir 	return *this;
731cdf0e10cSrcweir }
732cdf0e10cSrcweir 
733cdf0e10cSrcweir // -----------------------------------------------------------------------
734cdf0e10cSrcweir 
Insert(const STRCODE * pCharStr,xub_StrLen nIndex)735cdf0e10cSrcweir STRING& STRING::Insert( const STRCODE* pCharStr, xub_StrLen nIndex )
736cdf0e10cSrcweir {
737cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
738cdf0e10cSrcweir 	DBG_ASSERT( pCharStr, "String::Insert() - pCharStr is NULL" );
739cdf0e10cSrcweir 
740cdf0e10cSrcweir 	// Stringlaenge ermitteln
741cdf0e10cSrcweir 	sal_Int32 nCopyLen = ImplStringLen( pCharStr );
742cdf0e10cSrcweir 
743cdf0e10cSrcweir 	// Ueberlauf abfangen
744cdf0e10cSrcweir 	nCopyLen = ImplGetCopyLen( mpData->mnLen, nCopyLen );
745cdf0e10cSrcweir 
746cdf0e10cSrcweir 	// Ist der einzufuegende String ein Leerstring
747cdf0e10cSrcweir 	if ( !nCopyLen )
748cdf0e10cSrcweir 		return *this;
749cdf0e10cSrcweir 
750cdf0e10cSrcweir 	// Index groesser als Laenge
751cdf0e10cSrcweir 	if ( nIndex > mpData->mnLen )
752cdf0e10cSrcweir 		nIndex = static_cast< xub_StrLen >(mpData->mnLen);
753cdf0e10cSrcweir 
754cdf0e10cSrcweir 	// Neue Laenge ermitteln und neuen String anlegen
755cdf0e10cSrcweir 	STRINGDATA* pNewData = ImplAllocData( mpData->mnLen+nCopyLen );
756cdf0e10cSrcweir 
757cdf0e10cSrcweir 	// String kopieren
758cdf0e10cSrcweir 	memcpy( pNewData->maStr, mpData->maStr, nIndex*sizeof( STRCODE ) );
759cdf0e10cSrcweir 	memcpy( pNewData->maStr+nIndex, pCharStr, nCopyLen*sizeof( STRCODE ) );
760cdf0e10cSrcweir 	memcpy( pNewData->maStr+nIndex+nCopyLen, mpData->maStr+nIndex,
761cdf0e10cSrcweir 			(mpData->mnLen-nIndex)*sizeof( STRCODE ) );
762cdf0e10cSrcweir 
763cdf0e10cSrcweir 	// Alte Daten loeschen und Neue zuweisen
764cdf0e10cSrcweir 	STRING_RELEASE((STRING_TYPE *)mpData);
765cdf0e10cSrcweir 	mpData = pNewData;
766cdf0e10cSrcweir 
767cdf0e10cSrcweir 	return *this;
768cdf0e10cSrcweir }
769cdf0e10cSrcweir 
770cdf0e10cSrcweir // -----------------------------------------------------------------------
771cdf0e10cSrcweir 
Insert(STRCODE c,xub_StrLen nIndex)772cdf0e10cSrcweir STRING& STRING::Insert( STRCODE c, xub_StrLen nIndex )
773cdf0e10cSrcweir {
774cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
775cdf0e10cSrcweir 
776cdf0e10cSrcweir 	// Ist es kein 0-Character
777cdf0e10cSrcweir 	if ( !c || (mpData->mnLen == STRING_MAXLEN) )
778cdf0e10cSrcweir 		return *this;
779cdf0e10cSrcweir 
780cdf0e10cSrcweir 	// Index groesser als Laenge
781cdf0e10cSrcweir 	if ( nIndex > mpData->mnLen )
782cdf0e10cSrcweir 		nIndex = static_cast< xub_StrLen >(mpData->mnLen);
783cdf0e10cSrcweir 
784cdf0e10cSrcweir 	// Neue Laenge ermitteln und neuen String anlegen
785cdf0e10cSrcweir 	STRINGDATA* pNewData = ImplAllocData( mpData->mnLen+1 );
786cdf0e10cSrcweir 
787cdf0e10cSrcweir 	// String kopieren
788cdf0e10cSrcweir 	memcpy( pNewData->maStr, mpData->maStr, nIndex*sizeof( STRCODE ) );
789cdf0e10cSrcweir 	pNewData->maStr[nIndex] = c;
790cdf0e10cSrcweir 	memcpy( pNewData->maStr+nIndex+1, mpData->maStr+nIndex,
791cdf0e10cSrcweir 			(mpData->mnLen-nIndex)*sizeof( STRCODE ) );
792cdf0e10cSrcweir 
793cdf0e10cSrcweir 	// Alte Daten loeschen und Neue zuweisen
794cdf0e10cSrcweir 	STRING_RELEASE((STRING_TYPE *)mpData);
795cdf0e10cSrcweir 	mpData = pNewData;
796cdf0e10cSrcweir 
797cdf0e10cSrcweir 	return *this;
798cdf0e10cSrcweir }
799cdf0e10cSrcweir 
800cdf0e10cSrcweir // -----------------------------------------------------------------------
801cdf0e10cSrcweir 
Replace(xub_StrLen nIndex,xub_StrLen nCount,const STRING & rStr)802cdf0e10cSrcweir STRING& STRING::Replace( xub_StrLen nIndex, xub_StrLen nCount, const STRING& rStr )
803cdf0e10cSrcweir {
804cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
805cdf0e10cSrcweir 	DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING );
806cdf0e10cSrcweir 
807cdf0e10cSrcweir 	// Wenn Index groessergleich Laenge ist, dann ist es ein Append
808cdf0e10cSrcweir 	if ( nIndex >= mpData->mnLen )
809cdf0e10cSrcweir 	{
810cdf0e10cSrcweir 		Append( rStr );
811cdf0e10cSrcweir 		return *this;
812cdf0e10cSrcweir 	}
813cdf0e10cSrcweir 
814cdf0e10cSrcweir 	// Ist es eine Zuweisung
815cdf0e10cSrcweir 	if ( (nIndex == 0) && (nCount >= mpData->mnLen) )
816cdf0e10cSrcweir 	{
817cdf0e10cSrcweir 		Assign( rStr );
818cdf0e10cSrcweir 		return *this;
819cdf0e10cSrcweir 	}
820cdf0e10cSrcweir 
821cdf0e10cSrcweir 	// Reicht ein Erase
822cdf0e10cSrcweir 	sal_Int32 nStrLen = rStr.mpData->mnLen;
823cdf0e10cSrcweir 	if ( !nStrLen )
824cdf0e10cSrcweir 		return Erase( nIndex, nCount );
825cdf0e10cSrcweir 
826cdf0e10cSrcweir 	// nCount darf nicht ueber das Stringende hinnausgehen
827cdf0e10cSrcweir 	if ( nCount > mpData->mnLen - nIndex )
828cdf0e10cSrcweir 		nCount = static_cast< xub_StrLen >(mpData->mnLen-nIndex);
829cdf0e10cSrcweir 
830cdf0e10cSrcweir 	// Reicht ein Insert
831cdf0e10cSrcweir 	if ( !nCount )
832cdf0e10cSrcweir 		return Insert( rStr, nIndex );
833cdf0e10cSrcweir 
834cdf0e10cSrcweir 	// Reicht eine zeichenweise Zuweisung
835cdf0e10cSrcweir 	if ( nCount == nStrLen )
836cdf0e10cSrcweir 	{
837cdf0e10cSrcweir 		ImplCopyData();
838cdf0e10cSrcweir 		memcpy( mpData->maStr+nIndex, rStr.mpData->maStr, nCount*sizeof( STRCODE ) );
839cdf0e10cSrcweir 		return *this;
840cdf0e10cSrcweir 	}
841cdf0e10cSrcweir 
842cdf0e10cSrcweir 	// Ueberlauf abfangen
843cdf0e10cSrcweir 	nStrLen = ImplGetCopyLen( mpData->mnLen-nCount, nStrLen );
844cdf0e10cSrcweir 
845cdf0e10cSrcweir 	// Neue Daten anlegen
846cdf0e10cSrcweir 	STRINGDATA* pNewData = ImplAllocData( mpData->mnLen-nCount+nStrLen );
847cdf0e10cSrcweir 
848cdf0e10cSrcweir 	// String kopieren
849cdf0e10cSrcweir 	memcpy( pNewData->maStr, mpData->maStr, nIndex*sizeof( STRCODE ) );
850cdf0e10cSrcweir 	memcpy( pNewData->maStr+nIndex, rStr.mpData->maStr, nStrLen*sizeof( STRCODE ) );
851cdf0e10cSrcweir 	memcpy( pNewData->maStr+nIndex+nStrLen, mpData->maStr+nIndex+nCount,
852cdf0e10cSrcweir 			(mpData->mnLen-nIndex-nCount+1)*sizeof( STRCODE ) );
853cdf0e10cSrcweir 
854cdf0e10cSrcweir 	// Alte Daten loeschen und Neue zuweisen
855cdf0e10cSrcweir 	STRING_RELEASE((STRING_TYPE *)mpData);
856cdf0e10cSrcweir 	mpData = pNewData;
857cdf0e10cSrcweir 
858cdf0e10cSrcweir 	return *this;
859cdf0e10cSrcweir }
860cdf0e10cSrcweir 
861cdf0e10cSrcweir // -----------------------------------------------------------------------
862cdf0e10cSrcweir 
Erase(xub_StrLen nIndex,xub_StrLen nCount)863cdf0e10cSrcweir STRING& STRING::Erase( xub_StrLen nIndex, xub_StrLen nCount )
864cdf0e10cSrcweir {
865cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
866cdf0e10cSrcweir 
867cdf0e10cSrcweir 	// Ist der Index ausserhalb des Strings oder ist nCount == 0
868cdf0e10cSrcweir 	if ( (nIndex >= mpData->mnLen) || !nCount )
869cdf0e10cSrcweir 		return *this;
870cdf0e10cSrcweir 
871cdf0e10cSrcweir 	// nCount darf nicht ueber das Stringende hinnausgehen
872cdf0e10cSrcweir 	if ( nCount > mpData->mnLen - nIndex )
873cdf0e10cSrcweir 		nCount = static_cast< xub_StrLen >(mpData->mnLen-nIndex);
874cdf0e10cSrcweir 
875cdf0e10cSrcweir 	// Ist das Ergebnis kein Leerstring
876cdf0e10cSrcweir 	if ( mpData->mnLen - nCount )
877cdf0e10cSrcweir 	{
878cdf0e10cSrcweir 		// Neue Daten anlegen
879cdf0e10cSrcweir 		STRINGDATA* pNewData = ImplAllocData( mpData->mnLen-nCount );
880cdf0e10cSrcweir 
881cdf0e10cSrcweir 		// String kopieren
882cdf0e10cSrcweir 		memcpy( pNewData->maStr, mpData->maStr, nIndex*sizeof( STRCODE ) );
883cdf0e10cSrcweir 		memcpy( pNewData->maStr+nIndex, mpData->maStr+nIndex+nCount,
884cdf0e10cSrcweir 				(mpData->mnLen-nIndex-nCount+1)*sizeof( STRCODE ) );
885cdf0e10cSrcweir 
886cdf0e10cSrcweir 		// Alte Daten loeschen und Neue zuweisen
887cdf0e10cSrcweir 		STRING_RELEASE((STRING_TYPE *)mpData);
888cdf0e10cSrcweir 		mpData = pNewData;
889cdf0e10cSrcweir 	}
890cdf0e10cSrcweir 	else
891cdf0e10cSrcweir 	{
892cdf0e10cSrcweir 		STRING_NEW((STRING_TYPE **)&mpData);
893cdf0e10cSrcweir 	}
894cdf0e10cSrcweir 
895cdf0e10cSrcweir 	return *this;
896cdf0e10cSrcweir }
897cdf0e10cSrcweir 
898cdf0e10cSrcweir // -----------------------------------------------------------------------
899cdf0e10cSrcweir 
Fill(xub_StrLen nCount,STRCODE cFillChar)900cdf0e10cSrcweir STRING& STRING::Fill( xub_StrLen nCount, STRCODE cFillChar )
901cdf0e10cSrcweir {
902cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
903cdf0e10cSrcweir 
904cdf0e10cSrcweir 	if ( !nCount )
905cdf0e10cSrcweir 		return *this;
906cdf0e10cSrcweir 
907cdf0e10cSrcweir 	// Ist nCount groesser wie der jetzige String, dann verlaengern
908cdf0e10cSrcweir 	if ( nCount > mpData->mnLen )
909cdf0e10cSrcweir 	{
910cdf0e10cSrcweir 		// dann neuen String mit der neuen Laenge anlegen
911cdf0e10cSrcweir 		STRINGDATA* pNewData = ImplAllocData( nCount );
912cdf0e10cSrcweir 		STRING_RELEASE((STRING_TYPE *)mpData);
913cdf0e10cSrcweir 		mpData = pNewData;
914cdf0e10cSrcweir 	}
915cdf0e10cSrcweir 	else
916cdf0e10cSrcweir 		ImplCopyData();
917cdf0e10cSrcweir 
918cdf0e10cSrcweir 	STRCODE* pStr = mpData->maStr;
919cdf0e10cSrcweir 	do
920cdf0e10cSrcweir 	{
921cdf0e10cSrcweir 		*pStr = cFillChar;
922cdf0e10cSrcweir 		++pStr,
923cdf0e10cSrcweir 		--nCount;
924cdf0e10cSrcweir 	}
925cdf0e10cSrcweir 	while ( nCount );
926cdf0e10cSrcweir 
927cdf0e10cSrcweir 	return *this;
928cdf0e10cSrcweir }
929cdf0e10cSrcweir 
930cdf0e10cSrcweir // -----------------------------------------------------------------------
931cdf0e10cSrcweir 
Expand(xub_StrLen nCount,STRCODE cExpandChar)932cdf0e10cSrcweir STRING& STRING::Expand( xub_StrLen nCount, STRCODE cExpandChar )
933cdf0e10cSrcweir {
934cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
935cdf0e10cSrcweir 
936cdf0e10cSrcweir 	// Muss der String erweitert werden
937cdf0e10cSrcweir 	sal_Int32 nLen = mpData->mnLen;
938cdf0e10cSrcweir 	if ( nCount <= nLen )
939cdf0e10cSrcweir 		return *this;
940cdf0e10cSrcweir 
941cdf0e10cSrcweir 	// Neuen String anlegen
942cdf0e10cSrcweir 	STRINGDATA* pNewData = ImplAllocData( nCount );
943cdf0e10cSrcweir 
944cdf0e10cSrcweir 	// Alten String kopieren
945cdf0e10cSrcweir 	memcpy( pNewData->maStr, mpData->maStr, nLen*sizeof( STRCODE ) );
946cdf0e10cSrcweir 
947cdf0e10cSrcweir 	// und initialisieren
948cdf0e10cSrcweir 	STRCODE* pStr = pNewData->maStr;
949cdf0e10cSrcweir 	pStr += nLen;
950cdf0e10cSrcweir 	for (sal_Int32 i = nCount - nLen; i > 0; --i) {
951cdf0e10cSrcweir 		*pStr++ = cExpandChar;
952cdf0e10cSrcweir 	}
953cdf0e10cSrcweir 
954cdf0e10cSrcweir 	// Alte Daten loeschen und Neue zuweisen
955cdf0e10cSrcweir 	STRING_RELEASE((STRING_TYPE *)mpData);
956cdf0e10cSrcweir 	mpData = pNewData;
957cdf0e10cSrcweir 
958cdf0e10cSrcweir 	return *this;
959cdf0e10cSrcweir }
960cdf0e10cSrcweir 
961cdf0e10cSrcweir // -----------------------------------------------------------------------
962cdf0e10cSrcweir 
EraseLeadingChars(STRCODE c)963cdf0e10cSrcweir STRING& STRING::EraseLeadingChars( STRCODE c )
964cdf0e10cSrcweir {
965cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
966cdf0e10cSrcweir 
967cdf0e10cSrcweir 	if ( mpData->maStr[0] != c )
968cdf0e10cSrcweir 		return *this;
969cdf0e10cSrcweir 
970cdf0e10cSrcweir 	xub_StrLen nStart = 0;
971cdf0e10cSrcweir 	while ( mpData->maStr[nStart] == c )
972cdf0e10cSrcweir 		++nStart;
973cdf0e10cSrcweir 
974cdf0e10cSrcweir 	return Erase( 0, nStart );
975cdf0e10cSrcweir }
976cdf0e10cSrcweir 
977cdf0e10cSrcweir // -----------------------------------------------------------------------
978cdf0e10cSrcweir 
EraseTrailingChars(STRCODE c)979cdf0e10cSrcweir STRING& STRING::EraseTrailingChars( STRCODE c )
980cdf0e10cSrcweir {
981cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
982cdf0e10cSrcweir 
983cdf0e10cSrcweir 	sal_Int32 nEnd = mpData->mnLen;
984cdf0e10cSrcweir 	while ( nEnd && (mpData->maStr[nEnd-1] == c) )
985cdf0e10cSrcweir 		nEnd--;
986cdf0e10cSrcweir 
987cdf0e10cSrcweir 	if ( nEnd != mpData->mnLen )
988cdf0e10cSrcweir 		Erase( static_cast< xub_StrLen >(nEnd) );
989cdf0e10cSrcweir 
990cdf0e10cSrcweir 	return *this;
991cdf0e10cSrcweir }
992cdf0e10cSrcweir 
993cdf0e10cSrcweir // -----------------------------------------------------------------------
994cdf0e10cSrcweir 
EraseLeadingAndTrailingChars(STRCODE c)995cdf0e10cSrcweir STRING& STRING::EraseLeadingAndTrailingChars( STRCODE c )
996cdf0e10cSrcweir {
997cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
998cdf0e10cSrcweir 
999cdf0e10cSrcweir 	xub_StrLen nStart = 0;
1000cdf0e10cSrcweir 	while ( mpData->maStr[nStart] == c )
1001cdf0e10cSrcweir 		++nStart;
1002cdf0e10cSrcweir 	if ( nStart )
1003cdf0e10cSrcweir 		Erase( 0, nStart );
1004cdf0e10cSrcweir 
1005cdf0e10cSrcweir 	sal_Int32 nEnd = mpData->mnLen;
1006cdf0e10cSrcweir 	while ( nEnd && (mpData->maStr[nEnd-1] == c) )
1007cdf0e10cSrcweir 		nEnd--;
1008cdf0e10cSrcweir 	if ( nEnd != mpData->mnLen )
1009cdf0e10cSrcweir 		Erase( static_cast< xub_StrLen >(nEnd) );
1010cdf0e10cSrcweir 
1011cdf0e10cSrcweir 	return *this;
1012cdf0e10cSrcweir }
1013cdf0e10cSrcweir 
1014cdf0e10cSrcweir // -----------------------------------------------------------------------
1015cdf0e10cSrcweir 
EraseAllChars(STRCODE c)1016cdf0e10cSrcweir STRING& STRING::EraseAllChars( STRCODE c )
1017cdf0e10cSrcweir {
1018cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1019cdf0e10cSrcweir 
1020cdf0e10cSrcweir 	sal_Int32 nCount = 0;
1021cdf0e10cSrcweir 	for (sal_Int32 i = 0; i < mpData->mnLen; ++i) {
1022cdf0e10cSrcweir 		if ( mpData->maStr[i] == c )
1023cdf0e10cSrcweir 			++nCount;
1024cdf0e10cSrcweir 	}
1025cdf0e10cSrcweir 
1026cdf0e10cSrcweir 	if ( nCount )
1027cdf0e10cSrcweir 	{
1028cdf0e10cSrcweir 		if ( nCount == mpData->mnLen )
1029cdf0e10cSrcweir 		{
1030cdf0e10cSrcweir 			STRING_NEW((STRING_TYPE **)&mpData);
1031cdf0e10cSrcweir 		}
1032cdf0e10cSrcweir 		else
1033cdf0e10cSrcweir 		{
1034cdf0e10cSrcweir 			// Neuen String anlegen
1035cdf0e10cSrcweir 			STRINGDATA* pNewData = ImplAllocData( mpData->mnLen-nCount );
1036cdf0e10cSrcweir 
1037cdf0e10cSrcweir 			// Alten String kopieren und initialisieren
1038cdf0e10cSrcweir 			nCount = 0;
1039cdf0e10cSrcweir 			for( xub_StrLen j = 0; j < mpData->mnLen; ++j )
1040cdf0e10cSrcweir 			{
1041cdf0e10cSrcweir 				if ( mpData->maStr[j] != c )
1042cdf0e10cSrcweir 				{
1043cdf0e10cSrcweir 					pNewData->maStr[nCount] = mpData->maStr[j];
1044cdf0e10cSrcweir 					++nCount;
1045cdf0e10cSrcweir 				}
1046cdf0e10cSrcweir 			}
1047cdf0e10cSrcweir 
1048cdf0e10cSrcweir 			// Alte Daten loeschen und Neue zuweisen
1049cdf0e10cSrcweir 			STRING_RELEASE((STRING_TYPE *)mpData);
1050cdf0e10cSrcweir 			mpData = pNewData;
1051cdf0e10cSrcweir 		}
1052cdf0e10cSrcweir 	}
1053cdf0e10cSrcweir 
1054cdf0e10cSrcweir 	return *this;
1055cdf0e10cSrcweir }
1056cdf0e10cSrcweir 
1057cdf0e10cSrcweir // -----------------------------------------------------------------------
1058cdf0e10cSrcweir 
Reverse()1059cdf0e10cSrcweir STRING& STRING::Reverse()
1060cdf0e10cSrcweir {
1061cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1062cdf0e10cSrcweir 
1063cdf0e10cSrcweir 	if ( !mpData->mnLen )
1064cdf0e10cSrcweir 		return *this;
1065cdf0e10cSrcweir 
1066cdf0e10cSrcweir 	// Daten kopieren, wenn noetig
1067cdf0e10cSrcweir 	ImplCopyData();
1068cdf0e10cSrcweir 
1069cdf0e10cSrcweir 	// Reverse
1070cdf0e10cSrcweir 	sal_Int32 nCount = mpData->mnLen / 2;
1071cdf0e10cSrcweir 	for ( sal_Int32 i = 0; i < nCount; ++i )
1072cdf0e10cSrcweir 	{
1073cdf0e10cSrcweir 		STRCODE cTemp = mpData->maStr[i];
1074cdf0e10cSrcweir 		mpData->maStr[i] = mpData->maStr[mpData->mnLen-i-1];
1075cdf0e10cSrcweir 		mpData->maStr[mpData->mnLen-i-1] = cTemp;
1076cdf0e10cSrcweir 	}
1077cdf0e10cSrcweir 
1078cdf0e10cSrcweir 	return *this;
1079cdf0e10cSrcweir }
1080cdf0e10cSrcweir 
1081cdf0e10cSrcweir // -----------------------------------------------------------------------
1082cdf0e10cSrcweir 
ToLowerAscii()1083cdf0e10cSrcweir STRING& STRING::ToLowerAscii()
1084cdf0e10cSrcweir {
1085cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1086cdf0e10cSrcweir 
1087cdf0e10cSrcweir 	sal_Int32 nIndex = 0;
1088cdf0e10cSrcweir 	sal_Int32 nLen = mpData->mnLen;
1089cdf0e10cSrcweir 	STRCODE*	pStr = mpData->maStr;
1090cdf0e10cSrcweir 	while ( nIndex < nLen )
1091cdf0e10cSrcweir 	{
1092cdf0e10cSrcweir 		// Ist das Zeichen zwischen 'A' und 'Z' dann umwandeln
1093cdf0e10cSrcweir 		if ( (*pStr >= 65) && (*pStr <= 90) )
1094cdf0e10cSrcweir 		{
1095cdf0e10cSrcweir 			// Daten kopieren, wenn noetig
1096cdf0e10cSrcweir 			pStr = ImplCopyStringData( pStr );
1097cdf0e10cSrcweir 			*pStr += 32;
1098cdf0e10cSrcweir 		}
1099cdf0e10cSrcweir 
1100cdf0e10cSrcweir 		++pStr,
1101cdf0e10cSrcweir 		++nIndex;
1102cdf0e10cSrcweir 	}
1103cdf0e10cSrcweir 
1104cdf0e10cSrcweir 	return *this;
1105cdf0e10cSrcweir }
1106cdf0e10cSrcweir 
1107cdf0e10cSrcweir // -----------------------------------------------------------------------
1108cdf0e10cSrcweir 
ToUpperAscii()1109cdf0e10cSrcweir STRING& STRING::ToUpperAscii()
1110cdf0e10cSrcweir {
1111cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1112cdf0e10cSrcweir 
1113cdf0e10cSrcweir 	sal_Int32 nIndex = 0;
1114cdf0e10cSrcweir 	sal_Int32 nLen = mpData->mnLen;
1115cdf0e10cSrcweir 	STRCODE*	pStr = mpData->maStr;
1116cdf0e10cSrcweir 	while ( nIndex < nLen )
1117cdf0e10cSrcweir 	{
1118cdf0e10cSrcweir 		// Ist das Zeichen zwischen 'a' und 'z' dann umwandeln
1119cdf0e10cSrcweir 		if ( (*pStr >= 97) && (*pStr <= 122) )
1120cdf0e10cSrcweir 		{
1121cdf0e10cSrcweir 			// Daten kopieren, wenn noetig
1122cdf0e10cSrcweir 			pStr = ImplCopyStringData( pStr );
1123cdf0e10cSrcweir 			*pStr -= 32;
1124cdf0e10cSrcweir 		}
1125cdf0e10cSrcweir 
1126cdf0e10cSrcweir 		++pStr,
1127cdf0e10cSrcweir 		++nIndex;
1128cdf0e10cSrcweir 	}
1129cdf0e10cSrcweir 
1130cdf0e10cSrcweir 	return *this;
1131cdf0e10cSrcweir }
1132cdf0e10cSrcweir 
1133cdf0e10cSrcweir // -----------------------------------------------------------------------
1134cdf0e10cSrcweir 
ConvertLineEnd(LineEnd eLineEnd)1135cdf0e10cSrcweir STRING& STRING::ConvertLineEnd( LineEnd eLineEnd )
1136cdf0e10cSrcweir {
1137cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1138cdf0e10cSrcweir 
1139cdf0e10cSrcweir 	// Zeilenumbrueche ermitteln und neue Laenge berechnen
1140cdf0e10cSrcweir 	sal_Bool			bConvert	= sal_False;			// Muss konvertiert werden
1141cdf0e10cSrcweir 	const STRCODE*	pStr		= mpData->maStr;	// damit es schneller geht
1142cdf0e10cSrcweir 	xub_StrLen		nLineEndLen = (eLineEnd == LINEEND_CRLF) ? 2 : 1;
1143cdf0e10cSrcweir 	xub_StrLen		nLen		= 0;				// Ziel-Laenge
1144cdf0e10cSrcweir 	xub_StrLen		i			= 0;				// Source-Zaehler
1145cdf0e10cSrcweir 
1146cdf0e10cSrcweir 	while ( i < mpData->mnLen )
1147cdf0e10cSrcweir 	{
1148cdf0e10cSrcweir 		// Bei \r oder \n gibt es neuen Zeilenumbruch
1149cdf0e10cSrcweir 		if ( (pStr[i] == _CR) || (pStr[i] == _LF) )
1150cdf0e10cSrcweir 		{
1151*4c90b644SPeter Kovacs 			if( nLen <= STRING_MAXLEN - nLineEndLen )
1152cdf0e10cSrcweir 				nLen = nLen + nLineEndLen;
1153*4c90b644SPeter Kovacs 			else
1154*4c90b644SPeter Kovacs 				nLen = STRING_MAXLEN;
1155cdf0e10cSrcweir 
1156cdf0e10cSrcweir 			// Wenn schon gesetzt, dann brauchen wir keine aufwendige Abfrage
1157cdf0e10cSrcweir 			if ( !bConvert )
1158cdf0e10cSrcweir 			{
1159cdf0e10cSrcweir 				// Muessen wir Konvertieren
1160cdf0e10cSrcweir 				if ( ((eLineEnd != LINEEND_LF) && (pStr[i] == _LF)) ||
1161cdf0e10cSrcweir 					 ((eLineEnd == LINEEND_CRLF) && (pStr[i+1] != _LF)) ||
1162cdf0e10cSrcweir 					 ((eLineEnd == LINEEND_LF) &&
1163cdf0e10cSrcweir 					  ((pStr[i] == _CR) || (pStr[i+1] == _CR))) ||
1164cdf0e10cSrcweir 					 ((eLineEnd == LINEEND_CR) &&
1165cdf0e10cSrcweir 					  ((pStr[i] == _LF) || (pStr[i+1] == _LF))) )
1166cdf0e10cSrcweir 					bConvert = sal_True;
1167cdf0e10cSrcweir 			}
1168cdf0e10cSrcweir 
1169cdf0e10cSrcweir 			// \r\n oder \n\r, dann Zeichen ueberspringen
1170cdf0e10cSrcweir 			if ( ((pStr[i+1] == _CR) || (pStr[i+1] == _LF)) &&
1171cdf0e10cSrcweir 				 (pStr[i] != pStr[i+1]) )
1172cdf0e10cSrcweir 				++i;
1173cdf0e10cSrcweir 		}
1174cdf0e10cSrcweir 		else
1175*4c90b644SPeter Kovacs 		{
1176*4c90b644SPeter Kovacs 			if( nLen < STRING_MAXLEN )
1177cdf0e10cSrcweir 			    ++nLen;
1178*4c90b644SPeter Kovacs 		}
1179cdf0e10cSrcweir 		++i;
1180cdf0e10cSrcweir 
1181cdf0e10cSrcweir 		// Wenn String zu lang, dann konvertieren wir nicht
1182cdf0e10cSrcweir 		if ( nLen >= STRING_MAXLEN )
1183cdf0e10cSrcweir 			return *this;
1184cdf0e10cSrcweir 	}
1185cdf0e10cSrcweir 
1186cdf0e10cSrcweir 	// Zeilenumbrueche konvertieren
1187cdf0e10cSrcweir 	if ( bConvert )
1188cdf0e10cSrcweir 	{
1189cdf0e10cSrcweir 		// Neuen String anlegen
1190cdf0e10cSrcweir 		STRINGDATA* pNewData = ImplAllocData( nLen );
1191cdf0e10cSrcweir 		xub_StrLen	j = 0;
1192cdf0e10cSrcweir 		i = 0;
1193cdf0e10cSrcweir 		while ( i < mpData->mnLen )
1194cdf0e10cSrcweir 		{
1195cdf0e10cSrcweir 			// Bei \r oder \n gibt es neuen Zeilenumbruch
1196cdf0e10cSrcweir 			if ( (pStr[i] == _CR) || (pStr[i] == _LF) )
1197cdf0e10cSrcweir 			{
1198cdf0e10cSrcweir 				if ( eLineEnd == LINEEND_CRLF )
1199cdf0e10cSrcweir 				{
1200cdf0e10cSrcweir 					pNewData->maStr[j]	 = _CR;
1201cdf0e10cSrcweir 					pNewData->maStr[j+1] = _LF;
1202cdf0e10cSrcweir 					j += 2;
1203cdf0e10cSrcweir 				}
1204cdf0e10cSrcweir 				else
1205cdf0e10cSrcweir 				{
1206cdf0e10cSrcweir 					if ( eLineEnd == LINEEND_CR )
1207cdf0e10cSrcweir 						pNewData->maStr[j] = _CR;
1208cdf0e10cSrcweir 					else
1209cdf0e10cSrcweir 						pNewData->maStr[j] = _LF;
1210cdf0e10cSrcweir 					++j;
1211cdf0e10cSrcweir 				}
1212cdf0e10cSrcweir 
1213cdf0e10cSrcweir 				if ( ((pStr[i+1] == _CR) || (pStr[i+1] == _LF)) &&
1214cdf0e10cSrcweir 					 (pStr[i] != pStr[i+1]) )
1215cdf0e10cSrcweir 					++i;
1216cdf0e10cSrcweir 			}
1217cdf0e10cSrcweir 			else
1218cdf0e10cSrcweir 			{
1219cdf0e10cSrcweir 				pNewData->maStr[j] = mpData->maStr[i];
1220cdf0e10cSrcweir 				++j;
1221cdf0e10cSrcweir 			}
1222cdf0e10cSrcweir 
1223cdf0e10cSrcweir 			++i;
1224cdf0e10cSrcweir 		}
1225cdf0e10cSrcweir 
1226cdf0e10cSrcweir 		// Alte Daten loeschen und Neue zuweisen
1227cdf0e10cSrcweir 		STRING_RELEASE((STRING_TYPE *)mpData);
1228cdf0e10cSrcweir 		mpData = pNewData;
1229cdf0e10cSrcweir 	}
1230cdf0e10cSrcweir 
1231cdf0e10cSrcweir 	return *this;
1232cdf0e10cSrcweir }
1233cdf0e10cSrcweir 
1234cdf0e10cSrcweir // -----------------------------------------------------------------------
1235cdf0e10cSrcweir 
CompareTo(const STRING & rStr,xub_StrLen nLen) const1236cdf0e10cSrcweir StringCompare STRING::CompareTo( const STRING& rStr, xub_StrLen nLen ) const
1237cdf0e10cSrcweir {
1238cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1239cdf0e10cSrcweir 	DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING );
1240cdf0e10cSrcweir 
1241cdf0e10cSrcweir 	// Auf Gleichheit der Pointer testen
1242cdf0e10cSrcweir 	if ( mpData == rStr.mpData )
1243cdf0e10cSrcweir 		return COMPARE_EQUAL;
1244cdf0e10cSrcweir 
1245cdf0e10cSrcweir 	// Maximale Laenge ermitteln
1246cdf0e10cSrcweir 	if ( mpData->mnLen < nLen )
1247cdf0e10cSrcweir 		nLen = static_cast< xub_StrLen >(mpData->mnLen+1);
1248cdf0e10cSrcweir 	if ( rStr.mpData->mnLen < nLen )
1249cdf0e10cSrcweir 		nLen = static_cast< xub_StrLen >(rStr.mpData->mnLen+1);
1250cdf0e10cSrcweir 
1251cdf0e10cSrcweir 	// String vergleichen
1252cdf0e10cSrcweir 	sal_Int32 nCompare = ImplStringCompareWithoutZero( mpData->maStr, rStr.mpData->maStr, nLen );
1253cdf0e10cSrcweir 
1254cdf0e10cSrcweir 	// Rueckgabewert anpassen
1255cdf0e10cSrcweir 	if ( nCompare == 0 )
1256cdf0e10cSrcweir 		return COMPARE_EQUAL;
1257cdf0e10cSrcweir 	else if ( nCompare < 0 )
1258cdf0e10cSrcweir 		return COMPARE_LESS;
1259cdf0e10cSrcweir 	else
1260cdf0e10cSrcweir 		return COMPARE_GREATER;
1261cdf0e10cSrcweir }
1262cdf0e10cSrcweir 
1263cdf0e10cSrcweir // -----------------------------------------------------------------------
1264cdf0e10cSrcweir 
CompareTo(const STRCODE * pCharStr,xub_StrLen nLen) const1265cdf0e10cSrcweir StringCompare STRING::CompareTo( const STRCODE* pCharStr, xub_StrLen nLen ) const
1266cdf0e10cSrcweir {
1267cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1268cdf0e10cSrcweir 
1269cdf0e10cSrcweir 	// String vergleichen
1270cdf0e10cSrcweir 	sal_Int32 nCompare = ImplStringCompare( mpData->maStr, pCharStr, nLen );
1271cdf0e10cSrcweir 
1272cdf0e10cSrcweir 	// Rueckgabewert anpassen
1273cdf0e10cSrcweir 	if ( nCompare == 0 )
1274cdf0e10cSrcweir 		return COMPARE_EQUAL;
1275cdf0e10cSrcweir 	else if ( nCompare < 0 )
1276cdf0e10cSrcweir 		return COMPARE_LESS;
1277cdf0e10cSrcweir 	else
1278cdf0e10cSrcweir 		return COMPARE_GREATER;
1279cdf0e10cSrcweir }
1280cdf0e10cSrcweir 
1281cdf0e10cSrcweir // -----------------------------------------------------------------------
1282cdf0e10cSrcweir 
CompareIgnoreCaseToAscii(const STRING & rStr,xub_StrLen nLen) const1283cdf0e10cSrcweir StringCompare STRING::CompareIgnoreCaseToAscii( const STRING& rStr,
1284cdf0e10cSrcweir 												xub_StrLen nLen ) const
1285cdf0e10cSrcweir {
1286cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1287cdf0e10cSrcweir 	DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING );
1288cdf0e10cSrcweir 
1289cdf0e10cSrcweir 	// Auf Gleichheit der Pointer testen
1290cdf0e10cSrcweir 	if ( mpData == rStr.mpData )
1291cdf0e10cSrcweir 		return COMPARE_EQUAL;
1292cdf0e10cSrcweir 
1293cdf0e10cSrcweir 	// Maximale Laenge ermitteln
1294cdf0e10cSrcweir 	if ( mpData->mnLen < nLen )
1295cdf0e10cSrcweir 		nLen = static_cast< xub_StrLen >(mpData->mnLen+1);
1296cdf0e10cSrcweir 	if ( rStr.mpData->mnLen < nLen )
1297cdf0e10cSrcweir 		nLen = static_cast< xub_StrLen >(rStr.mpData->mnLen+1);
1298cdf0e10cSrcweir 
1299cdf0e10cSrcweir 	// String vergleichen
1300cdf0e10cSrcweir 	sal_Int32 nCompare = ImplStringICompareWithoutZero( mpData->maStr, rStr.mpData->maStr, nLen );
1301cdf0e10cSrcweir 
1302cdf0e10cSrcweir 	// Rueckgabewert anpassen
1303cdf0e10cSrcweir 	if ( nCompare == 0 )
1304cdf0e10cSrcweir 		return COMPARE_EQUAL;
1305cdf0e10cSrcweir 	else if ( nCompare < 0 )
1306cdf0e10cSrcweir 		return COMPARE_LESS;
1307cdf0e10cSrcweir 	else
1308cdf0e10cSrcweir 		return COMPARE_GREATER;
1309cdf0e10cSrcweir }
1310cdf0e10cSrcweir 
1311cdf0e10cSrcweir // -----------------------------------------------------------------------
1312cdf0e10cSrcweir 
CompareIgnoreCaseToAscii(const STRCODE * pCharStr,xub_StrLen nLen) const1313cdf0e10cSrcweir StringCompare STRING::CompareIgnoreCaseToAscii( const STRCODE* pCharStr,
1314cdf0e10cSrcweir 												xub_StrLen nLen ) const
1315cdf0e10cSrcweir {
1316cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1317cdf0e10cSrcweir 
1318cdf0e10cSrcweir 	// String vergleichen
1319cdf0e10cSrcweir 	sal_Int32 nCompare = ImplStringICompare( mpData->maStr, pCharStr, nLen );
1320cdf0e10cSrcweir 
1321cdf0e10cSrcweir 	// Rueckgabewert anpassen
1322cdf0e10cSrcweir 	if ( nCompare == 0 )
1323cdf0e10cSrcweir 		return COMPARE_EQUAL;
1324cdf0e10cSrcweir 	else if ( nCompare < 0 )
1325cdf0e10cSrcweir 		return COMPARE_LESS;
1326cdf0e10cSrcweir 	else
1327cdf0e10cSrcweir 		return COMPARE_GREATER;
1328cdf0e10cSrcweir }
1329cdf0e10cSrcweir 
1330cdf0e10cSrcweir // -----------------------------------------------------------------------
1331cdf0e10cSrcweir 
Equals(const STRING & rStr) const1332cdf0e10cSrcweir sal_Bool STRING::Equals( const STRING& rStr ) const
1333cdf0e10cSrcweir {
1334cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1335cdf0e10cSrcweir 	DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING );
1336cdf0e10cSrcweir 
1337cdf0e10cSrcweir 	// Sind die Daten gleich
1338cdf0e10cSrcweir 	if ( mpData == rStr.mpData )
1339cdf0e10cSrcweir 		return sal_True;
1340cdf0e10cSrcweir 
1341cdf0e10cSrcweir 	// Gleiche Laenge
1342cdf0e10cSrcweir 	if ( mpData->mnLen != rStr.mpData->mnLen )
1343cdf0e10cSrcweir 		return sal_False;
1344cdf0e10cSrcweir 
1345cdf0e10cSrcweir 	// String vergleichen
1346cdf0e10cSrcweir 	return (ImplStringCompareWithoutZero( mpData->maStr, rStr.mpData->maStr, mpData->mnLen ) == 0);
1347cdf0e10cSrcweir }
1348cdf0e10cSrcweir 
1349cdf0e10cSrcweir // -----------------------------------------------------------------------
1350cdf0e10cSrcweir 
Equals(const STRCODE * pCharStr) const1351cdf0e10cSrcweir sal_Bool STRING::Equals( const STRCODE* pCharStr ) const
1352cdf0e10cSrcweir {
1353cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1354cdf0e10cSrcweir 
1355cdf0e10cSrcweir 	return (ImplStringCompare( mpData->maStr, pCharStr ) == 0);
1356cdf0e10cSrcweir }
1357cdf0e10cSrcweir 
1358cdf0e10cSrcweir // -----------------------------------------------------------------------
1359cdf0e10cSrcweir 
EqualsIgnoreCaseAscii(const STRING & rStr) const1360cdf0e10cSrcweir sal_Bool STRING::EqualsIgnoreCaseAscii( const STRING& rStr ) const
1361cdf0e10cSrcweir {
1362cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1363cdf0e10cSrcweir 	DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING );
1364cdf0e10cSrcweir 
1365cdf0e10cSrcweir 	// Sind die Daten gleich
1366cdf0e10cSrcweir 	if ( mpData == rStr.mpData )
1367cdf0e10cSrcweir 		return sal_True;
1368cdf0e10cSrcweir 
1369cdf0e10cSrcweir 	// Gleiche Laenge
1370cdf0e10cSrcweir 	if ( mpData->mnLen != rStr.mpData->mnLen )
1371cdf0e10cSrcweir 		return sal_False;
1372cdf0e10cSrcweir 
1373cdf0e10cSrcweir 	// String vergleichen
1374cdf0e10cSrcweir 	return (ImplStringICompareWithoutZero( mpData->maStr, rStr.mpData->maStr, mpData->mnLen ) == 0);
1375cdf0e10cSrcweir }
1376cdf0e10cSrcweir 
1377cdf0e10cSrcweir // -----------------------------------------------------------------------
1378cdf0e10cSrcweir 
EqualsIgnoreCaseAscii(const STRCODE * pCharStr) const1379cdf0e10cSrcweir sal_Bool STRING::EqualsIgnoreCaseAscii( const STRCODE* pCharStr ) const
1380cdf0e10cSrcweir {
1381cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1382cdf0e10cSrcweir 
1383cdf0e10cSrcweir 	return (ImplStringICompare( mpData->maStr, pCharStr ) == 0);
1384cdf0e10cSrcweir }
1385cdf0e10cSrcweir 
1386cdf0e10cSrcweir // -----------------------------------------------------------------------
1387cdf0e10cSrcweir 
Equals(const STRING & rStr,xub_StrLen nIndex,xub_StrLen nLen) const1388cdf0e10cSrcweir sal_Bool STRING::Equals( const STRING& rStr, xub_StrLen nIndex, xub_StrLen nLen ) const
1389cdf0e10cSrcweir {
1390cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1391cdf0e10cSrcweir 	DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING );
1392cdf0e10cSrcweir 
1393cdf0e10cSrcweir 	// Are there enough codes for comparing?
1394cdf0e10cSrcweir 	if ( nIndex > mpData->mnLen )
1395cdf0e10cSrcweir 		return (rStr.mpData->mnLen == 0);
1396cdf0e10cSrcweir 	sal_Int32 nMaxLen = mpData->mnLen-nIndex;
1397cdf0e10cSrcweir 	if ( nMaxLen < nLen )
1398cdf0e10cSrcweir 	{
1399cdf0e10cSrcweir 		if ( rStr.mpData->mnLen != nMaxLen )
1400cdf0e10cSrcweir 			return sal_False;
1401cdf0e10cSrcweir 		nLen = static_cast< xub_StrLen >(nMaxLen);
1402cdf0e10cSrcweir 	}
1403cdf0e10cSrcweir 
1404cdf0e10cSrcweir 	// String vergleichen
1405cdf0e10cSrcweir 	return (ImplStringCompareWithoutZero( mpData->maStr+nIndex, rStr.mpData->maStr, nLen ) == 0);
1406cdf0e10cSrcweir }
1407cdf0e10cSrcweir 
1408cdf0e10cSrcweir // -----------------------------------------------------------------------
1409cdf0e10cSrcweir 
Equals(const STRCODE * pCharStr,xub_StrLen nIndex,xub_StrLen nLen) const1410cdf0e10cSrcweir sal_Bool STRING::Equals( const STRCODE* pCharStr, xub_StrLen nIndex, xub_StrLen nLen ) const
1411cdf0e10cSrcweir {
1412cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1413cdf0e10cSrcweir 
1414cdf0e10cSrcweir 	// Are there enough codes for comparing?
1415cdf0e10cSrcweir 	if ( nIndex > mpData->mnLen )
1416cdf0e10cSrcweir 		return (*pCharStr == 0);
1417cdf0e10cSrcweir 
1418cdf0e10cSrcweir 	return (ImplStringCompare( mpData->maStr+nIndex, pCharStr, nLen ) == 0);
1419cdf0e10cSrcweir }
1420cdf0e10cSrcweir 
1421cdf0e10cSrcweir // -----------------------------------------------------------------------
1422cdf0e10cSrcweir 
EqualsIgnoreCaseAscii(const STRING & rStr,xub_StrLen nIndex,xub_StrLen nLen) const1423cdf0e10cSrcweir sal_Bool STRING::EqualsIgnoreCaseAscii( const STRING& rStr, xub_StrLen nIndex, xub_StrLen nLen ) const
1424cdf0e10cSrcweir {
1425cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1426cdf0e10cSrcweir 	DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING );
1427cdf0e10cSrcweir 
1428cdf0e10cSrcweir 	// Are there enough codes for comparing?
1429cdf0e10cSrcweir 	if ( nIndex > mpData->mnLen )
1430cdf0e10cSrcweir 		return (rStr.mpData->mnLen == 0);
1431cdf0e10cSrcweir 	sal_Int32 nMaxLen = mpData->mnLen-nIndex;
1432cdf0e10cSrcweir 	if ( nMaxLen < nLen )
1433cdf0e10cSrcweir 	{
1434cdf0e10cSrcweir 		if ( rStr.mpData->mnLen != nMaxLen )
1435cdf0e10cSrcweir 			return sal_False;
1436cdf0e10cSrcweir 		nLen = static_cast< xub_StrLen >(nMaxLen);
1437cdf0e10cSrcweir 	}
1438cdf0e10cSrcweir 
1439cdf0e10cSrcweir 	// String vergleichen
1440cdf0e10cSrcweir 	return (ImplStringICompareWithoutZero( mpData->maStr+nIndex, rStr.mpData->maStr, nLen ) == 0);
1441cdf0e10cSrcweir }
1442cdf0e10cSrcweir 
1443cdf0e10cSrcweir // -----------------------------------------------------------------------
1444cdf0e10cSrcweir 
EqualsIgnoreCaseAscii(const STRCODE * pCharStr,xub_StrLen nIndex,xub_StrLen nLen) const1445cdf0e10cSrcweir sal_Bool STRING::EqualsIgnoreCaseAscii( const STRCODE* pCharStr, xub_StrLen nIndex, xub_StrLen nLen ) const
1446cdf0e10cSrcweir {
1447cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1448cdf0e10cSrcweir 
1449cdf0e10cSrcweir 	// Are there enough codes for comparing?
1450cdf0e10cSrcweir 	if ( nIndex > mpData->mnLen )
1451cdf0e10cSrcweir 		return (*pCharStr == 0);
1452cdf0e10cSrcweir 
1453cdf0e10cSrcweir 	return (ImplStringICompare( mpData->maStr+nIndex, pCharStr, nLen ) == 0);
1454cdf0e10cSrcweir }
1455cdf0e10cSrcweir 
1456cdf0e10cSrcweir // -----------------------------------------------------------------------
1457cdf0e10cSrcweir 
Match(const STRING & rStr) const1458cdf0e10cSrcweir xub_StrLen STRING::Match( const STRING& rStr ) const
1459cdf0e10cSrcweir {
1460cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1461cdf0e10cSrcweir 	DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING );
1462cdf0e10cSrcweir 
1463cdf0e10cSrcweir 	// Ist dieser String leer
1464cdf0e10cSrcweir 	if ( !mpData->mnLen )
1465cdf0e10cSrcweir 		return STRING_MATCH;
1466cdf0e10cSrcweir 
1467cdf0e10cSrcweir 	// Suche bis Stringende nach dem ersten nicht uebereinstimmenden Zeichen
1468cdf0e10cSrcweir 	const STRCODE*	pStr1 = mpData->maStr;
1469cdf0e10cSrcweir 	const STRCODE*	pStr2 = rStr.mpData->maStr;
1470cdf0e10cSrcweir 	xub_StrLen		i = 0;
1471cdf0e10cSrcweir 	while ( i < mpData->mnLen )
1472cdf0e10cSrcweir 	{
1473cdf0e10cSrcweir 		// Stimmt das Zeichen nicht ueberein, dann abbrechen
1474cdf0e10cSrcweir 		if ( *pStr1 != *pStr2 )
1475cdf0e10cSrcweir 			return i;
1476cdf0e10cSrcweir 		++pStr1,
1477cdf0e10cSrcweir 		++pStr2,
1478cdf0e10cSrcweir 		++i;
1479cdf0e10cSrcweir 	}
1480cdf0e10cSrcweir 
1481cdf0e10cSrcweir 	return STRING_MATCH;
1482cdf0e10cSrcweir }
1483cdf0e10cSrcweir 
1484cdf0e10cSrcweir // -----------------------------------------------------------------------
1485cdf0e10cSrcweir 
Match(const STRCODE * pCharStr) const1486cdf0e10cSrcweir xub_StrLen STRING::Match( const STRCODE* pCharStr ) const
1487cdf0e10cSrcweir {
1488cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1489cdf0e10cSrcweir 
1490cdf0e10cSrcweir 	// Ist dieser String leer
1491cdf0e10cSrcweir 	if ( !mpData->mnLen )
1492cdf0e10cSrcweir 		return STRING_MATCH;
1493cdf0e10cSrcweir 
1494cdf0e10cSrcweir 	// Suche bis Stringende nach dem ersten nicht uebereinstimmenden Zeichen
1495cdf0e10cSrcweir 	const STRCODE*	pStr = mpData->maStr;
1496cdf0e10cSrcweir 	xub_StrLen		i = 0;
1497cdf0e10cSrcweir 	while ( i < mpData->mnLen )
1498cdf0e10cSrcweir 	{
1499cdf0e10cSrcweir 		// Stimmt das Zeichen nicht ueberein, dann abbrechen
1500cdf0e10cSrcweir 		if ( *pStr != *pCharStr )
1501cdf0e10cSrcweir 			return i;
1502cdf0e10cSrcweir 		++pStr,
1503cdf0e10cSrcweir 		++pCharStr,
1504cdf0e10cSrcweir 		++i;
1505cdf0e10cSrcweir 	}
1506cdf0e10cSrcweir 
1507cdf0e10cSrcweir 	return STRING_MATCH;
1508cdf0e10cSrcweir }
1509cdf0e10cSrcweir 
1510cdf0e10cSrcweir // -----------------------------------------------------------------------
1511cdf0e10cSrcweir 
Search(STRCODE c,xub_StrLen nIndex) const1512cdf0e10cSrcweir xub_StrLen STRING::Search( STRCODE c, xub_StrLen nIndex ) const
1513cdf0e10cSrcweir {
1514cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1515cdf0e10cSrcweir 
1516cdf0e10cSrcweir 	sal_Int32		nLen = mpData->mnLen;
1517cdf0e10cSrcweir 	const STRCODE*	pStr = mpData->maStr;
1518cdf0e10cSrcweir 	pStr += nIndex;
1519cdf0e10cSrcweir 	while ( nIndex < nLen )
1520cdf0e10cSrcweir 	{
1521cdf0e10cSrcweir 		if ( *pStr == c )
1522cdf0e10cSrcweir 			return nIndex;
1523cdf0e10cSrcweir 		++pStr,
1524cdf0e10cSrcweir 		++nIndex;
1525cdf0e10cSrcweir 	}
1526cdf0e10cSrcweir 
1527cdf0e10cSrcweir 	return STRING_NOTFOUND;
1528cdf0e10cSrcweir }
1529cdf0e10cSrcweir 
1530cdf0e10cSrcweir // -----------------------------------------------------------------------
1531cdf0e10cSrcweir 
Search(const STRING & rStr,xub_StrLen nIndex) const1532cdf0e10cSrcweir xub_StrLen STRING::Search( const STRING& rStr, xub_StrLen nIndex ) const
1533cdf0e10cSrcweir {
1534cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1535cdf0e10cSrcweir 	DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING );
1536cdf0e10cSrcweir 
1537cdf0e10cSrcweir 	sal_Int32 nLen = mpData->mnLen;
1538cdf0e10cSrcweir 	sal_Int32 nStrLen = rStr.mpData->mnLen;
1539cdf0e10cSrcweir 
1540cdf0e10cSrcweir 	// Falls die Laenge des uebergebenen Strings 0 ist oder der Index
1541cdf0e10cSrcweir 	// hinter dem String liegt, dann wurde der String nicht gefunden
1542cdf0e10cSrcweir 	if ( !nStrLen || (nIndex >= nLen) )
1543cdf0e10cSrcweir 		return STRING_NOTFOUND;
1544cdf0e10cSrcweir 
1545cdf0e10cSrcweir 	const STRCODE* pStr1 = mpData->maStr;
1546cdf0e10cSrcweir 	pStr1 += nIndex;
1547cdf0e10cSrcweir 
1548cdf0e10cSrcweir 	if ( nStrLen == 1 )
1549cdf0e10cSrcweir 	{
1550cdf0e10cSrcweir 		STRCODE cSearch = rStr.mpData->maStr[0];
1551cdf0e10cSrcweir 		while ( nIndex < nLen )
1552cdf0e10cSrcweir 		{
1553cdf0e10cSrcweir 			if ( *pStr1 == cSearch )
1554cdf0e10cSrcweir 				return nIndex;
1555cdf0e10cSrcweir 			++pStr1,
1556cdf0e10cSrcweir 			++nIndex;
1557cdf0e10cSrcweir 		}
1558cdf0e10cSrcweir 	}
1559cdf0e10cSrcweir 	else
1560cdf0e10cSrcweir 	{
1561cdf0e10cSrcweir 		const STRCODE* pStr2 = rStr.mpData->maStr;
1562cdf0e10cSrcweir 
1563cdf0e10cSrcweir 		// Nur innerhalb des Strings suchen
1564cdf0e10cSrcweir 		while ( nLen - nIndex >= nStrLen )
1565cdf0e10cSrcweir 		{
1566cdf0e10cSrcweir 			// Stimmt der String ueberein
1567cdf0e10cSrcweir 			if ( ImplStringCompareWithoutZero( pStr1, pStr2, nStrLen ) == 0 )
1568cdf0e10cSrcweir 				return nIndex;
1569cdf0e10cSrcweir 			++pStr1,
1570cdf0e10cSrcweir 			++nIndex;
1571cdf0e10cSrcweir 		}
1572cdf0e10cSrcweir 	}
1573cdf0e10cSrcweir 
1574cdf0e10cSrcweir 	return STRING_NOTFOUND;
1575cdf0e10cSrcweir }
1576cdf0e10cSrcweir 
1577cdf0e10cSrcweir // -----------------------------------------------------------------------
1578cdf0e10cSrcweir 
Search(const STRCODE * pCharStr,xub_StrLen nIndex) const1579cdf0e10cSrcweir xub_StrLen STRING::Search( const STRCODE* pCharStr, xub_StrLen nIndex ) const
1580cdf0e10cSrcweir {
1581cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1582cdf0e10cSrcweir 
1583cdf0e10cSrcweir 	sal_Int32 nLen = mpData->mnLen;
1584cdf0e10cSrcweir 	xub_StrLen nStrLen	= ImplStringLen( pCharStr );
1585cdf0e10cSrcweir 
1586cdf0e10cSrcweir 	// Falls die Laenge des uebergebenen Strings 0 ist oder der Index
1587cdf0e10cSrcweir 	// hinter dem String liegt, dann wurde der String nicht gefunden
1588cdf0e10cSrcweir 	if ( !nStrLen || (nIndex >= nLen) )
1589cdf0e10cSrcweir 		return STRING_NOTFOUND;
1590cdf0e10cSrcweir 
1591cdf0e10cSrcweir 	const STRCODE* pStr = mpData->maStr;
1592cdf0e10cSrcweir 	pStr += nIndex;
1593cdf0e10cSrcweir 
1594cdf0e10cSrcweir 	if ( nStrLen == 1 )
1595cdf0e10cSrcweir 	{
1596cdf0e10cSrcweir 		STRCODE cSearch = *pCharStr;
1597cdf0e10cSrcweir 		while ( nIndex < nLen )
1598cdf0e10cSrcweir 		{
1599cdf0e10cSrcweir 			if ( *pStr == cSearch )
1600cdf0e10cSrcweir 				return nIndex;
1601cdf0e10cSrcweir 			++pStr,
1602cdf0e10cSrcweir 			++nIndex;
1603cdf0e10cSrcweir 		}
1604cdf0e10cSrcweir 	}
1605cdf0e10cSrcweir 	else
1606cdf0e10cSrcweir 	{
1607cdf0e10cSrcweir 		// Nur innerhalb des Strings suchen
1608cdf0e10cSrcweir 		while ( nLen - nIndex >= nStrLen )
1609cdf0e10cSrcweir 		{
1610cdf0e10cSrcweir 			// Stimmt der String ueberein
1611cdf0e10cSrcweir 			if ( ImplStringCompareWithoutZero( pStr, pCharStr, nStrLen ) == 0 )
1612cdf0e10cSrcweir 				return nIndex;
1613cdf0e10cSrcweir 			++pStr,
1614cdf0e10cSrcweir 			++nIndex;
1615cdf0e10cSrcweir 		}
1616cdf0e10cSrcweir 	}
1617cdf0e10cSrcweir 
1618cdf0e10cSrcweir 	return STRING_NOTFOUND;
1619cdf0e10cSrcweir }
1620cdf0e10cSrcweir 
1621cdf0e10cSrcweir // -----------------------------------------------------------------------
1622cdf0e10cSrcweir 
SearchBackward(STRCODE c,xub_StrLen nIndex) const1623cdf0e10cSrcweir xub_StrLen STRING::SearchBackward( STRCODE c, xub_StrLen nIndex ) const
1624cdf0e10cSrcweir {
1625cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1626cdf0e10cSrcweir 
1627cdf0e10cSrcweir 	if ( nIndex > mpData->mnLen )
1628cdf0e10cSrcweir 		nIndex = (xub_StrLen)mpData->mnLen;
1629cdf0e10cSrcweir 
1630cdf0e10cSrcweir 	const STRCODE* pStr = mpData->maStr;
1631cdf0e10cSrcweir 	pStr += nIndex;
1632cdf0e10cSrcweir 
1633cdf0e10cSrcweir 	while ( nIndex )
1634cdf0e10cSrcweir 	{
1635cdf0e10cSrcweir 		nIndex--;
1636cdf0e10cSrcweir 		pStr--;
1637cdf0e10cSrcweir 		if ( *pStr == c )
1638cdf0e10cSrcweir 			return nIndex;
1639cdf0e10cSrcweir 	}
1640cdf0e10cSrcweir 
1641cdf0e10cSrcweir 	return STRING_NOTFOUND;
1642cdf0e10cSrcweir }
1643cdf0e10cSrcweir 
1644cdf0e10cSrcweir // -----------------------------------------------------------------------
1645cdf0e10cSrcweir 
SearchChar(const STRCODE * pChars,xub_StrLen nIndex) const1646cdf0e10cSrcweir xub_StrLen STRING::SearchChar( const STRCODE* pChars, xub_StrLen nIndex ) const
1647cdf0e10cSrcweir {
1648cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1649cdf0e10cSrcweir 
1650cdf0e10cSrcweir 	sal_Int32		nLen = mpData->mnLen;
1651cdf0e10cSrcweir 	const STRCODE*	pStr = mpData->maStr;
1652cdf0e10cSrcweir 	pStr += nIndex;
1653cdf0e10cSrcweir 	while ( nIndex < nLen )
1654cdf0e10cSrcweir 	{
1655cdf0e10cSrcweir 		STRCODE 		c = *pStr;
1656cdf0e10cSrcweir 		const STRCODE*	pCompStr = pChars;
1657cdf0e10cSrcweir 		while ( *pCompStr )
1658cdf0e10cSrcweir 		{
1659cdf0e10cSrcweir 			if ( *pCompStr == c )
1660cdf0e10cSrcweir 				return nIndex;
1661cdf0e10cSrcweir 			++pCompStr;
1662cdf0e10cSrcweir 		}
1663cdf0e10cSrcweir 		++pStr,
1664cdf0e10cSrcweir 		++nIndex;
1665cdf0e10cSrcweir 	}
1666cdf0e10cSrcweir 
1667cdf0e10cSrcweir 	return STRING_NOTFOUND;
1668cdf0e10cSrcweir }
1669cdf0e10cSrcweir 
1670cdf0e10cSrcweir // -----------------------------------------------------------------------
1671cdf0e10cSrcweir 
SearchCharBackward(const STRCODE * pChars,xub_StrLen nIndex) const1672cdf0e10cSrcweir xub_StrLen STRING::SearchCharBackward( const STRCODE* pChars, xub_StrLen nIndex ) const
1673cdf0e10cSrcweir {
1674cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1675cdf0e10cSrcweir 
1676cdf0e10cSrcweir 	if ( nIndex > mpData->mnLen )
1677cdf0e10cSrcweir 		nIndex = (xub_StrLen)mpData->mnLen;
1678cdf0e10cSrcweir 
1679cdf0e10cSrcweir 	const STRCODE* pStr = mpData->maStr;
1680cdf0e10cSrcweir 	pStr += nIndex;
1681cdf0e10cSrcweir 
1682cdf0e10cSrcweir 	while ( nIndex )
1683cdf0e10cSrcweir 	{
1684cdf0e10cSrcweir 		nIndex--;
1685cdf0e10cSrcweir 		pStr--;
1686cdf0e10cSrcweir 
1687cdf0e10cSrcweir 		STRCODE 		c =*pStr;
1688cdf0e10cSrcweir 		const STRCODE*	pCompStr = pChars;
1689cdf0e10cSrcweir 		while ( *pCompStr )
1690cdf0e10cSrcweir 		{
1691cdf0e10cSrcweir 			if ( *pCompStr == c )
1692cdf0e10cSrcweir 				return nIndex;
1693cdf0e10cSrcweir 			++pCompStr;
1694cdf0e10cSrcweir 		}
1695cdf0e10cSrcweir 	}
1696cdf0e10cSrcweir 
1697cdf0e10cSrcweir 	return STRING_NOTFOUND;
1698cdf0e10cSrcweir }
1699cdf0e10cSrcweir 
1700cdf0e10cSrcweir // -----------------------------------------------------------------------
1701cdf0e10cSrcweir 
SearchAndReplace(STRCODE c,STRCODE cRep,xub_StrLen nIndex)1702cdf0e10cSrcweir xub_StrLen STRING::SearchAndReplace( STRCODE c, STRCODE cRep, xub_StrLen nIndex )
1703cdf0e10cSrcweir {
1704cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1705cdf0e10cSrcweir 
1706cdf0e10cSrcweir 	sal_Int32		nLen = mpData->mnLen;
1707cdf0e10cSrcweir 	const STRCODE*	pStr = mpData->maStr;
1708cdf0e10cSrcweir 	pStr += nIndex;
1709cdf0e10cSrcweir 	while ( nIndex < nLen )
1710cdf0e10cSrcweir 	{
1711cdf0e10cSrcweir 		if ( *pStr == c )
1712cdf0e10cSrcweir 		{
1713cdf0e10cSrcweir 			ImplCopyData();
1714cdf0e10cSrcweir 			mpData->maStr[nIndex] = cRep;
1715cdf0e10cSrcweir 			return nIndex;
1716cdf0e10cSrcweir 		}
1717cdf0e10cSrcweir 		++pStr,
1718cdf0e10cSrcweir 		++nIndex;
1719cdf0e10cSrcweir 	}
1720cdf0e10cSrcweir 
1721cdf0e10cSrcweir 	return STRING_NOTFOUND;
1722cdf0e10cSrcweir }
1723cdf0e10cSrcweir 
1724cdf0e10cSrcweir // -----------------------------------------------------------------------
1725cdf0e10cSrcweir 
SearchAndReplace(const STRING & rStr,const STRING & rRepStr,xub_StrLen nIndex)1726cdf0e10cSrcweir xub_StrLen STRING::SearchAndReplace( const STRING& rStr, const STRING& rRepStr,
1727cdf0e10cSrcweir 									 xub_StrLen nIndex )
1728cdf0e10cSrcweir {
1729cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1730cdf0e10cSrcweir 	DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING );
1731cdf0e10cSrcweir 	DBG_CHKOBJ( &rRepStr, STRING, DBGCHECKSTRING );
1732cdf0e10cSrcweir 
1733cdf0e10cSrcweir 	xub_StrLen nSPos = Search( rStr, nIndex );
1734cdf0e10cSrcweir 	if ( nSPos != STRING_NOTFOUND )
1735cdf0e10cSrcweir 		Replace( nSPos, rStr.Len(), rRepStr );
1736cdf0e10cSrcweir 
1737cdf0e10cSrcweir 	return nSPos;
1738cdf0e10cSrcweir }
1739cdf0e10cSrcweir 
1740cdf0e10cSrcweir // -----------------------------------------------------------------------
1741cdf0e10cSrcweir 
SearchAndReplace(const STRCODE * pCharStr,const STRING & rRepStr,xub_StrLen nIndex)1742cdf0e10cSrcweir xub_StrLen STRING::SearchAndReplace( const STRCODE* pCharStr, const STRING& rRepStr,
1743cdf0e10cSrcweir 									 xub_StrLen nIndex )
1744cdf0e10cSrcweir {
1745cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1746cdf0e10cSrcweir 	DBG_CHKOBJ( &rRepStr, STRING, DBGCHECKSTRING );
1747cdf0e10cSrcweir 
1748cdf0e10cSrcweir 	xub_StrLen nSPos = Search( pCharStr, nIndex );
1749cdf0e10cSrcweir 	if ( nSPos != STRING_NOTFOUND )
1750cdf0e10cSrcweir 		Replace( nSPos, ImplStringLen( pCharStr ), rRepStr );
1751cdf0e10cSrcweir 
1752cdf0e10cSrcweir 	return nSPos;
1753cdf0e10cSrcweir }
1754cdf0e10cSrcweir 
1755cdf0e10cSrcweir // -----------------------------------------------------------------------
1756cdf0e10cSrcweir 
SearchAndReplaceAll(STRCODE c,STRCODE cRep)1757cdf0e10cSrcweir void STRING::SearchAndReplaceAll( STRCODE c, STRCODE cRep )
1758cdf0e10cSrcweir {
1759cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1760cdf0e10cSrcweir 
1761cdf0e10cSrcweir 	sal_Int32		nLen	= mpData->mnLen;
1762cdf0e10cSrcweir 	const STRCODE*	pStr	= mpData->maStr;
1763cdf0e10cSrcweir 	sal_Int32		nIndex	= 0;
1764cdf0e10cSrcweir 	while ( nIndex < nLen )
1765cdf0e10cSrcweir 	{
1766cdf0e10cSrcweir 		if ( *pStr == c )
1767cdf0e10cSrcweir 		{
1768cdf0e10cSrcweir 			ImplCopyData();
1769cdf0e10cSrcweir 			mpData->maStr[nIndex] = cRep;
1770cdf0e10cSrcweir 		}
1771cdf0e10cSrcweir 		++pStr,
1772cdf0e10cSrcweir 		++nIndex;
1773cdf0e10cSrcweir 	}
1774cdf0e10cSrcweir }
1775cdf0e10cSrcweir 
1776cdf0e10cSrcweir // -----------------------------------------------------------------------
1777cdf0e10cSrcweir 
SearchAndReplaceAll(const STRCODE * pCharStr,const STRING & rRepStr)1778cdf0e10cSrcweir void STRING::SearchAndReplaceAll( const STRCODE* pCharStr, const STRING& rRepStr )
1779cdf0e10cSrcweir {
1780cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1781cdf0e10cSrcweir 	DBG_CHKOBJ( &rRepStr, STRING, DBGCHECKSTRING );
1782cdf0e10cSrcweir 
1783cdf0e10cSrcweir 	xub_StrLen nCharLen = ImplStringLen( pCharStr );
1784cdf0e10cSrcweir 	xub_StrLen nSPos = Search( pCharStr, 0 );
1785cdf0e10cSrcweir 	while ( nSPos != STRING_NOTFOUND )
1786cdf0e10cSrcweir 	{
1787cdf0e10cSrcweir 		Replace( nSPos, nCharLen, rRepStr );
1788cdf0e10cSrcweir 		nSPos = nSPos + rRepStr.Len();
1789cdf0e10cSrcweir 		nSPos = Search( pCharStr, nSPos );
1790cdf0e10cSrcweir 	}
1791cdf0e10cSrcweir }
1792cdf0e10cSrcweir 
1793cdf0e10cSrcweir // -----------------------------------------------------------------------
1794cdf0e10cSrcweir 
SearchAndReplaceAll(const STRING & rStr,const STRING & rRepStr)1795cdf0e10cSrcweir void STRING::SearchAndReplaceAll( const STRING& rStr, const STRING& rRepStr )
1796cdf0e10cSrcweir {
1797cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1798cdf0e10cSrcweir 	DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING );
1799cdf0e10cSrcweir 	DBG_CHKOBJ( &rRepStr, STRING, DBGCHECKSTRING );
1800cdf0e10cSrcweir 
1801cdf0e10cSrcweir 	xub_StrLen nSPos = Search( rStr, 0 );
1802cdf0e10cSrcweir 	while ( nSPos != STRING_NOTFOUND )
1803cdf0e10cSrcweir 	{
1804cdf0e10cSrcweir 		Replace( nSPos, rStr.Len(), rRepStr );
1805cdf0e10cSrcweir 		nSPos = nSPos + rRepStr.Len();
1806cdf0e10cSrcweir 		nSPos = Search( rStr, nSPos );
1807cdf0e10cSrcweir 	}
1808cdf0e10cSrcweir }
1809cdf0e10cSrcweir 
1810cdf0e10cSrcweir // -----------------------------------------------------------------------
1811cdf0e10cSrcweir 
GetTokenCount(STRCODE cTok) const1812cdf0e10cSrcweir xub_StrLen STRING::GetTokenCount( STRCODE cTok ) const
1813cdf0e10cSrcweir {
1814cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1815cdf0e10cSrcweir 
1816cdf0e10cSrcweir 	// Leerer String: TokenCount per Definition 0
1817cdf0e10cSrcweir 	if ( !mpData->mnLen )
1818cdf0e10cSrcweir 		return 0;
1819cdf0e10cSrcweir 
1820cdf0e10cSrcweir 	xub_StrLen		nTokCount		= 1;
1821cdf0e10cSrcweir 	sal_Int32		nLen			= mpData->mnLen;
1822cdf0e10cSrcweir 	const STRCODE*	pStr			= mpData->maStr;
1823cdf0e10cSrcweir 	sal_Int32		nIndex			= 0;
1824cdf0e10cSrcweir 	while ( nIndex < nLen )
1825cdf0e10cSrcweir 	{
1826cdf0e10cSrcweir 		// Stimmt das Tokenzeichen ueberein, dann erhoehe TokCount
1827cdf0e10cSrcweir 		if ( *pStr == cTok )
1828cdf0e10cSrcweir 			++nTokCount;
1829cdf0e10cSrcweir 		++pStr,
1830cdf0e10cSrcweir 		++nIndex;
1831cdf0e10cSrcweir 	}
1832cdf0e10cSrcweir 
1833cdf0e10cSrcweir 	return nTokCount;
1834cdf0e10cSrcweir }
1835cdf0e10cSrcweir 
1836cdf0e10cSrcweir // -----------------------------------------------------------------------
1837cdf0e10cSrcweir 
SetToken(xub_StrLen nToken,STRCODE cTok,const STRING & rStr,xub_StrLen nIndex)1838cdf0e10cSrcweir void STRING::SetToken( xub_StrLen nToken, STRCODE cTok, const STRING& rStr,
1839cdf0e10cSrcweir 					   xub_StrLen nIndex )
1840cdf0e10cSrcweir {
1841cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1842cdf0e10cSrcweir 	DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING );
1843cdf0e10cSrcweir 
1844cdf0e10cSrcweir 	const STRCODE*	pStr			= mpData->maStr;
1845cdf0e10cSrcweir 	xub_StrLen		nLen			= (xub_StrLen)mpData->mnLen;
1846cdf0e10cSrcweir 	xub_StrLen		nTok			= 0;
1847cdf0e10cSrcweir 	xub_StrLen		nFirstChar		= nIndex;
1848cdf0e10cSrcweir 	xub_StrLen		i				= nFirstChar;
1849cdf0e10cSrcweir 
1850cdf0e10cSrcweir 	// Bestimme die Token-Position und Laenge
1851cdf0e10cSrcweir 	pStr += i;
1852cdf0e10cSrcweir 	while ( i < nLen )
1853cdf0e10cSrcweir 	{
1854cdf0e10cSrcweir 		// Stimmt das Tokenzeichen ueberein, dann erhoehe TokCount
1855cdf0e10cSrcweir 		if ( *pStr == cTok )
1856cdf0e10cSrcweir 		{
1857cdf0e10cSrcweir 			++nTok;
1858cdf0e10cSrcweir 
1859cdf0e10cSrcweir 			if ( nTok == nToken )
1860cdf0e10cSrcweir 				nFirstChar = i+1;
1861cdf0e10cSrcweir 			else
1862cdf0e10cSrcweir 			{
1863cdf0e10cSrcweir 				if ( nTok > nToken )
1864cdf0e10cSrcweir 					break;
1865cdf0e10cSrcweir 			}
1866cdf0e10cSrcweir 		}
1867cdf0e10cSrcweir 
1868cdf0e10cSrcweir 		++pStr,
1869cdf0e10cSrcweir 		++i;
1870cdf0e10cSrcweir 	}
1871cdf0e10cSrcweir 
1872cdf0e10cSrcweir 	if ( nTok >= nToken )
1873cdf0e10cSrcweir 		Replace( nFirstChar, i-nFirstChar, rStr );
1874cdf0e10cSrcweir }
1875cdf0e10cSrcweir 
1876cdf0e10cSrcweir // -----------------------------------------------------------------------
1877cdf0e10cSrcweir 
GetToken(xub_StrLen nToken,STRCODE cTok,xub_StrLen & rIndex) const1878cdf0e10cSrcweir STRING STRING::GetToken( xub_StrLen nToken, STRCODE cTok, xub_StrLen& rIndex ) const
1879cdf0e10cSrcweir {
1880cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1881cdf0e10cSrcweir 
1882cdf0e10cSrcweir 	const STRCODE*	pStr			= mpData->maStr;
1883cdf0e10cSrcweir 	xub_StrLen		nLen			= (xub_StrLen)mpData->mnLen;
1884cdf0e10cSrcweir 	xub_StrLen		nTok			= 0;
1885cdf0e10cSrcweir 	xub_StrLen		nFirstChar		= rIndex;
1886cdf0e10cSrcweir 	xub_StrLen		i				= nFirstChar;
1887cdf0e10cSrcweir 
1888cdf0e10cSrcweir 	// Bestimme die Token-Position und Laenge
1889cdf0e10cSrcweir 	pStr += i;
1890cdf0e10cSrcweir 	while ( i < nLen )
1891cdf0e10cSrcweir 	{
1892cdf0e10cSrcweir 		// Stimmt das Tokenzeichen ueberein, dann erhoehe TokCount
1893cdf0e10cSrcweir 		if ( *pStr == cTok )
1894cdf0e10cSrcweir 		{
1895cdf0e10cSrcweir 			++nTok;
1896cdf0e10cSrcweir 
1897cdf0e10cSrcweir 			if ( nTok == nToken )
1898cdf0e10cSrcweir 				nFirstChar = i+1;
1899cdf0e10cSrcweir 			else
1900cdf0e10cSrcweir 			{
1901cdf0e10cSrcweir 				if ( nTok > nToken )
1902cdf0e10cSrcweir 					break;
1903cdf0e10cSrcweir 			}
1904cdf0e10cSrcweir 		}
1905cdf0e10cSrcweir 
1906cdf0e10cSrcweir 		++pStr,
1907cdf0e10cSrcweir 		++i;
1908cdf0e10cSrcweir 	}
1909cdf0e10cSrcweir 
1910cdf0e10cSrcweir 	if ( nTok >= nToken )
1911cdf0e10cSrcweir 	{
1912cdf0e10cSrcweir 		if ( i < nLen )
1913cdf0e10cSrcweir 			rIndex = i+1;
1914cdf0e10cSrcweir 		else
1915cdf0e10cSrcweir 			rIndex = STRING_NOTFOUND;
1916cdf0e10cSrcweir 		return Copy( nFirstChar, i-nFirstChar );
1917cdf0e10cSrcweir 	}
1918cdf0e10cSrcweir 	else
1919cdf0e10cSrcweir 	{
1920cdf0e10cSrcweir 		rIndex = STRING_NOTFOUND;
1921cdf0e10cSrcweir 		return STRING();
1922cdf0e10cSrcweir 	}
1923cdf0e10cSrcweir }
1924cdf0e10cSrcweir 
1925cdf0e10cSrcweir // -----------------------------------------------------------------------
1926cdf0e10cSrcweir 
GetQuotedTokenCount(const STRING & rQuotedPairs,STRCODE cTok) const1927cdf0e10cSrcweir xub_StrLen STRING::GetQuotedTokenCount( const STRING& rQuotedPairs, STRCODE cTok ) const
1928cdf0e10cSrcweir {
1929cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1930cdf0e10cSrcweir 	DBG_CHKOBJ( &rQuotedPairs, STRING, DBGCHECKSTRING );
1931cdf0e10cSrcweir 	DBG_ASSERT( !(rQuotedPairs.Len()%2), "String::GetQuotedTokenCount() - QuotedString%2 != 0" );
1932cdf0e10cSrcweir 	DBG_ASSERT( rQuotedPairs.Search(cTok) == STRING_NOTFOUND, "String::GetQuotedTokenCount() - cTok in QuotedString" );
1933cdf0e10cSrcweir 
1934cdf0e10cSrcweir 	// Leerer String: TokenCount per Definition 0
1935cdf0e10cSrcweir 	if ( !mpData->mnLen )
1936cdf0e10cSrcweir 		return 0;
1937cdf0e10cSrcweir 
1938cdf0e10cSrcweir 	xub_StrLen		nTokCount		= 1;
1939cdf0e10cSrcweir 	sal_Int32		nLen			= mpData->mnLen;
1940cdf0e10cSrcweir 	xub_StrLen		nQuotedLen		= rQuotedPairs.Len();
1941cdf0e10cSrcweir 	STRCODE 		cQuotedEndChar	= 0;
1942cdf0e10cSrcweir 	const STRCODE*	pQuotedStr		= rQuotedPairs.mpData->maStr;
1943cdf0e10cSrcweir 	const STRCODE*	pStr			= mpData->maStr;
1944cdf0e10cSrcweir 	sal_Int32		nIndex			= 0;
1945cdf0e10cSrcweir 	while ( nIndex < nLen )
1946cdf0e10cSrcweir 	{
1947cdf0e10cSrcweir 		STRCODE c = *pStr;
1948cdf0e10cSrcweir 		if ( cQuotedEndChar )
1949cdf0e10cSrcweir 		{
1950cdf0e10cSrcweir 			// Ende des Quotes erreicht ?
1951cdf0e10cSrcweir 			if ( c == cQuotedEndChar )
1952cdf0e10cSrcweir 				cQuotedEndChar = 0;
1953cdf0e10cSrcweir 		}
1954cdf0e10cSrcweir 		else
1955cdf0e10cSrcweir 		{
1956cdf0e10cSrcweir 			// Ist das Zeichen ein Quote-Anfang-Zeichen ?
1957cdf0e10cSrcweir 			xub_StrLen nQuoteIndex = 0;
1958cdf0e10cSrcweir 			while ( nQuoteIndex < nQuotedLen )
1959cdf0e10cSrcweir 			{
1960cdf0e10cSrcweir 				if ( pQuotedStr[nQuoteIndex] == c )
1961cdf0e10cSrcweir 				{
1962cdf0e10cSrcweir 					cQuotedEndChar = pQuotedStr[nQuoteIndex+1];
1963cdf0e10cSrcweir 					break;
1964cdf0e10cSrcweir 				}
1965cdf0e10cSrcweir 				else
1966cdf0e10cSrcweir 					nQuoteIndex += 2;
1967cdf0e10cSrcweir 			}
1968cdf0e10cSrcweir 
1969cdf0e10cSrcweir 			// Stimmt das Tokenzeichen ueberein, dann erhoehe TokCount
1970cdf0e10cSrcweir 			if ( c == cTok )
1971cdf0e10cSrcweir 				++nTokCount;
1972cdf0e10cSrcweir 		}
1973cdf0e10cSrcweir 
1974cdf0e10cSrcweir 		++pStr,
1975cdf0e10cSrcweir 		++nIndex;
1976cdf0e10cSrcweir 	}
1977cdf0e10cSrcweir 
1978cdf0e10cSrcweir 	return nTokCount;
1979cdf0e10cSrcweir }
1980cdf0e10cSrcweir 
1981cdf0e10cSrcweir // -----------------------------------------------------------------------
1982cdf0e10cSrcweir 
GetQuotedToken(xub_StrLen nToken,const STRING & rQuotedPairs,STRCODE cTok,xub_StrLen & rIndex) const1983cdf0e10cSrcweir STRING STRING::GetQuotedToken( xub_StrLen nToken, const STRING& rQuotedPairs,
1984cdf0e10cSrcweir 							   STRCODE cTok, xub_StrLen& rIndex ) const
1985cdf0e10cSrcweir {
1986cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
1987cdf0e10cSrcweir 	DBG_CHKOBJ( &rQuotedPairs, STRING, DBGCHECKSTRING );
1988cdf0e10cSrcweir 	DBG_ASSERT( !(rQuotedPairs.Len()%2), "String::GetQuotedToken() - QuotedString%2 != 0" );
1989cdf0e10cSrcweir 	DBG_ASSERT( rQuotedPairs.Search(cTok) == STRING_NOTFOUND, "String::GetQuotedToken() - cTok in QuotedString" );
1990cdf0e10cSrcweir 
1991cdf0e10cSrcweir 	const STRCODE*	pStr			= mpData->maStr;
1992cdf0e10cSrcweir 	const STRCODE*	pQuotedStr		= rQuotedPairs.mpData->maStr;
1993cdf0e10cSrcweir 	STRCODE 		cQuotedEndChar	= 0;
1994cdf0e10cSrcweir 	xub_StrLen		nQuotedLen		= rQuotedPairs.Len();
1995cdf0e10cSrcweir 	xub_StrLen		nLen			= (xub_StrLen)mpData->mnLen;
1996cdf0e10cSrcweir 	xub_StrLen		nTok			= 0;
1997cdf0e10cSrcweir 	xub_StrLen		nFirstChar		= rIndex;
1998cdf0e10cSrcweir 	xub_StrLen		i				= nFirstChar;
1999cdf0e10cSrcweir 
2000cdf0e10cSrcweir 	// Bestimme die Token-Position und Laenge
2001cdf0e10cSrcweir 	pStr += i;
2002cdf0e10cSrcweir 	while ( i < nLen )
2003cdf0e10cSrcweir 	{
2004cdf0e10cSrcweir 		STRCODE c = *pStr;
2005cdf0e10cSrcweir 		if ( cQuotedEndChar )
2006cdf0e10cSrcweir 		{
2007cdf0e10cSrcweir 			// Ende des Quotes erreicht ?
2008cdf0e10cSrcweir 			if ( c == cQuotedEndChar )
2009cdf0e10cSrcweir 				cQuotedEndChar = 0;
2010cdf0e10cSrcweir 		}
2011cdf0e10cSrcweir 		else
2012cdf0e10cSrcweir 		{
2013cdf0e10cSrcweir 			// Ist das Zeichen ein Quote-Anfang-Zeichen ?
2014cdf0e10cSrcweir 			xub_StrLen nQuoteIndex = 0;
2015cdf0e10cSrcweir 			while ( nQuoteIndex < nQuotedLen )
2016cdf0e10cSrcweir 			{
2017cdf0e10cSrcweir 				if ( pQuotedStr[nQuoteIndex] == c )
2018cdf0e10cSrcweir 				{
2019cdf0e10cSrcweir 					cQuotedEndChar = pQuotedStr[nQuoteIndex+1];
2020cdf0e10cSrcweir 					break;
2021cdf0e10cSrcweir 				}
2022cdf0e10cSrcweir 				else
2023cdf0e10cSrcweir 					nQuoteIndex += 2;
2024cdf0e10cSrcweir 			}
2025cdf0e10cSrcweir 
2026cdf0e10cSrcweir 			// Stimmt das Tokenzeichen ueberein, dann erhoehe TokCount
2027cdf0e10cSrcweir 			if ( c == cTok )
2028cdf0e10cSrcweir 			{
2029cdf0e10cSrcweir 				++nTok;
2030cdf0e10cSrcweir 
2031cdf0e10cSrcweir 				if ( nTok == nToken )
2032cdf0e10cSrcweir 					nFirstChar = i+1;
2033cdf0e10cSrcweir 				else
2034cdf0e10cSrcweir 				{
2035cdf0e10cSrcweir 					if ( nTok > nToken )
2036cdf0e10cSrcweir 						break;
2037cdf0e10cSrcweir 				}
2038cdf0e10cSrcweir 			}
2039cdf0e10cSrcweir 		}
2040cdf0e10cSrcweir 
2041cdf0e10cSrcweir 		++pStr,
2042cdf0e10cSrcweir 		++i;
2043cdf0e10cSrcweir 	}
2044cdf0e10cSrcweir 
2045cdf0e10cSrcweir 	if ( nTok >= nToken )
2046cdf0e10cSrcweir 	{
2047cdf0e10cSrcweir 		if ( i < nLen )
2048cdf0e10cSrcweir 			rIndex = i+1;
2049cdf0e10cSrcweir 		else
2050cdf0e10cSrcweir 			rIndex = STRING_NOTFOUND;
2051cdf0e10cSrcweir 		return Copy( nFirstChar, i-nFirstChar );
2052cdf0e10cSrcweir 	}
2053cdf0e10cSrcweir 	else
2054cdf0e10cSrcweir 	{
2055cdf0e10cSrcweir 		rIndex = STRING_NOTFOUND;
2056cdf0e10cSrcweir 		return STRING();
2057cdf0e10cSrcweir 	}
2058cdf0e10cSrcweir }
2059cdf0e10cSrcweir 
2060cdf0e10cSrcweir // -----------------------------------------------------------------------
2061cdf0e10cSrcweir 
GetBufferAccess()2062cdf0e10cSrcweir STRCODE* STRING::GetBufferAccess()
2063cdf0e10cSrcweir {
2064cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
2065cdf0e10cSrcweir 
2066cdf0e10cSrcweir 	// Daten kopieren, wenn noetig
2067cdf0e10cSrcweir 	if ( mpData->mnLen )
2068cdf0e10cSrcweir 		ImplCopyData();
2069cdf0e10cSrcweir 
2070cdf0e10cSrcweir 	// Pointer auf den String zurueckgeben
2071cdf0e10cSrcweir 	return mpData->maStr;
2072cdf0e10cSrcweir }
2073cdf0e10cSrcweir 
2074cdf0e10cSrcweir // -----------------------------------------------------------------------
2075cdf0e10cSrcweir 
ReleaseBufferAccess(xub_StrLen nLen)2076cdf0e10cSrcweir void STRING::ReleaseBufferAccess( xub_StrLen nLen )
2077cdf0e10cSrcweir {
2078cdf0e10cSrcweir 	// Hier ohne Funktionstest, da String nicht konsistent
2079cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, NULL );
2080cdf0e10cSrcweir 	DBG_ASSERT( mpData->mnRefCount == 1, "String::ReleaseCharStr() called for String with RefCount" );
2081cdf0e10cSrcweir 
2082cdf0e10cSrcweir 	if ( nLen > mpData->mnLen )
2083cdf0e10cSrcweir 		nLen = ImplStringLen( mpData->maStr );
2084cdf0e10cSrcweir     OSL_ASSERT(nLen <= mpData->mnLen);
2085cdf0e10cSrcweir 	if ( !nLen )
2086cdf0e10cSrcweir 	{
2087cdf0e10cSrcweir 		STRING_NEW((STRING_TYPE **)&mpData);
2088cdf0e10cSrcweir 	}
2089cdf0e10cSrcweir 	// Bei mehr als 8 Zeichen unterschied, kuerzen wir den Buffer
2090cdf0e10cSrcweir 	else if ( mpData->mnLen - nLen > 8 )
2091cdf0e10cSrcweir 	{
2092cdf0e10cSrcweir 		STRINGDATA* pNewData = ImplAllocData( nLen );
2093cdf0e10cSrcweir 		memcpy( pNewData->maStr, mpData->maStr, nLen*sizeof( STRCODE ) );
2094cdf0e10cSrcweir 		STRING_RELEASE((STRING_TYPE *)mpData);
2095cdf0e10cSrcweir 		mpData = pNewData;
2096cdf0e10cSrcweir 	}
2097cdf0e10cSrcweir 	else
2098cdf0e10cSrcweir 		mpData->mnLen = nLen;
2099cdf0e10cSrcweir }
2100cdf0e10cSrcweir 
2101cdf0e10cSrcweir // -----------------------------------------------------------------------
2102cdf0e10cSrcweir 
AllocBuffer(xub_StrLen nLen)2103cdf0e10cSrcweir STRCODE* STRING::AllocBuffer( xub_StrLen nLen )
2104cdf0e10cSrcweir {
2105cdf0e10cSrcweir 	DBG_CHKTHIS( STRING, DBGCHECKSTRING );
2106cdf0e10cSrcweir 
2107cdf0e10cSrcweir 	STRING_RELEASE((STRING_TYPE *)mpData);
2108cdf0e10cSrcweir 	if ( nLen )
2109cdf0e10cSrcweir 		mpData = ImplAllocData( nLen );
2110cdf0e10cSrcweir 	else
2111cdf0e10cSrcweir 	{
2112cdf0e10cSrcweir 		mpData = NULL;
2113cdf0e10cSrcweir 		STRING_NEW((STRING_TYPE **)&mpData);
2114cdf0e10cSrcweir 	}
2115cdf0e10cSrcweir 
2116cdf0e10cSrcweir 	return mpData->maStr;
2117cdf0e10cSrcweir }
2118