xref: /AOO41X/main/sal/rtl/source/strtmpl.c (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir /* ======================================================================= */
29*cdf0e10cSrcweir /* Internal C-String help functions which could be used without the        */
30*cdf0e10cSrcweir /* String-Class                                                            */
31*cdf0e10cSrcweir /* ======================================================================= */
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir /*
34*cdf0e10cSrcweir inline void rtl_str_ImplCopy( IMPL_RTL_STRCODE* pDest,
35*cdf0e10cSrcweir                               const IMPL_RTL_STRCODE* pSrc,
36*cdf0e10cSrcweir                               sal_Int32 nCount )
37*cdf0e10cSrcweir {
38*cdf0e10cSrcweir     while ( nCount > 0 )
39*cdf0e10cSrcweir     {
40*cdf0e10cSrcweir         *pDest = *pSrc;
41*cdf0e10cSrcweir         pDest++;
42*cdf0e10cSrcweir         pSrc++;
43*cdf0e10cSrcweir         nCount--;
44*cdf0e10cSrcweir     }
45*cdf0e10cSrcweir }
46*cdf0e10cSrcweir */
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir #define rtl_str_ImplCopy( _pDest, _pSrc, _nCount )                  \
49*cdf0e10cSrcweir {                                                                   \
50*cdf0e10cSrcweir     IMPL_RTL_STRCODE*       __mm_pDest      = _pDest;               \
51*cdf0e10cSrcweir     const IMPL_RTL_STRCODE* __mm_pSrc       = _pSrc;                \
52*cdf0e10cSrcweir     sal_Int32               __mm_nCount     = _nCount;              \
53*cdf0e10cSrcweir     while ( __mm_nCount > 0 )                                       \
54*cdf0e10cSrcweir     {                                                               \
55*cdf0e10cSrcweir         *__mm_pDest = *__mm_pSrc;                                   \
56*cdf0e10cSrcweir         __mm_pDest++;                                               \
57*cdf0e10cSrcweir         __mm_pSrc++;                                                \
58*cdf0e10cSrcweir         __mm_nCount--;                                              \
59*cdf0e10cSrcweir     }                                                               \
60*cdf0e10cSrcweir }
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir /* ======================================================================= */
63*cdf0e10cSrcweir /* C-String functions which could be used without the String-Class         */
64*cdf0e10cSrcweir /* ======================================================================= */
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir sal_Int32 SAL_CALL IMPL_RTL_STRNAME( getLength )( const IMPL_RTL_STRCODE* pStr )
67*cdf0e10cSrcweir {
68*cdf0e10cSrcweir     const IMPL_RTL_STRCODE* pTempStr = pStr;
69*cdf0e10cSrcweir     while( *pTempStr )
70*cdf0e10cSrcweir         pTempStr++;
71*cdf0e10cSrcweir     return pTempStr-pStr;
72*cdf0e10cSrcweir }
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir sal_Int32 SAL_CALL IMPL_RTL_STRNAME( compare )( const IMPL_RTL_STRCODE* pStr1,
77*cdf0e10cSrcweir                                                 const IMPL_RTL_STRCODE* pStr2 )
78*cdf0e10cSrcweir {
79*cdf0e10cSrcweir     sal_Int32 nRet;
80*cdf0e10cSrcweir     while ( ((nRet = ((sal_Int32)(IMPL_RTL_USTRCODE(*pStr1)))-
81*cdf0e10cSrcweir                      ((sal_Int32)(IMPL_RTL_USTRCODE(*pStr2)))) == 0) &&
82*cdf0e10cSrcweir             *pStr2 )
83*cdf0e10cSrcweir     {
84*cdf0e10cSrcweir         pStr1++;
85*cdf0e10cSrcweir         pStr2++;
86*cdf0e10cSrcweir     }
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir     return nRet;
89*cdf0e10cSrcweir }
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir sal_Int32 SAL_CALL IMPL_RTL_STRNAME( compare_WithLength )( const IMPL_RTL_STRCODE* pStr1,
94*cdf0e10cSrcweir                                                            sal_Int32 nStr1Len,
95*cdf0e10cSrcweir                                                            const IMPL_RTL_STRCODE* pStr2,
96*cdf0e10cSrcweir                                                            sal_Int32 nStr2Len )
97*cdf0e10cSrcweir {
98*cdf0e10cSrcweir     sal_Int32 nRet = nStr1Len - nStr2Len;
99*cdf0e10cSrcweir     int nCount = (nRet <= 0) ? nStr1Len : nStr2Len;
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir     --pStr1;
102*cdf0e10cSrcweir     --pStr2;
103*cdf0e10cSrcweir     while( (--nCount >= 0) && (*++pStr1 == *++pStr2) );
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir     if( nCount >= 0 )
106*cdf0e10cSrcweir         nRet = ((sal_Int32)(IMPL_RTL_USTRCODE( *pStr1 )))
107*cdf0e10cSrcweir              - ((sal_Int32)(IMPL_RTL_USTRCODE( *pStr2 )));
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir     return nRet;
110*cdf0e10cSrcweir }
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir sal_Int32 SAL_CALL IMPL_RTL_STRNAME( shortenedCompare_WithLength )( const IMPL_RTL_STRCODE* pStr1,
115*cdf0e10cSrcweir                                                                     sal_Int32 nStr1Len,
116*cdf0e10cSrcweir                                                                     const IMPL_RTL_STRCODE* pStr2,
117*cdf0e10cSrcweir                                                                     sal_Int32 nStr2Len,
118*cdf0e10cSrcweir                                                                     sal_Int32 nShortenedLength )
119*cdf0e10cSrcweir {
120*cdf0e10cSrcweir     const IMPL_RTL_STRCODE* pStr1End = pStr1 + nStr1Len;
121*cdf0e10cSrcweir     const IMPL_RTL_STRCODE* pStr2End = pStr2 + nStr2Len;
122*cdf0e10cSrcweir     sal_Int32               nRet;
123*cdf0e10cSrcweir     while ( (nShortenedLength > 0) &&
124*cdf0e10cSrcweir             (pStr1 < pStr1End) && (pStr2 < pStr2End) )
125*cdf0e10cSrcweir     {
126*cdf0e10cSrcweir         nRet = ((sal_Int32)(IMPL_RTL_USTRCODE( *pStr1 )))-
127*cdf0e10cSrcweir                ((sal_Int32)(IMPL_RTL_USTRCODE( *pStr2 )));
128*cdf0e10cSrcweir         if ( nRet )
129*cdf0e10cSrcweir             return nRet;
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir         nShortenedLength--;
132*cdf0e10cSrcweir         pStr1++;
133*cdf0e10cSrcweir         pStr2++;
134*cdf0e10cSrcweir     }
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir     if ( nShortenedLength <= 0 )
137*cdf0e10cSrcweir         return 0;
138*cdf0e10cSrcweir     return nStr1Len - nStr2Len;
139*cdf0e10cSrcweir }
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir sal_Int32 SAL_CALL IMPL_RTL_STRNAME( reverseCompare_WithLength )( const IMPL_RTL_STRCODE* pStr1,
144*cdf0e10cSrcweir                                                                   sal_Int32 nStr1Len,
145*cdf0e10cSrcweir                                                                   const IMPL_RTL_STRCODE* pStr2,
146*cdf0e10cSrcweir                                                                   sal_Int32 nStr2Len )
147*cdf0e10cSrcweir {
148*cdf0e10cSrcweir     const IMPL_RTL_STRCODE* pStr1Run = pStr1+nStr1Len;
149*cdf0e10cSrcweir     const IMPL_RTL_STRCODE* pStr2Run = pStr2+nStr2Len;
150*cdf0e10cSrcweir     sal_Int32               nRet;
151*cdf0e10cSrcweir     while ( (pStr1 < pStr1Run) && (pStr2 < pStr2Run) )
152*cdf0e10cSrcweir     {
153*cdf0e10cSrcweir         pStr1Run--;
154*cdf0e10cSrcweir         pStr2Run--;
155*cdf0e10cSrcweir         nRet = ((sal_Int32)(IMPL_RTL_USTRCODE( *pStr1Run )))-
156*cdf0e10cSrcweir                ((sal_Int32)(IMPL_RTL_USTRCODE( *pStr2Run )));
157*cdf0e10cSrcweir         if ( nRet )
158*cdf0e10cSrcweir             return nRet;
159*cdf0e10cSrcweir     }
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir     return nStr1Len - nStr2Len;
162*cdf0e10cSrcweir }
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir sal_Int32 SAL_CALL IMPL_RTL_STRNAME( compareIgnoreAsciiCase )( const IMPL_RTL_STRCODE* pStr1,
167*cdf0e10cSrcweir                                                                const IMPL_RTL_STRCODE* pStr2 )
168*cdf0e10cSrcweir {
169*cdf0e10cSrcweir     sal_Int32   nRet;
170*cdf0e10cSrcweir     sal_Int32   c1;
171*cdf0e10cSrcweir     sal_Int32   c2;
172*cdf0e10cSrcweir     do
173*cdf0e10cSrcweir     {
174*cdf0e10cSrcweir         /* If character between 'A' and 'Z', than convert it to lowercase */
175*cdf0e10cSrcweir         c1 = (sal_Int32)IMPL_RTL_USTRCODE( *pStr1 );
176*cdf0e10cSrcweir         c2 = (sal_Int32)IMPL_RTL_USTRCODE( *pStr2 );
177*cdf0e10cSrcweir         if ( (c1 >= 65) && (c1 <= 90) )
178*cdf0e10cSrcweir             c1 += 32;
179*cdf0e10cSrcweir         if ( (c2 >= 65) && (c2 <= 90) )
180*cdf0e10cSrcweir             c2 += 32;
181*cdf0e10cSrcweir         nRet = c1-c2;
182*cdf0e10cSrcweir         if ( nRet != 0 )
183*cdf0e10cSrcweir             return nRet;
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir         pStr1++;
186*cdf0e10cSrcweir         pStr2++;
187*cdf0e10cSrcweir     }
188*cdf0e10cSrcweir     while ( c2 );
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir     return 0;
191*cdf0e10cSrcweir }
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir sal_Int32 SAL_CALL IMPL_RTL_STRNAME( compareIgnoreAsciiCase_WithLength )( const IMPL_RTL_STRCODE* pStr1,
196*cdf0e10cSrcweir                                                                           sal_Int32 nStr1Len,
197*cdf0e10cSrcweir                                                                           const IMPL_RTL_STRCODE* pStr2,
198*cdf0e10cSrcweir                                                                           sal_Int32 nStr2Len )
199*cdf0e10cSrcweir {
200*cdf0e10cSrcweir     const IMPL_RTL_STRCODE* pStr1End = pStr1 + nStr1Len;
201*cdf0e10cSrcweir     const IMPL_RTL_STRCODE* pStr2End = pStr2 + nStr2Len;
202*cdf0e10cSrcweir     sal_Int32   nRet;
203*cdf0e10cSrcweir     sal_Int32   c1;
204*cdf0e10cSrcweir     sal_Int32   c2;
205*cdf0e10cSrcweir     while ( (pStr1 < pStr1End) && (pStr2 < pStr2End) )
206*cdf0e10cSrcweir     {
207*cdf0e10cSrcweir         /* If character between 'A' and 'Z', than convert it to lowercase */
208*cdf0e10cSrcweir         c1 = (sal_Int32)IMPL_RTL_USTRCODE( *pStr1 );
209*cdf0e10cSrcweir         c2 = (sal_Int32)IMPL_RTL_USTRCODE( *pStr2 );
210*cdf0e10cSrcweir         if ( (c1 >= 65) && (c1 <= 90) )
211*cdf0e10cSrcweir             c1 += 32;
212*cdf0e10cSrcweir         if ( (c2 >= 65) && (c2 <= 90) )
213*cdf0e10cSrcweir             c2 += 32;
214*cdf0e10cSrcweir         nRet = c1-c2;
215*cdf0e10cSrcweir         if ( nRet != 0 )
216*cdf0e10cSrcweir             return nRet;
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir         pStr1++;
219*cdf0e10cSrcweir         pStr2++;
220*cdf0e10cSrcweir     }
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir     return nStr1Len - nStr2Len;
223*cdf0e10cSrcweir }
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir sal_Int32 SAL_CALL IMPL_RTL_STRNAME( shortenedCompareIgnoreAsciiCase_WithLength )( const IMPL_RTL_STRCODE* pStr1,
228*cdf0e10cSrcweir                                                                                    sal_Int32 nStr1Len,
229*cdf0e10cSrcweir                                                                                    const IMPL_RTL_STRCODE* pStr2,
230*cdf0e10cSrcweir                                                                                    sal_Int32 nStr2Len,
231*cdf0e10cSrcweir                                                                                    sal_Int32 nShortenedLength )
232*cdf0e10cSrcweir {
233*cdf0e10cSrcweir     const IMPL_RTL_STRCODE* pStr1End = pStr1 + nStr1Len;
234*cdf0e10cSrcweir     const IMPL_RTL_STRCODE* pStr2End = pStr2 + nStr2Len;
235*cdf0e10cSrcweir     sal_Int32               nRet;
236*cdf0e10cSrcweir     sal_Int32               c1;
237*cdf0e10cSrcweir     sal_Int32               c2;
238*cdf0e10cSrcweir     while ( (nShortenedLength > 0) &&
239*cdf0e10cSrcweir             (pStr1 < pStr1End) && (pStr2 < pStr2End) )
240*cdf0e10cSrcweir     {
241*cdf0e10cSrcweir         /* If character between 'A' and 'Z', than convert it to lowercase */
242*cdf0e10cSrcweir         c1 = (sal_Int32)IMPL_RTL_USTRCODE( *pStr1 );
243*cdf0e10cSrcweir         c2 = (sal_Int32)IMPL_RTL_USTRCODE( *pStr2 );
244*cdf0e10cSrcweir         if ( (c1 >= 65) && (c1 <= 90) )
245*cdf0e10cSrcweir             c1 += 32;
246*cdf0e10cSrcweir         if ( (c2 >= 65) && (c2 <= 90) )
247*cdf0e10cSrcweir             c2 += 32;
248*cdf0e10cSrcweir         nRet = c1-c2;
249*cdf0e10cSrcweir         if ( nRet != 0 )
250*cdf0e10cSrcweir             return nRet;
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir         nShortenedLength--;
253*cdf0e10cSrcweir         pStr1++;
254*cdf0e10cSrcweir         pStr2++;
255*cdf0e10cSrcweir     }
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir     if ( nShortenedLength <= 0 )
258*cdf0e10cSrcweir         return 0;
259*cdf0e10cSrcweir     return nStr1Len - nStr2Len;
260*cdf0e10cSrcweir }
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir sal_Int32 SAL_CALL IMPL_RTL_STRNAME( hashCode )( const IMPL_RTL_STRCODE* pStr )
265*cdf0e10cSrcweir {
266*cdf0e10cSrcweir     return IMPL_RTL_STRNAME( hashCode_WithLength )( pStr, IMPL_RTL_STRNAME( getLength )( pStr ) );
267*cdf0e10cSrcweir }
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir sal_Int32 SAL_CALL IMPL_RTL_STRNAME( hashCode_WithLength )( const IMPL_RTL_STRCODE* pStr,
272*cdf0e10cSrcweir                                                             sal_Int32 nLen )
273*cdf0e10cSrcweir {
274*cdf0e10cSrcweir     sal_Int32 h = nLen;
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir     if ( nLen < 256 )
277*cdf0e10cSrcweir     {
278*cdf0e10cSrcweir         while ( nLen > 0 )
279*cdf0e10cSrcweir         {
280*cdf0e10cSrcweir             h = (h*37) + IMPL_RTL_USTRCODE( *pStr );
281*cdf0e10cSrcweir             pStr++;
282*cdf0e10cSrcweir             nLen--;
283*cdf0e10cSrcweir         }
284*cdf0e10cSrcweir     }
285*cdf0e10cSrcweir     else
286*cdf0e10cSrcweir     {
287*cdf0e10cSrcweir         sal_Int32               nSkip;
288*cdf0e10cSrcweir         const IMPL_RTL_STRCODE* pEndStr = pStr+nLen-5;
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir         /* only sample some characters */
291*cdf0e10cSrcweir         /* the first 3, some characters between, and the last 5 */
292*cdf0e10cSrcweir         h = (h*39) + IMPL_RTL_USTRCODE( *pStr );
293*cdf0e10cSrcweir         pStr++;
294*cdf0e10cSrcweir         h = (h*39) + IMPL_RTL_USTRCODE( *pStr );
295*cdf0e10cSrcweir         pStr++;
296*cdf0e10cSrcweir         h = (h*39) + IMPL_RTL_USTRCODE( *pStr );
297*cdf0e10cSrcweir         pStr++;
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir         if ( nLen < 32 )
300*cdf0e10cSrcweir             nSkip = nLen / 4;
301*cdf0e10cSrcweir         else
302*cdf0e10cSrcweir             nSkip = nLen / 8;
303*cdf0e10cSrcweir         nLen -= 8;
304*cdf0e10cSrcweir         while ( nLen > 0 )
305*cdf0e10cSrcweir         {
306*cdf0e10cSrcweir             h = (h*39) + IMPL_RTL_USTRCODE( *pStr );
307*cdf0e10cSrcweir             pStr += nSkip;
308*cdf0e10cSrcweir             nLen -= nSkip;
309*cdf0e10cSrcweir         }
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir         h = (h*39) + IMPL_RTL_USTRCODE( *pEndStr );
312*cdf0e10cSrcweir         pEndStr++;
313*cdf0e10cSrcweir         h = (h*39) + IMPL_RTL_USTRCODE( *pEndStr );
314*cdf0e10cSrcweir         pEndStr++;
315*cdf0e10cSrcweir         h = (h*39) + IMPL_RTL_USTRCODE( *pEndStr );
316*cdf0e10cSrcweir         pEndStr++;
317*cdf0e10cSrcweir         h = (h*39) + IMPL_RTL_USTRCODE( *pEndStr );
318*cdf0e10cSrcweir         pEndStr++;
319*cdf0e10cSrcweir         h = (h*39) + IMPL_RTL_USTRCODE( *pEndStr );
320*cdf0e10cSrcweir     }
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir     return h;
323*cdf0e10cSrcweir }
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir sal_Int32 SAL_CALL IMPL_RTL_STRNAME( indexOfChar )( const IMPL_RTL_STRCODE* pStr,
328*cdf0e10cSrcweir                                                     IMPL_RTL_STRCODE c )
329*cdf0e10cSrcweir {
330*cdf0e10cSrcweir     const IMPL_RTL_STRCODE* pTempStr = pStr;
331*cdf0e10cSrcweir     while ( *pTempStr )
332*cdf0e10cSrcweir     {
333*cdf0e10cSrcweir         if ( *pTempStr == c )
334*cdf0e10cSrcweir             return pTempStr-pStr;
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir         pTempStr++;
337*cdf0e10cSrcweir     }
338*cdf0e10cSrcweir 
339*cdf0e10cSrcweir     return -1;
340*cdf0e10cSrcweir }
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
343*cdf0e10cSrcweir 
344*cdf0e10cSrcweir sal_Int32 SAL_CALL IMPL_RTL_STRNAME( indexOfChar_WithLength )( const IMPL_RTL_STRCODE* pStr,
345*cdf0e10cSrcweir                                                                sal_Int32 nLen,
346*cdf0e10cSrcweir                                                                IMPL_RTL_STRCODE c )
347*cdf0e10cSrcweir {
348*cdf0e10cSrcweir     const IMPL_RTL_STRCODE* pTempStr = pStr;
349*cdf0e10cSrcweir     while ( nLen > 0 )
350*cdf0e10cSrcweir     {
351*cdf0e10cSrcweir         if ( *pTempStr == c )
352*cdf0e10cSrcweir             return pTempStr-pStr;
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir         pTempStr++;
355*cdf0e10cSrcweir         nLen--;
356*cdf0e10cSrcweir     }
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir     return -1;
359*cdf0e10cSrcweir }
360*cdf0e10cSrcweir 
361*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir sal_Int32 SAL_CALL IMPL_RTL_STRNAME( lastIndexOfChar )( const IMPL_RTL_STRCODE* pStr,
364*cdf0e10cSrcweir                                                         IMPL_RTL_STRCODE c )
365*cdf0e10cSrcweir {
366*cdf0e10cSrcweir     return IMPL_RTL_STRNAME( lastIndexOfChar_WithLength )( pStr, IMPL_RTL_STRNAME( getLength )( pStr ), c );
367*cdf0e10cSrcweir }
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir sal_Int32 SAL_CALL IMPL_RTL_STRNAME( lastIndexOfChar_WithLength )( const IMPL_RTL_STRCODE* pStr,
372*cdf0e10cSrcweir                                                                    sal_Int32 nLen,
373*cdf0e10cSrcweir                                                                    IMPL_RTL_STRCODE c )
374*cdf0e10cSrcweir {
375*cdf0e10cSrcweir     pStr += nLen;
376*cdf0e10cSrcweir     while ( nLen > 0 )
377*cdf0e10cSrcweir     {
378*cdf0e10cSrcweir         nLen--;
379*cdf0e10cSrcweir         pStr--;
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir         if ( *pStr == c )
382*cdf0e10cSrcweir             return nLen;
383*cdf0e10cSrcweir     }
384*cdf0e10cSrcweir 
385*cdf0e10cSrcweir     return -1;
386*cdf0e10cSrcweir }
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir sal_Int32 SAL_CALL IMPL_RTL_STRNAME( indexOfStr )( const IMPL_RTL_STRCODE* pStr,
391*cdf0e10cSrcweir                                                    const IMPL_RTL_STRCODE* pSubStr )
392*cdf0e10cSrcweir {
393*cdf0e10cSrcweir     return IMPL_RTL_STRNAME( indexOfStr_WithLength )( pStr, IMPL_RTL_STRNAME( getLength )( pStr ),
394*cdf0e10cSrcweir                                                       pSubStr, IMPL_RTL_STRNAME( getLength )( pSubStr ) );
395*cdf0e10cSrcweir }
396*cdf0e10cSrcweir 
397*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir sal_Int32 SAL_CALL IMPL_RTL_STRNAME( indexOfStr_WithLength )( const IMPL_RTL_STRCODE* pStr,
400*cdf0e10cSrcweir                                                               sal_Int32 nStrLen,
401*cdf0e10cSrcweir                                                               const  IMPL_RTL_STRCODE* pSubStr,
402*cdf0e10cSrcweir                                                               sal_Int32 nSubLen )
403*cdf0e10cSrcweir {
404*cdf0e10cSrcweir     /* faster search for a single character */
405*cdf0e10cSrcweir     if ( nSubLen < 2 )
406*cdf0e10cSrcweir     {
407*cdf0e10cSrcweir         /* an empty SubString is always not foundable */
408*cdf0e10cSrcweir         if ( nSubLen == 1 )
409*cdf0e10cSrcweir         {
410*cdf0e10cSrcweir             IMPL_RTL_STRCODE        c = *pSubStr;
411*cdf0e10cSrcweir             const IMPL_RTL_STRCODE* pTempStr = pStr;
412*cdf0e10cSrcweir             while ( nStrLen > 0 )
413*cdf0e10cSrcweir             {
414*cdf0e10cSrcweir                 if ( *pTempStr == c )
415*cdf0e10cSrcweir                     return pTempStr-pStr;
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir                 pTempStr++;
418*cdf0e10cSrcweir                 nStrLen--;
419*cdf0e10cSrcweir             }
420*cdf0e10cSrcweir         }
421*cdf0e10cSrcweir     }
422*cdf0e10cSrcweir     else
423*cdf0e10cSrcweir     {
424*cdf0e10cSrcweir         const IMPL_RTL_STRCODE* pTempStr = pStr;
425*cdf0e10cSrcweir         while ( nStrLen > 0 )
426*cdf0e10cSrcweir         {
427*cdf0e10cSrcweir             if ( *pTempStr == *pSubStr )
428*cdf0e10cSrcweir             {
429*cdf0e10cSrcweir                 /* Compare SubString */
430*cdf0e10cSrcweir                 if ( nSubLen <= nStrLen )
431*cdf0e10cSrcweir                 {
432*cdf0e10cSrcweir                     const IMPL_RTL_STRCODE* pTempStr1 = pTempStr;
433*cdf0e10cSrcweir                     const IMPL_RTL_STRCODE* pTempStr2 = pSubStr;
434*cdf0e10cSrcweir                     sal_Int32               nTempLen = nSubLen;
435*cdf0e10cSrcweir                     while ( nTempLen )
436*cdf0e10cSrcweir                     {
437*cdf0e10cSrcweir                         if ( *pTempStr1 != *pTempStr2 )
438*cdf0e10cSrcweir                             break;
439*cdf0e10cSrcweir 
440*cdf0e10cSrcweir                         pTempStr1++;
441*cdf0e10cSrcweir                         pTempStr2++;
442*cdf0e10cSrcweir                         nTempLen--;
443*cdf0e10cSrcweir                     }
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir                     if ( !nTempLen )
446*cdf0e10cSrcweir                         return pTempStr-pStr;
447*cdf0e10cSrcweir                 }
448*cdf0e10cSrcweir                 else
449*cdf0e10cSrcweir                     break;
450*cdf0e10cSrcweir             }
451*cdf0e10cSrcweir 
452*cdf0e10cSrcweir             nStrLen--;
453*cdf0e10cSrcweir             pTempStr++;
454*cdf0e10cSrcweir         }
455*cdf0e10cSrcweir     }
456*cdf0e10cSrcweir 
457*cdf0e10cSrcweir     return -1;
458*cdf0e10cSrcweir }
459*cdf0e10cSrcweir 
460*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
461*cdf0e10cSrcweir 
462*cdf0e10cSrcweir sal_Int32 SAL_CALL IMPL_RTL_STRNAME( lastIndexOfStr )( const IMPL_RTL_STRCODE* pStr,
463*cdf0e10cSrcweir                                                        const IMPL_RTL_STRCODE* pSubStr )
464*cdf0e10cSrcweir {
465*cdf0e10cSrcweir     return IMPL_RTL_STRNAME( lastIndexOfStr_WithLength )( pStr, IMPL_RTL_STRNAME( getLength )( pStr ),
466*cdf0e10cSrcweir                                                           pSubStr, IMPL_RTL_STRNAME( getLength )( pSubStr ) );
467*cdf0e10cSrcweir }
468*cdf0e10cSrcweir 
469*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
470*cdf0e10cSrcweir 
471*cdf0e10cSrcweir sal_Int32 SAL_CALL IMPL_RTL_STRNAME( lastIndexOfStr_WithLength )( const IMPL_RTL_STRCODE* pStr,
472*cdf0e10cSrcweir                                                                   sal_Int32 nStrLen,
473*cdf0e10cSrcweir                                                                   const IMPL_RTL_STRCODE* pSubStr,
474*cdf0e10cSrcweir                                                                   sal_Int32 nSubLen )
475*cdf0e10cSrcweir {
476*cdf0e10cSrcweir     /* faster search for a single character */
477*cdf0e10cSrcweir     if ( nSubLen < 2 )
478*cdf0e10cSrcweir     {
479*cdf0e10cSrcweir         /* an empty SubString is always not foundable */
480*cdf0e10cSrcweir         if ( nSubLen == 1 )
481*cdf0e10cSrcweir         {
482*cdf0e10cSrcweir             IMPL_RTL_STRCODE c = *pSubStr;
483*cdf0e10cSrcweir             pStr += nStrLen;
484*cdf0e10cSrcweir             while ( nStrLen > 0 )
485*cdf0e10cSrcweir             {
486*cdf0e10cSrcweir                 nStrLen--;
487*cdf0e10cSrcweir                 pStr--;
488*cdf0e10cSrcweir 
489*cdf0e10cSrcweir                 if ( *pStr == c )
490*cdf0e10cSrcweir                     return nStrLen;
491*cdf0e10cSrcweir             }
492*cdf0e10cSrcweir         }
493*cdf0e10cSrcweir     }
494*cdf0e10cSrcweir     else
495*cdf0e10cSrcweir     {
496*cdf0e10cSrcweir         pStr += nStrLen;
497*cdf0e10cSrcweir         nStrLen -= nSubLen;
498*cdf0e10cSrcweir         pStr -= nSubLen;
499*cdf0e10cSrcweir         while ( nStrLen >= 0 )
500*cdf0e10cSrcweir         {
501*cdf0e10cSrcweir             const IMPL_RTL_STRCODE* pTempStr1 = pStr;
502*cdf0e10cSrcweir             const IMPL_RTL_STRCODE* pTempStr2 = pSubStr;
503*cdf0e10cSrcweir             sal_Int32               nTempLen = nSubLen;
504*cdf0e10cSrcweir             while ( nTempLen )
505*cdf0e10cSrcweir             {
506*cdf0e10cSrcweir                 if ( *pTempStr1 != *pTempStr2 )
507*cdf0e10cSrcweir                     break;
508*cdf0e10cSrcweir 
509*cdf0e10cSrcweir                 pTempStr1++;
510*cdf0e10cSrcweir                 pTempStr2++;
511*cdf0e10cSrcweir                 nTempLen--;
512*cdf0e10cSrcweir             }
513*cdf0e10cSrcweir 
514*cdf0e10cSrcweir             if ( !nTempLen )
515*cdf0e10cSrcweir                 return nStrLen;
516*cdf0e10cSrcweir 
517*cdf0e10cSrcweir             nStrLen--;
518*cdf0e10cSrcweir             pStr--;
519*cdf0e10cSrcweir         }
520*cdf0e10cSrcweir     }
521*cdf0e10cSrcweir 
522*cdf0e10cSrcweir     return -1;
523*cdf0e10cSrcweir }
524*cdf0e10cSrcweir 
525*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir void SAL_CALL IMPL_RTL_STRNAME( replaceChar )( IMPL_RTL_STRCODE* pStr,
528*cdf0e10cSrcweir                                                IMPL_RTL_STRCODE cOld,
529*cdf0e10cSrcweir                                                IMPL_RTL_STRCODE cNew )
530*cdf0e10cSrcweir {
531*cdf0e10cSrcweir     while ( *pStr )
532*cdf0e10cSrcweir     {
533*cdf0e10cSrcweir         if ( *pStr == cOld )
534*cdf0e10cSrcweir             *pStr = cNew;
535*cdf0e10cSrcweir 
536*cdf0e10cSrcweir         pStr++;
537*cdf0e10cSrcweir     }
538*cdf0e10cSrcweir }
539*cdf0e10cSrcweir 
540*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
541*cdf0e10cSrcweir 
542*cdf0e10cSrcweir void SAL_CALL IMPL_RTL_STRNAME( replaceChar_WithLength )( IMPL_RTL_STRCODE* pStr,
543*cdf0e10cSrcweir                                                           sal_Int32 nLen,
544*cdf0e10cSrcweir                                                           IMPL_RTL_STRCODE cOld,
545*cdf0e10cSrcweir                                                           IMPL_RTL_STRCODE cNew )
546*cdf0e10cSrcweir {
547*cdf0e10cSrcweir     while ( nLen > 0 )
548*cdf0e10cSrcweir     {
549*cdf0e10cSrcweir         if ( *pStr == cOld )
550*cdf0e10cSrcweir             *pStr = cNew;
551*cdf0e10cSrcweir 
552*cdf0e10cSrcweir         pStr++;
553*cdf0e10cSrcweir         nLen--;
554*cdf0e10cSrcweir     }
555*cdf0e10cSrcweir }
556*cdf0e10cSrcweir 
557*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
558*cdf0e10cSrcweir 
559*cdf0e10cSrcweir void SAL_CALL IMPL_RTL_STRNAME( toAsciiLowerCase )( IMPL_RTL_STRCODE* pStr )
560*cdf0e10cSrcweir {
561*cdf0e10cSrcweir     while ( *pStr )
562*cdf0e10cSrcweir     {
563*cdf0e10cSrcweir         /* Between A-Z (65-90), than to lowercase (+32) */
564*cdf0e10cSrcweir         if ( (*pStr >= 65) && (*pStr <= 90) )
565*cdf0e10cSrcweir             *pStr += 32;
566*cdf0e10cSrcweir 
567*cdf0e10cSrcweir         pStr++;
568*cdf0e10cSrcweir     }
569*cdf0e10cSrcweir }
570*cdf0e10cSrcweir 
571*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
572*cdf0e10cSrcweir 
573*cdf0e10cSrcweir void SAL_CALL IMPL_RTL_STRNAME( toAsciiLowerCase_WithLength )( IMPL_RTL_STRCODE* pStr,
574*cdf0e10cSrcweir                                                                sal_Int32 nLen )
575*cdf0e10cSrcweir {
576*cdf0e10cSrcweir     while ( nLen > 0 )
577*cdf0e10cSrcweir     {
578*cdf0e10cSrcweir         /* Between A-Z (65-90), than to lowercase (+32) */
579*cdf0e10cSrcweir         if ( (*pStr >= 65) && (*pStr <= 90) )
580*cdf0e10cSrcweir             *pStr += 32;
581*cdf0e10cSrcweir 
582*cdf0e10cSrcweir         pStr++;
583*cdf0e10cSrcweir         nLen--;
584*cdf0e10cSrcweir     }
585*cdf0e10cSrcweir }
586*cdf0e10cSrcweir 
587*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
588*cdf0e10cSrcweir 
589*cdf0e10cSrcweir void SAL_CALL IMPL_RTL_STRNAME( toAsciiUpperCase )( IMPL_RTL_STRCODE* pStr )
590*cdf0e10cSrcweir {
591*cdf0e10cSrcweir     while ( *pStr )
592*cdf0e10cSrcweir     {
593*cdf0e10cSrcweir         /* Between a-z (97-122), than to uppercase (-32) */
594*cdf0e10cSrcweir         if ( (*pStr >= 97) && (*pStr <= 122) )
595*cdf0e10cSrcweir             *pStr -= 32;
596*cdf0e10cSrcweir 
597*cdf0e10cSrcweir         pStr++;
598*cdf0e10cSrcweir     }
599*cdf0e10cSrcweir }
600*cdf0e10cSrcweir 
601*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
602*cdf0e10cSrcweir 
603*cdf0e10cSrcweir void SAL_CALL IMPL_RTL_STRNAME( toAsciiUpperCase_WithLength )( IMPL_RTL_STRCODE* pStr,
604*cdf0e10cSrcweir                                                                sal_Int32 nLen )
605*cdf0e10cSrcweir {
606*cdf0e10cSrcweir     while ( nLen > 0 )
607*cdf0e10cSrcweir     {
608*cdf0e10cSrcweir         /* Between a-z (97-122), than to uppercase (-32) */
609*cdf0e10cSrcweir         if ( (*pStr >= 97) && (*pStr <= 122) )
610*cdf0e10cSrcweir             *pStr -= 32;
611*cdf0e10cSrcweir 
612*cdf0e10cSrcweir         pStr++;
613*cdf0e10cSrcweir         nLen--;
614*cdf0e10cSrcweir     }
615*cdf0e10cSrcweir }
616*cdf0e10cSrcweir 
617*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
618*cdf0e10cSrcweir 
619*cdf0e10cSrcweir sal_Int32 SAL_CALL IMPL_RTL_STRNAME( trim )( IMPL_RTL_STRCODE* pStr )
620*cdf0e10cSrcweir {
621*cdf0e10cSrcweir     return IMPL_RTL_STRNAME( trim_WithLength )( pStr, IMPL_RTL_STRNAME( getLength )( pStr ) );
622*cdf0e10cSrcweir }
623*cdf0e10cSrcweir 
624*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
625*cdf0e10cSrcweir 
626*cdf0e10cSrcweir sal_Int32 SAL_CALL IMPL_RTL_STRNAME( trim_WithLength )( IMPL_RTL_STRCODE* pStr, sal_Int32 nLen )
627*cdf0e10cSrcweir {
628*cdf0e10cSrcweir     sal_Int32 nPreSpaces    = 0;
629*cdf0e10cSrcweir     sal_Int32 nPostSpaces   = 0;
630*cdf0e10cSrcweir     sal_Int32 nIndex        = nLen-1;
631*cdf0e10cSrcweir 
632*cdf0e10cSrcweir     while ( (nPreSpaces < nLen) && rtl_ImplIsWhitespace( IMPL_RTL_USTRCODE(*(pStr+nPreSpaces)) ) )
633*cdf0e10cSrcweir         nPreSpaces++;
634*cdf0e10cSrcweir 
635*cdf0e10cSrcweir     while ( (nIndex > nPreSpaces) && rtl_ImplIsWhitespace( IMPL_RTL_USTRCODE(*(pStr+nIndex)) ) )
636*cdf0e10cSrcweir     {
637*cdf0e10cSrcweir         nPostSpaces++;
638*cdf0e10cSrcweir         nIndex--;
639*cdf0e10cSrcweir     }
640*cdf0e10cSrcweir 
641*cdf0e10cSrcweir     if ( nPostSpaces )
642*cdf0e10cSrcweir     {
643*cdf0e10cSrcweir         nLen -= nPostSpaces;
644*cdf0e10cSrcweir         *(pStr+nLen) = 0;
645*cdf0e10cSrcweir     }
646*cdf0e10cSrcweir 
647*cdf0e10cSrcweir     if ( nPreSpaces )
648*cdf0e10cSrcweir     {
649*cdf0e10cSrcweir         IMPL_RTL_STRCODE* pNewStr = pStr+nPreSpaces;
650*cdf0e10cSrcweir 
651*cdf0e10cSrcweir         nLen -= nPreSpaces;
652*cdf0e10cSrcweir         nIndex = nLen;
653*cdf0e10cSrcweir 
654*cdf0e10cSrcweir         while ( nIndex )
655*cdf0e10cSrcweir         {
656*cdf0e10cSrcweir             *pStr = *pNewStr;
657*cdf0e10cSrcweir             pStr++;
658*cdf0e10cSrcweir             pNewStr++;
659*cdf0e10cSrcweir             nIndex--;
660*cdf0e10cSrcweir         }
661*cdf0e10cSrcweir         *pStr = 0;
662*cdf0e10cSrcweir     }
663*cdf0e10cSrcweir 
664*cdf0e10cSrcweir     return nLen;
665*cdf0e10cSrcweir }
666*cdf0e10cSrcweir 
667*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
668*cdf0e10cSrcweir 
669*cdf0e10cSrcweir sal_Int32 SAL_CALL IMPL_RTL_STRNAME( valueOfBoolean )( IMPL_RTL_STRCODE* pStr, sal_Bool b )
670*cdf0e10cSrcweir {
671*cdf0e10cSrcweir     if ( b )
672*cdf0e10cSrcweir     {
673*cdf0e10cSrcweir         *pStr = 't';
674*cdf0e10cSrcweir         pStr++;
675*cdf0e10cSrcweir         *pStr = 'r';
676*cdf0e10cSrcweir         pStr++;
677*cdf0e10cSrcweir         *pStr = 'u';
678*cdf0e10cSrcweir         pStr++;
679*cdf0e10cSrcweir         *pStr = 'e';
680*cdf0e10cSrcweir         pStr++;
681*cdf0e10cSrcweir         *pStr = 0;
682*cdf0e10cSrcweir         return 4;
683*cdf0e10cSrcweir     }
684*cdf0e10cSrcweir     else
685*cdf0e10cSrcweir     {
686*cdf0e10cSrcweir         *pStr = 'f';
687*cdf0e10cSrcweir         pStr++;
688*cdf0e10cSrcweir         *pStr = 'a';
689*cdf0e10cSrcweir         pStr++;
690*cdf0e10cSrcweir         *pStr = 'l';
691*cdf0e10cSrcweir         pStr++;
692*cdf0e10cSrcweir         *pStr = 's';
693*cdf0e10cSrcweir         pStr++;
694*cdf0e10cSrcweir         *pStr = 'e';
695*cdf0e10cSrcweir         pStr++;
696*cdf0e10cSrcweir         *pStr = 0;
697*cdf0e10cSrcweir         return 5;
698*cdf0e10cSrcweir     }
699*cdf0e10cSrcweir }
700*cdf0e10cSrcweir 
701*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
702*cdf0e10cSrcweir 
703*cdf0e10cSrcweir sal_Int32 SAL_CALL IMPL_RTL_STRNAME( valueOfChar )( IMPL_RTL_STRCODE* pStr,
704*cdf0e10cSrcweir                                                     IMPL_RTL_STRCODE c )
705*cdf0e10cSrcweir {
706*cdf0e10cSrcweir     *pStr++ = c;
707*cdf0e10cSrcweir     *pStr = 0;
708*cdf0e10cSrcweir     return 1;
709*cdf0e10cSrcweir }
710*cdf0e10cSrcweir 
711*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
712*cdf0e10cSrcweir 
713*cdf0e10cSrcweir sal_Int32 SAL_CALL IMPL_RTL_STRNAME( valueOfInt32 )( IMPL_RTL_STRCODE* pStr,
714*cdf0e10cSrcweir                                                      sal_Int32 n,
715*cdf0e10cSrcweir                                                      sal_Int16 nRadix )
716*cdf0e10cSrcweir {
717*cdf0e10cSrcweir     sal_Char    aBuf[RTL_STR_MAX_VALUEOFINT32];
718*cdf0e10cSrcweir     sal_Char*   pBuf = aBuf;
719*cdf0e10cSrcweir     sal_Int32   nLen = 0;
720*cdf0e10cSrcweir     sal_uInt32  nValue;
721*cdf0e10cSrcweir 
722*cdf0e10cSrcweir     /* Radix must be valid */
723*cdf0e10cSrcweir     if ( (nRadix < RTL_STR_MIN_RADIX) || (nRadix > RTL_STR_MAX_RADIX) )
724*cdf0e10cSrcweir         nRadix = 10;
725*cdf0e10cSrcweir 
726*cdf0e10cSrcweir     /* is value negativ */
727*cdf0e10cSrcweir     if ( n < 0 )
728*cdf0e10cSrcweir     {
729*cdf0e10cSrcweir         *pStr = '-';
730*cdf0e10cSrcweir         pStr++;
731*cdf0e10cSrcweir         nLen++;
732*cdf0e10cSrcweir         nValue = -n; /* FIXME this code is not portable for n == -2147483648
733*cdf0e10cSrcweir                         (smallest negative value for sal_Int32) */
734*cdf0e10cSrcweir     }
735*cdf0e10cSrcweir     else
736*cdf0e10cSrcweir         nValue = n;
737*cdf0e10cSrcweir 
738*cdf0e10cSrcweir     /* create a recursive buffer with all values, except the last one */
739*cdf0e10cSrcweir     do
740*cdf0e10cSrcweir     {
741*cdf0e10cSrcweir         sal_Char nDigit = (sal_Char)(nValue % nRadix);
742*cdf0e10cSrcweir         nValue /= nRadix;
743*cdf0e10cSrcweir         if ( nDigit > 9 )
744*cdf0e10cSrcweir             *pBuf = (nDigit-10) + 'a';
745*cdf0e10cSrcweir         else
746*cdf0e10cSrcweir             *pBuf = (nDigit + '0' );
747*cdf0e10cSrcweir         pBuf++;
748*cdf0e10cSrcweir     }
749*cdf0e10cSrcweir     while ( nValue > 0 );
750*cdf0e10cSrcweir 
751*cdf0e10cSrcweir     /* copy the values in the right direction into the destination buffer */
752*cdf0e10cSrcweir     do
753*cdf0e10cSrcweir     {
754*cdf0e10cSrcweir         pBuf--;
755*cdf0e10cSrcweir         *pStr = *pBuf;
756*cdf0e10cSrcweir         pStr++;
757*cdf0e10cSrcweir         nLen++;
758*cdf0e10cSrcweir     }
759*cdf0e10cSrcweir     while ( pBuf != aBuf );
760*cdf0e10cSrcweir     *pStr = 0;
761*cdf0e10cSrcweir 
762*cdf0e10cSrcweir     return nLen;
763*cdf0e10cSrcweir }
764*cdf0e10cSrcweir 
765*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
766*cdf0e10cSrcweir 
767*cdf0e10cSrcweir sal_Int32 SAL_CALL IMPL_RTL_STRNAME( valueOfInt64 )( IMPL_RTL_STRCODE* pStr,
768*cdf0e10cSrcweir                                                      sal_Int64 n,
769*cdf0e10cSrcweir                                                      sal_Int16 nRadix )
770*cdf0e10cSrcweir {
771*cdf0e10cSrcweir     sal_Char    aBuf[RTL_STR_MAX_VALUEOFINT64];
772*cdf0e10cSrcweir     sal_Char*   pBuf = aBuf;
773*cdf0e10cSrcweir     sal_Int32   nLen = 0;
774*cdf0e10cSrcweir     sal_uInt64  nValue;
775*cdf0e10cSrcweir 
776*cdf0e10cSrcweir     /* Radix must be valid */
777*cdf0e10cSrcweir     if ( (nRadix < RTL_STR_MIN_RADIX) || (nRadix > RTL_STR_MAX_RADIX) )
778*cdf0e10cSrcweir         nRadix = 10;
779*cdf0e10cSrcweir 
780*cdf0e10cSrcweir     /* is value negativ */
781*cdf0e10cSrcweir     if ( n < 0 )
782*cdf0e10cSrcweir     {
783*cdf0e10cSrcweir         *pStr = '-';
784*cdf0e10cSrcweir         pStr++;
785*cdf0e10cSrcweir         nLen++;
786*cdf0e10cSrcweir         nValue = -n; /* FIXME this code is not portable for
787*cdf0e10cSrcweir                         n == -9223372036854775808 (smallest negative value for
788*cdf0e10cSrcweir                         sal_Int64) */
789*cdf0e10cSrcweir     }
790*cdf0e10cSrcweir     else
791*cdf0e10cSrcweir         nValue = n;
792*cdf0e10cSrcweir 
793*cdf0e10cSrcweir     /* create a recursive buffer with all values, except the last one */
794*cdf0e10cSrcweir     do
795*cdf0e10cSrcweir     {
796*cdf0e10cSrcweir         sal_Char nDigit = (sal_Char)(nValue % nRadix);
797*cdf0e10cSrcweir         nValue /= nRadix;
798*cdf0e10cSrcweir         if ( nDigit > 9 )
799*cdf0e10cSrcweir             *pBuf = (nDigit-10) + 'a';
800*cdf0e10cSrcweir         else
801*cdf0e10cSrcweir             *pBuf = (nDigit + '0' );
802*cdf0e10cSrcweir         pBuf++;
803*cdf0e10cSrcweir     }
804*cdf0e10cSrcweir     while ( nValue > 0 );
805*cdf0e10cSrcweir 
806*cdf0e10cSrcweir     /* copy the values in the right direction into the destination buffer */
807*cdf0e10cSrcweir     do
808*cdf0e10cSrcweir     {
809*cdf0e10cSrcweir         pBuf--;
810*cdf0e10cSrcweir         *pStr = *pBuf;
811*cdf0e10cSrcweir         pStr++;
812*cdf0e10cSrcweir         nLen++;
813*cdf0e10cSrcweir     }
814*cdf0e10cSrcweir     while ( pBuf != aBuf );
815*cdf0e10cSrcweir     *pStr = 0;
816*cdf0e10cSrcweir 
817*cdf0e10cSrcweir     return nLen;
818*cdf0e10cSrcweir }
819*cdf0e10cSrcweir 
820*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
821*cdf0e10cSrcweir 
822*cdf0e10cSrcweir sal_Bool SAL_CALL IMPL_RTL_STRNAME( toBoolean )( const IMPL_RTL_STRCODE* pStr )
823*cdf0e10cSrcweir {
824*cdf0e10cSrcweir     if ( *pStr == '1' )
825*cdf0e10cSrcweir         return sal_True;
826*cdf0e10cSrcweir 
827*cdf0e10cSrcweir     if ( (*pStr == 'T') || (*pStr == 't') )
828*cdf0e10cSrcweir     {
829*cdf0e10cSrcweir         pStr++;
830*cdf0e10cSrcweir         if ( (*pStr == 'R') || (*pStr == 'r') )
831*cdf0e10cSrcweir         {
832*cdf0e10cSrcweir             pStr++;
833*cdf0e10cSrcweir             if ( (*pStr == 'U') || (*pStr == 'u') )
834*cdf0e10cSrcweir             {
835*cdf0e10cSrcweir                 pStr++;
836*cdf0e10cSrcweir                 if ( (*pStr == 'E') || (*pStr == 'e') )
837*cdf0e10cSrcweir                     return sal_True;
838*cdf0e10cSrcweir             }
839*cdf0e10cSrcweir         }
840*cdf0e10cSrcweir     }
841*cdf0e10cSrcweir 
842*cdf0e10cSrcweir     return sal_False;
843*cdf0e10cSrcweir }
844*cdf0e10cSrcweir 
845*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
846*cdf0e10cSrcweir 
847*cdf0e10cSrcweir sal_Int32 SAL_CALL IMPL_RTL_STRNAME( toInt32 )( const IMPL_RTL_STRCODE* pStr,
848*cdf0e10cSrcweir                                                 sal_Int16 nRadix )
849*cdf0e10cSrcweir {
850*cdf0e10cSrcweir     sal_Bool    bNeg;
851*cdf0e10cSrcweir     sal_Int16   nDigit;
852*cdf0e10cSrcweir     sal_Int32   n = 0;
853*cdf0e10cSrcweir 
854*cdf0e10cSrcweir     if ( (nRadix < RTL_STR_MIN_RADIX) || (nRadix > RTL_STR_MAX_RADIX) )
855*cdf0e10cSrcweir         nRadix = 10;
856*cdf0e10cSrcweir 
857*cdf0e10cSrcweir     /* Skip whitespaces */
858*cdf0e10cSrcweir     while ( *pStr && rtl_ImplIsWhitespace( IMPL_RTL_USTRCODE( *pStr ) ) )
859*cdf0e10cSrcweir         pStr++;
860*cdf0e10cSrcweir 
861*cdf0e10cSrcweir     if ( *pStr == '-' )
862*cdf0e10cSrcweir     {
863*cdf0e10cSrcweir         bNeg = sal_True;
864*cdf0e10cSrcweir         pStr++;
865*cdf0e10cSrcweir     }
866*cdf0e10cSrcweir     else
867*cdf0e10cSrcweir     {
868*cdf0e10cSrcweir         if ( *pStr == '+' )
869*cdf0e10cSrcweir             pStr++;
870*cdf0e10cSrcweir         bNeg = sal_False;
871*cdf0e10cSrcweir     }
872*cdf0e10cSrcweir 
873*cdf0e10cSrcweir     while ( *pStr )
874*cdf0e10cSrcweir     {
875*cdf0e10cSrcweir         nDigit = rtl_ImplGetDigit( IMPL_RTL_USTRCODE( *pStr ), nRadix );
876*cdf0e10cSrcweir         if ( nDigit < 0 )
877*cdf0e10cSrcweir             break;
878*cdf0e10cSrcweir 
879*cdf0e10cSrcweir         n *= nRadix;
880*cdf0e10cSrcweir         n += nDigit;
881*cdf0e10cSrcweir 
882*cdf0e10cSrcweir         pStr++;
883*cdf0e10cSrcweir     }
884*cdf0e10cSrcweir 
885*cdf0e10cSrcweir     if ( bNeg )
886*cdf0e10cSrcweir         return -n;
887*cdf0e10cSrcweir     else
888*cdf0e10cSrcweir         return n;
889*cdf0e10cSrcweir }
890*cdf0e10cSrcweir 
891*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
892*cdf0e10cSrcweir 
893*cdf0e10cSrcweir sal_Int64 SAL_CALL IMPL_RTL_STRNAME( toInt64 )( const IMPL_RTL_STRCODE* pStr,
894*cdf0e10cSrcweir                                                 sal_Int16 nRadix )
895*cdf0e10cSrcweir {
896*cdf0e10cSrcweir     sal_Bool    bNeg;
897*cdf0e10cSrcweir     sal_Int16   nDigit;
898*cdf0e10cSrcweir     sal_Int64   n = 0;
899*cdf0e10cSrcweir 
900*cdf0e10cSrcweir     if ( (nRadix < RTL_STR_MIN_RADIX) || (nRadix > RTL_STR_MAX_RADIX) )
901*cdf0e10cSrcweir         nRadix = 10;
902*cdf0e10cSrcweir 
903*cdf0e10cSrcweir     /* Skip whitespaces */
904*cdf0e10cSrcweir     while ( *pStr && rtl_ImplIsWhitespace( IMPL_RTL_USTRCODE( *pStr ) ) )
905*cdf0e10cSrcweir         pStr++;
906*cdf0e10cSrcweir 
907*cdf0e10cSrcweir     if ( *pStr == '-' )
908*cdf0e10cSrcweir     {
909*cdf0e10cSrcweir         bNeg = sal_True;
910*cdf0e10cSrcweir         pStr++;
911*cdf0e10cSrcweir     }
912*cdf0e10cSrcweir     else
913*cdf0e10cSrcweir     {
914*cdf0e10cSrcweir         if ( *pStr == '+' )
915*cdf0e10cSrcweir             pStr++;
916*cdf0e10cSrcweir         bNeg = sal_False;
917*cdf0e10cSrcweir     }
918*cdf0e10cSrcweir 
919*cdf0e10cSrcweir     while ( *pStr )
920*cdf0e10cSrcweir     {
921*cdf0e10cSrcweir         nDigit = rtl_ImplGetDigit( IMPL_RTL_USTRCODE( *pStr ), nRadix );
922*cdf0e10cSrcweir         if ( nDigit < 0 )
923*cdf0e10cSrcweir             break;
924*cdf0e10cSrcweir 
925*cdf0e10cSrcweir         n *= nRadix;
926*cdf0e10cSrcweir         n += nDigit;
927*cdf0e10cSrcweir 
928*cdf0e10cSrcweir         pStr++;
929*cdf0e10cSrcweir     }
930*cdf0e10cSrcweir 
931*cdf0e10cSrcweir     if ( bNeg )
932*cdf0e10cSrcweir         return -n;
933*cdf0e10cSrcweir     else
934*cdf0e10cSrcweir         return n;
935*cdf0e10cSrcweir }
936*cdf0e10cSrcweir 
937*cdf0e10cSrcweir /* ======================================================================= */
938*cdf0e10cSrcweir /* Internal String-Class help functions                                    */
939*cdf0e10cSrcweir /* ======================================================================= */
940*cdf0e10cSrcweir 
941*cdf0e10cSrcweir static IMPL_RTL_STRINGDATA* IMPL_RTL_STRINGNAME( ImplAlloc )( sal_Int32 nLen )
942*cdf0e10cSrcweir {
943*cdf0e10cSrcweir     IMPL_RTL_STRINGDATA * pData
944*cdf0e10cSrcweir         = (SAL_INT_CAST(sal_uInt32, nLen)
945*cdf0e10cSrcweir            <= ((SAL_MAX_UINT32 - sizeof (IMPL_RTL_STRINGDATA))
946*cdf0e10cSrcweir                / sizeof (IMPL_RTL_STRCODE)))
947*cdf0e10cSrcweir         ? (IMPL_RTL_STRINGDATA *) rtl_allocateMemory(
948*cdf0e10cSrcweir             sizeof (IMPL_RTL_STRINGDATA) + nLen * sizeof (IMPL_RTL_STRCODE))
949*cdf0e10cSrcweir         : NULL;
950*cdf0e10cSrcweir     if (pData != NULL) {
951*cdf0e10cSrcweir         pData->refCount = 1;
952*cdf0e10cSrcweir         pData->length = nLen;
953*cdf0e10cSrcweir         pData->buffer[nLen] = 0;
954*cdf0e10cSrcweir     }
955*cdf0e10cSrcweir     return pData;
956*cdf0e10cSrcweir }
957*cdf0e10cSrcweir 
958*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
959*cdf0e10cSrcweir 
960*cdf0e10cSrcweir static IMPL_RTL_STRCODE* IMPL_RTL_STRINGNAME( ImplNewCopy )( IMPL_RTL_STRINGDATA** ppThis,
961*cdf0e10cSrcweir                                                              IMPL_RTL_STRINGDATA* pStr,
962*cdf0e10cSrcweir                                                              sal_Int32 nCount )
963*cdf0e10cSrcweir {
964*cdf0e10cSrcweir     IMPL_RTL_STRCODE*       pDest;
965*cdf0e10cSrcweir     const IMPL_RTL_STRCODE* pSrc;
966*cdf0e10cSrcweir     IMPL_RTL_STRINGDATA*    pData = IMPL_RTL_STRINGNAME( ImplAlloc )( pStr->length );
967*cdf0e10cSrcweir     OSL_ASSERT(pData != NULL);
968*cdf0e10cSrcweir 
969*cdf0e10cSrcweir     pDest   = pData->buffer;
970*cdf0e10cSrcweir     pSrc    = pStr->buffer;
971*cdf0e10cSrcweir     while ( nCount > 0 )
972*cdf0e10cSrcweir     {
973*cdf0e10cSrcweir         *pDest = *pSrc;
974*cdf0e10cSrcweir         pDest++;
975*cdf0e10cSrcweir         pSrc++;
976*cdf0e10cSrcweir         nCount--;
977*cdf0e10cSrcweir     }
978*cdf0e10cSrcweir 
979*cdf0e10cSrcweir     *ppThis = pData;
980*cdf0e10cSrcweir     return pDest;
981*cdf0e10cSrcweir }
982*cdf0e10cSrcweir 
983*cdf0e10cSrcweir /* ======================================================================= */
984*cdf0e10cSrcweir /* String-Class functions                                                  */
985*cdf0e10cSrcweir /* ======================================================================= */
986*cdf0e10cSrcweir 
987*cdf0e10cSrcweir #define IMPL_RTL_AQUIRE( pThis )                                \
988*cdf0e10cSrcweir {                                                               \
989*cdf0e10cSrcweir     if (!SAL_STRING_IS_STATIC (pThis))                          \
990*cdf0e10cSrcweir         osl_incrementInterlockedCount( &((pThis)->refCount) );  \
991*cdf0e10cSrcweir }
992*cdf0e10cSrcweir 
993*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
994*cdf0e10cSrcweir 
995*cdf0e10cSrcweir void SAL_CALL IMPL_RTL_STRINGNAME( acquire )( IMPL_RTL_STRINGDATA* pThis )
996*cdf0e10cSrcweir {
997*cdf0e10cSrcweir     IMPL_RTL_AQUIRE( pThis );
998*cdf0e10cSrcweir }
999*cdf0e10cSrcweir 
1000*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
1001*cdf0e10cSrcweir 
1002*cdf0e10cSrcweir void SAL_CALL IMPL_RTL_STRINGNAME( release )( IMPL_RTL_STRINGDATA* pThis )
1003*cdf0e10cSrcweir {
1004*cdf0e10cSrcweir     if (SAL_STRING_IS_STATIC (pThis))
1005*cdf0e10cSrcweir         return;
1006*cdf0e10cSrcweir 
1007*cdf0e10cSrcweir /* OString doesn't have an 'intern' */
1008*cdf0e10cSrcweir #ifdef IMPL_RTL_INTERN
1009*cdf0e10cSrcweir     if (SAL_STRING_IS_INTERN (pThis))
1010*cdf0e10cSrcweir     {
1011*cdf0e10cSrcweir         internRelease (pThis);
1012*cdf0e10cSrcweir         return;
1013*cdf0e10cSrcweir     }
1014*cdf0e10cSrcweir #endif
1015*cdf0e10cSrcweir 
1016*cdf0e10cSrcweir     if ( pThis->refCount == 1 ||
1017*cdf0e10cSrcweir          !osl_decrementInterlockedCount( &(pThis->refCount) ) )
1018*cdf0e10cSrcweir     {
1019*cdf0e10cSrcweir         rtl_freeMemory( pThis );
1020*cdf0e10cSrcweir     }
1021*cdf0e10cSrcweir }
1022*cdf0e10cSrcweir 
1023*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
1024*cdf0e10cSrcweir 
1025*cdf0e10cSrcweir void SAL_CALL IMPL_RTL_STRINGNAME( new )( IMPL_RTL_STRINGDATA** ppThis )
1026*cdf0e10cSrcweir {
1027*cdf0e10cSrcweir     if ( *ppThis)
1028*cdf0e10cSrcweir         IMPL_RTL_STRINGNAME( release )( *ppThis );
1029*cdf0e10cSrcweir 
1030*cdf0e10cSrcweir     *ppThis = (IMPL_RTL_STRINGDATA*) (&IMPL_RTL_EMPTYSTRING);
1031*cdf0e10cSrcweir     IMPL_RTL_AQUIRE( *ppThis );
1032*cdf0e10cSrcweir }
1033*cdf0e10cSrcweir 
1034*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
1035*cdf0e10cSrcweir 
1036*cdf0e10cSrcweir void SAL_CALL IMPL_RTL_STRINGNAME( new_WithLength )( IMPL_RTL_STRINGDATA** ppThis, sal_Int32 nLen )
1037*cdf0e10cSrcweir {
1038*cdf0e10cSrcweir     if ( nLen <= 0 )
1039*cdf0e10cSrcweir         IMPL_RTL_STRINGNAME( new )( ppThis );
1040*cdf0e10cSrcweir     else
1041*cdf0e10cSrcweir     {
1042*cdf0e10cSrcweir         if ( *ppThis)
1043*cdf0e10cSrcweir             IMPL_RTL_STRINGNAME( release )( *ppThis );
1044*cdf0e10cSrcweir 
1045*cdf0e10cSrcweir         *ppThis = IMPL_RTL_STRINGNAME( ImplAlloc )( nLen );
1046*cdf0e10cSrcweir         OSL_ASSERT(*ppThis != NULL);
1047*cdf0e10cSrcweir         (*ppThis)->length   = 0;
1048*cdf0e10cSrcweir 
1049*cdf0e10cSrcweir         {
1050*cdf0e10cSrcweir         IMPL_RTL_STRCODE* pTempStr = (*ppThis)->buffer;
1051*cdf0e10cSrcweir         while ( nLen >= 0 )
1052*cdf0e10cSrcweir         {
1053*cdf0e10cSrcweir             *pTempStr = 0;
1054*cdf0e10cSrcweir             pTempStr++;
1055*cdf0e10cSrcweir             nLen--;
1056*cdf0e10cSrcweir         }
1057*cdf0e10cSrcweir         }
1058*cdf0e10cSrcweir     }
1059*cdf0e10cSrcweir }
1060*cdf0e10cSrcweir 
1061*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
1062*cdf0e10cSrcweir 
1063*cdf0e10cSrcweir void SAL_CALL IMPL_RTL_STRINGNAME( newFromString )( IMPL_RTL_STRINGDATA** ppThis,
1064*cdf0e10cSrcweir                                                     const IMPL_RTL_STRINGDATA* pStr )
1065*cdf0e10cSrcweir {
1066*cdf0e10cSrcweir     IMPL_RTL_STRINGDATA* pOrg;
1067*cdf0e10cSrcweir 
1068*cdf0e10cSrcweir     if ( !pStr->length )
1069*cdf0e10cSrcweir     {
1070*cdf0e10cSrcweir         IMPL_RTL_STRINGNAME( new )( ppThis );
1071*cdf0e10cSrcweir         return;
1072*cdf0e10cSrcweir     }
1073*cdf0e10cSrcweir 
1074*cdf0e10cSrcweir     pOrg = *ppThis;
1075*cdf0e10cSrcweir     *ppThis = IMPL_RTL_STRINGNAME( ImplAlloc )( pStr->length );
1076*cdf0e10cSrcweir     OSL_ASSERT(*ppThis != NULL);
1077*cdf0e10cSrcweir     rtl_str_ImplCopy( (*ppThis)->buffer, pStr->buffer, pStr->length );
1078*cdf0e10cSrcweir 
1079*cdf0e10cSrcweir     /* must be done at least, if pStr == *ppThis */
1080*cdf0e10cSrcweir     if ( pOrg )
1081*cdf0e10cSrcweir         IMPL_RTL_STRINGNAME( release )( pOrg );
1082*cdf0e10cSrcweir }
1083*cdf0e10cSrcweir 
1084*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
1085*cdf0e10cSrcweir 
1086*cdf0e10cSrcweir void SAL_CALL IMPL_RTL_STRINGNAME( newFromStr )( IMPL_RTL_STRINGDATA** ppThis,
1087*cdf0e10cSrcweir                                                  const IMPL_RTL_STRCODE* pCharStr )
1088*cdf0e10cSrcweir {
1089*cdf0e10cSrcweir     IMPL_RTL_STRCODE*       pBuffer;
1090*cdf0e10cSrcweir     IMPL_RTL_STRINGDATA*    pOrg;
1091*cdf0e10cSrcweir     sal_Int32               nLen;
1092*cdf0e10cSrcweir 
1093*cdf0e10cSrcweir     if ( pCharStr )
1094*cdf0e10cSrcweir     {
1095*cdf0e10cSrcweir         const IMPL_RTL_STRCODE* pTempStr = pCharStr;
1096*cdf0e10cSrcweir         while( *pTempStr )
1097*cdf0e10cSrcweir             pTempStr++;
1098*cdf0e10cSrcweir         nLen = pTempStr-pCharStr;
1099*cdf0e10cSrcweir     }
1100*cdf0e10cSrcweir     else
1101*cdf0e10cSrcweir         nLen = 0;
1102*cdf0e10cSrcweir 
1103*cdf0e10cSrcweir     if ( !nLen )
1104*cdf0e10cSrcweir     {
1105*cdf0e10cSrcweir         IMPL_RTL_STRINGNAME( new )( ppThis );
1106*cdf0e10cSrcweir         return;
1107*cdf0e10cSrcweir     }
1108*cdf0e10cSrcweir 
1109*cdf0e10cSrcweir     pOrg = *ppThis;
1110*cdf0e10cSrcweir     *ppThis = IMPL_RTL_STRINGNAME( ImplAlloc )( nLen );
1111*cdf0e10cSrcweir     OSL_ASSERT(*ppThis != NULL);
1112*cdf0e10cSrcweir     pBuffer = (*ppThis)->buffer;
1113*cdf0e10cSrcweir     do
1114*cdf0e10cSrcweir     {
1115*cdf0e10cSrcweir         *pBuffer = *pCharStr;
1116*cdf0e10cSrcweir         pBuffer++;
1117*cdf0e10cSrcweir         pCharStr++;
1118*cdf0e10cSrcweir     }
1119*cdf0e10cSrcweir     while ( *pCharStr );
1120*cdf0e10cSrcweir 
1121*cdf0e10cSrcweir     /* must be done at least, if pCharStr == *ppThis */
1122*cdf0e10cSrcweir     if ( pOrg )
1123*cdf0e10cSrcweir         IMPL_RTL_STRINGNAME( release )( pOrg );
1124*cdf0e10cSrcweir }
1125*cdf0e10cSrcweir 
1126*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
1127*cdf0e10cSrcweir 
1128*cdf0e10cSrcweir void SAL_CALL IMPL_RTL_STRINGNAME( newFromStr_WithLength )( IMPL_RTL_STRINGDATA** ppThis,
1129*cdf0e10cSrcweir                                                             const IMPL_RTL_STRCODE* pCharStr,
1130*cdf0e10cSrcweir                                                             sal_Int32 nLen )
1131*cdf0e10cSrcweir {
1132*cdf0e10cSrcweir     IMPL_RTL_STRINGDATA* pOrg;
1133*cdf0e10cSrcweir 
1134*cdf0e10cSrcweir     if ( !pCharStr || (nLen <= 0) )
1135*cdf0e10cSrcweir     {
1136*cdf0e10cSrcweir         IMPL_RTL_STRINGNAME( new )( ppThis );
1137*cdf0e10cSrcweir         return;
1138*cdf0e10cSrcweir     }
1139*cdf0e10cSrcweir 
1140*cdf0e10cSrcweir     pOrg = *ppThis;
1141*cdf0e10cSrcweir     *ppThis = IMPL_RTL_STRINGNAME( ImplAlloc )( nLen );
1142*cdf0e10cSrcweir     OSL_ASSERT(*ppThis != NULL);
1143*cdf0e10cSrcweir     rtl_str_ImplCopy( (*ppThis)->buffer, pCharStr, nLen );
1144*cdf0e10cSrcweir 
1145*cdf0e10cSrcweir     /* must be done at least, if pCharStr == *ppThis */
1146*cdf0e10cSrcweir     if ( pOrg )
1147*cdf0e10cSrcweir         IMPL_RTL_STRINGNAME( release )( pOrg );
1148*cdf0e10cSrcweir }
1149*cdf0e10cSrcweir 
1150*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
1151*cdf0e10cSrcweir 
1152*cdf0e10cSrcweir void SAL_CALL IMPL_RTL_STRINGNAME( assign )( IMPL_RTL_STRINGDATA** ppThis,
1153*cdf0e10cSrcweir                                              IMPL_RTL_STRINGDATA* pStr )
1154*cdf0e10cSrcweir {
1155*cdf0e10cSrcweir     /* must be done at first, if pStr == *ppThis */
1156*cdf0e10cSrcweir     IMPL_RTL_AQUIRE( pStr );
1157*cdf0e10cSrcweir 
1158*cdf0e10cSrcweir     if ( *ppThis )
1159*cdf0e10cSrcweir         IMPL_RTL_STRINGNAME( release )( *ppThis );
1160*cdf0e10cSrcweir 
1161*cdf0e10cSrcweir     *ppThis = pStr;
1162*cdf0e10cSrcweir }
1163*cdf0e10cSrcweir 
1164*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
1165*cdf0e10cSrcweir 
1166*cdf0e10cSrcweir sal_Int32 SAL_CALL IMPL_RTL_STRINGNAME( getLength )( const IMPL_RTL_STRINGDATA* pThis )
1167*cdf0e10cSrcweir {
1168*cdf0e10cSrcweir     return pThis->length;
1169*cdf0e10cSrcweir }
1170*cdf0e10cSrcweir 
1171*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
1172*cdf0e10cSrcweir 
1173*cdf0e10cSrcweir IMPL_RTL_STRCODE* SAL_CALL IMPL_RTL_STRINGNAME( getStr )( IMPL_RTL_STRINGDATA * pThis )
1174*cdf0e10cSrcweir {
1175*cdf0e10cSrcweir     return pThis->buffer;
1176*cdf0e10cSrcweir }
1177*cdf0e10cSrcweir 
1178*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
1179*cdf0e10cSrcweir 
1180*cdf0e10cSrcweir void SAL_CALL IMPL_RTL_STRINGNAME( newConcat )( IMPL_RTL_STRINGDATA** ppThis,
1181*cdf0e10cSrcweir                                                 IMPL_RTL_STRINGDATA* pLeft,
1182*cdf0e10cSrcweir                                                 IMPL_RTL_STRINGDATA* pRight )
1183*cdf0e10cSrcweir {
1184*cdf0e10cSrcweir     IMPL_RTL_STRINGDATA* pOrg = *ppThis;
1185*cdf0e10cSrcweir 
1186*cdf0e10cSrcweir     /* Test for 0-Pointer - if not, change newReplaceStrAt! */
1187*cdf0e10cSrcweir     if ( !pRight || !pRight->length )
1188*cdf0e10cSrcweir     {
1189*cdf0e10cSrcweir         *ppThis = pLeft;
1190*cdf0e10cSrcweir         IMPL_RTL_AQUIRE( pLeft );
1191*cdf0e10cSrcweir     }
1192*cdf0e10cSrcweir     else if ( !pLeft || !pLeft->length )
1193*cdf0e10cSrcweir     {
1194*cdf0e10cSrcweir         *ppThis = pRight;
1195*cdf0e10cSrcweir         IMPL_RTL_AQUIRE( pRight );
1196*cdf0e10cSrcweir     }
1197*cdf0e10cSrcweir     else
1198*cdf0e10cSrcweir     {
1199*cdf0e10cSrcweir         IMPL_RTL_STRINGDATA* pTempStr = IMPL_RTL_STRINGNAME( ImplAlloc )( pLeft->length + pRight->length );
1200*cdf0e10cSrcweir         OSL_ASSERT(pTempStr != NULL);
1201*cdf0e10cSrcweir         rtl_str_ImplCopy( pTempStr->buffer, pLeft->buffer, pLeft->length );
1202*cdf0e10cSrcweir         rtl_str_ImplCopy( pTempStr->buffer+pLeft->length, pRight->buffer, pRight->length );
1203*cdf0e10cSrcweir         *ppThis = pTempStr;
1204*cdf0e10cSrcweir     }
1205*cdf0e10cSrcweir 
1206*cdf0e10cSrcweir     /* must be done at least, if left or right == *ppThis */
1207*cdf0e10cSrcweir     if ( pOrg )
1208*cdf0e10cSrcweir         IMPL_RTL_STRINGNAME( release )( pOrg );
1209*cdf0e10cSrcweir }
1210*cdf0e10cSrcweir 
1211*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
1212*cdf0e10cSrcweir 
1213*cdf0e10cSrcweir void SAL_CALL IMPL_RTL_STRINGNAME( newReplaceStrAt )( IMPL_RTL_STRINGDATA** ppThis,
1214*cdf0e10cSrcweir                                                       IMPL_RTL_STRINGDATA* pStr,
1215*cdf0e10cSrcweir                                                       sal_Int32 nIndex,
1216*cdf0e10cSrcweir                                                       sal_Int32 nCount,
1217*cdf0e10cSrcweir                                                       IMPL_RTL_STRINGDATA* pNewSubStr )
1218*cdf0e10cSrcweir {
1219*cdf0e10cSrcweir     /* Append? */
1220*cdf0e10cSrcweir     if ( nIndex >= pStr->length )
1221*cdf0e10cSrcweir     {
1222*cdf0e10cSrcweir         /* newConcat test, if pNewSubStr is 0 */
1223*cdf0e10cSrcweir         IMPL_RTL_STRINGNAME( newConcat )( ppThis, pStr, pNewSubStr );
1224*cdf0e10cSrcweir         return;
1225*cdf0e10cSrcweir     }
1226*cdf0e10cSrcweir 
1227*cdf0e10cSrcweir     /* negativ index? */
1228*cdf0e10cSrcweir     if ( nIndex < 0 )
1229*cdf0e10cSrcweir     {
1230*cdf0e10cSrcweir         nCount -= nIndex;
1231*cdf0e10cSrcweir         nIndex = 0;
1232*cdf0e10cSrcweir     }
1233*cdf0e10cSrcweir 
1234*cdf0e10cSrcweir     /* not more than the String length could be deleted */
1235*cdf0e10cSrcweir     if ( nCount >= pStr->length-nIndex )
1236*cdf0e10cSrcweir     {
1237*cdf0e10cSrcweir         nCount = pStr->length-nIndex;
1238*cdf0e10cSrcweir 
1239*cdf0e10cSrcweir         /* Assign of NewSubStr? */
1240*cdf0e10cSrcweir         if ( !nIndex && (nCount >= pStr->length) )
1241*cdf0e10cSrcweir         {
1242*cdf0e10cSrcweir             if ( !pNewSubStr )
1243*cdf0e10cSrcweir                 IMPL_RTL_STRINGNAME( new )( ppThis );
1244*cdf0e10cSrcweir             else
1245*cdf0e10cSrcweir                 IMPL_RTL_STRINGNAME( assign )( ppThis, pNewSubStr );
1246*cdf0e10cSrcweir             return;
1247*cdf0e10cSrcweir         }
1248*cdf0e10cSrcweir     }
1249*cdf0e10cSrcweir 
1250*cdf0e10cSrcweir     /* Assign of Str? */
1251*cdf0e10cSrcweir     if ( !nCount && (!pNewSubStr || !pNewSubStr->length) )
1252*cdf0e10cSrcweir     {
1253*cdf0e10cSrcweir         IMPL_RTL_STRINGNAME( assign )( ppThis, pStr );
1254*cdf0e10cSrcweir         return;
1255*cdf0e10cSrcweir     }
1256*cdf0e10cSrcweir 
1257*cdf0e10cSrcweir     {
1258*cdf0e10cSrcweir     IMPL_RTL_STRINGDATA*    pOrg = *ppThis;
1259*cdf0e10cSrcweir     IMPL_RTL_STRCODE*       pBuffer;
1260*cdf0e10cSrcweir     sal_Int32               nNewLen;
1261*cdf0e10cSrcweir 
1262*cdf0e10cSrcweir     /* Calculate length of the new string */
1263*cdf0e10cSrcweir     nNewLen = pStr->length-nCount;
1264*cdf0e10cSrcweir     if ( pNewSubStr )
1265*cdf0e10cSrcweir         nNewLen += pNewSubStr->length;
1266*cdf0e10cSrcweir 
1267*cdf0e10cSrcweir     /* Alloc New Buffer */
1268*cdf0e10cSrcweir     *ppThis = IMPL_RTL_STRINGNAME( ImplAlloc )( nNewLen );
1269*cdf0e10cSrcweir     OSL_ASSERT(*ppThis != NULL);
1270*cdf0e10cSrcweir     pBuffer = (*ppThis)->buffer;
1271*cdf0e10cSrcweir     if ( nIndex )
1272*cdf0e10cSrcweir     {
1273*cdf0e10cSrcweir         rtl_str_ImplCopy( pBuffer, pStr->buffer, nIndex );
1274*cdf0e10cSrcweir         pBuffer += nIndex;
1275*cdf0e10cSrcweir     }
1276*cdf0e10cSrcweir     if ( pNewSubStr && pNewSubStr->length )
1277*cdf0e10cSrcweir     {
1278*cdf0e10cSrcweir         rtl_str_ImplCopy( pBuffer, pNewSubStr->buffer, pNewSubStr->length );
1279*cdf0e10cSrcweir         pBuffer += pNewSubStr->length;
1280*cdf0e10cSrcweir     }
1281*cdf0e10cSrcweir     rtl_str_ImplCopy( pBuffer, pStr->buffer+nIndex+nCount, pStr->length-nIndex-nCount );
1282*cdf0e10cSrcweir 
1283*cdf0e10cSrcweir     /* must be done at least, if pStr or pNewSubStr == *ppThis */
1284*cdf0e10cSrcweir     if ( pOrg )
1285*cdf0e10cSrcweir         IMPL_RTL_STRINGNAME( release )( pOrg );
1286*cdf0e10cSrcweir     }
1287*cdf0e10cSrcweir }
1288*cdf0e10cSrcweir 
1289*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
1290*cdf0e10cSrcweir 
1291*cdf0e10cSrcweir void SAL_CALL IMPL_RTL_STRINGNAME( newReplace )( IMPL_RTL_STRINGDATA** ppThis,
1292*cdf0e10cSrcweir                                                  IMPL_RTL_STRINGDATA* pStr,
1293*cdf0e10cSrcweir                                                  IMPL_RTL_STRCODE cOld,
1294*cdf0e10cSrcweir                                                  IMPL_RTL_STRCODE cNew )
1295*cdf0e10cSrcweir {
1296*cdf0e10cSrcweir     IMPL_RTL_STRINGDATA*    pOrg        = *ppThis;
1297*cdf0e10cSrcweir     int                     bChanged    = 0;
1298*cdf0e10cSrcweir     sal_Int32               nLen        = pStr->length;
1299*cdf0e10cSrcweir     const IMPL_RTL_STRCODE* pCharStr    = pStr->buffer;
1300*cdf0e10cSrcweir 
1301*cdf0e10cSrcweir     while ( nLen > 0 )
1302*cdf0e10cSrcweir     {
1303*cdf0e10cSrcweir         if ( *pCharStr == cOld )
1304*cdf0e10cSrcweir         {
1305*cdf0e10cSrcweir             /* Copy String */
1306*cdf0e10cSrcweir             IMPL_RTL_STRCODE* pNewCharStr = IMPL_RTL_STRINGNAME( ImplNewCopy )( ppThis, pStr, pCharStr-pStr->buffer );
1307*cdf0e10cSrcweir 
1308*cdf0e10cSrcweir             /* replace/copy rest of the string */
1309*cdf0e10cSrcweir             if ( pNewCharStr )
1310*cdf0e10cSrcweir             {
1311*cdf0e10cSrcweir                 *pNewCharStr = cNew;
1312*cdf0e10cSrcweir                 pNewCharStr++;
1313*cdf0e10cSrcweir                 pCharStr++;
1314*cdf0e10cSrcweir                 nLen--;
1315*cdf0e10cSrcweir 
1316*cdf0e10cSrcweir                 while ( nLen > 0 )
1317*cdf0e10cSrcweir                 {
1318*cdf0e10cSrcweir                     if ( *pCharStr == cOld )
1319*cdf0e10cSrcweir                         *pNewCharStr = cNew;
1320*cdf0e10cSrcweir                     else
1321*cdf0e10cSrcweir                         *pNewCharStr = *pCharStr;
1322*cdf0e10cSrcweir 
1323*cdf0e10cSrcweir                     pNewCharStr++;
1324*cdf0e10cSrcweir                     pCharStr++;
1325*cdf0e10cSrcweir                     nLen--;
1326*cdf0e10cSrcweir                 }
1327*cdf0e10cSrcweir             }
1328*cdf0e10cSrcweir 
1329*cdf0e10cSrcweir             bChanged = 1;
1330*cdf0e10cSrcweir             break;
1331*cdf0e10cSrcweir         }
1332*cdf0e10cSrcweir 
1333*cdf0e10cSrcweir         pCharStr++;
1334*cdf0e10cSrcweir         nLen--;
1335*cdf0e10cSrcweir     }
1336*cdf0e10cSrcweir 
1337*cdf0e10cSrcweir     if ( !bChanged )
1338*cdf0e10cSrcweir     {
1339*cdf0e10cSrcweir         *ppThis = pStr;
1340*cdf0e10cSrcweir         IMPL_RTL_AQUIRE( pStr );
1341*cdf0e10cSrcweir     }
1342*cdf0e10cSrcweir 
1343*cdf0e10cSrcweir     /* must be done at least, if pStr == *ppThis */
1344*cdf0e10cSrcweir     if ( pOrg )
1345*cdf0e10cSrcweir         IMPL_RTL_STRINGNAME( release )( pOrg );
1346*cdf0e10cSrcweir }
1347*cdf0e10cSrcweir 
1348*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
1349*cdf0e10cSrcweir 
1350*cdf0e10cSrcweir void SAL_CALL IMPL_RTL_STRINGNAME( newToAsciiLowerCase )( IMPL_RTL_STRINGDATA** ppThis,
1351*cdf0e10cSrcweir                                                           IMPL_RTL_STRINGDATA* pStr )
1352*cdf0e10cSrcweir {
1353*cdf0e10cSrcweir     IMPL_RTL_STRINGDATA*    pOrg        = *ppThis;
1354*cdf0e10cSrcweir     int                     bChanged    = 0;
1355*cdf0e10cSrcweir     sal_Int32               nLen        = pStr->length;
1356*cdf0e10cSrcweir     const IMPL_RTL_STRCODE* pCharStr    = pStr->buffer;
1357*cdf0e10cSrcweir 
1358*cdf0e10cSrcweir     while ( nLen > 0 )
1359*cdf0e10cSrcweir     {
1360*cdf0e10cSrcweir         /* Between A-Z (65-90), than to lowercase (+32) */
1361*cdf0e10cSrcweir         if ( (*pCharStr >= 65) && (*pCharStr <= 90) )
1362*cdf0e10cSrcweir         {
1363*cdf0e10cSrcweir             /* Copy String */
1364*cdf0e10cSrcweir             IMPL_RTL_STRCODE* pNewCharStr = IMPL_RTL_STRINGNAME( ImplNewCopy )( ppThis, pStr, pCharStr-pStr->buffer );
1365*cdf0e10cSrcweir 
1366*cdf0e10cSrcweir             /* replace/copy rest of the string */
1367*cdf0e10cSrcweir             if ( pNewCharStr )
1368*cdf0e10cSrcweir             {
1369*cdf0e10cSrcweir                 /* to lowercase (+32) */
1370*cdf0e10cSrcweir                 *pNewCharStr = *pCharStr+32;
1371*cdf0e10cSrcweir                 pNewCharStr++;
1372*cdf0e10cSrcweir                 pCharStr++;
1373*cdf0e10cSrcweir                 nLen--;
1374*cdf0e10cSrcweir 
1375*cdf0e10cSrcweir                 while ( nLen > 0 )
1376*cdf0e10cSrcweir                 {
1377*cdf0e10cSrcweir                     /* Between A-Z (65-90), than to lowercase (+32) */
1378*cdf0e10cSrcweir                     if ( (*pCharStr >= 65) && (*pCharStr <= 90) )
1379*cdf0e10cSrcweir                         *pNewCharStr = *pCharStr+32;
1380*cdf0e10cSrcweir                     else
1381*cdf0e10cSrcweir                         *pNewCharStr = *pCharStr;
1382*cdf0e10cSrcweir 
1383*cdf0e10cSrcweir                     pNewCharStr++;
1384*cdf0e10cSrcweir                     pCharStr++;
1385*cdf0e10cSrcweir                     nLen--;
1386*cdf0e10cSrcweir                 }
1387*cdf0e10cSrcweir             }
1388*cdf0e10cSrcweir 
1389*cdf0e10cSrcweir             bChanged = 1;
1390*cdf0e10cSrcweir             break;
1391*cdf0e10cSrcweir         }
1392*cdf0e10cSrcweir 
1393*cdf0e10cSrcweir         pCharStr++;
1394*cdf0e10cSrcweir         nLen--;
1395*cdf0e10cSrcweir     }
1396*cdf0e10cSrcweir 
1397*cdf0e10cSrcweir     if ( !bChanged )
1398*cdf0e10cSrcweir     {
1399*cdf0e10cSrcweir         *ppThis = pStr;
1400*cdf0e10cSrcweir         IMPL_RTL_AQUIRE( pStr );
1401*cdf0e10cSrcweir     }
1402*cdf0e10cSrcweir 
1403*cdf0e10cSrcweir     /* must be done at least, if pStr == *ppThis */
1404*cdf0e10cSrcweir     if ( pOrg )
1405*cdf0e10cSrcweir         IMPL_RTL_STRINGNAME( release )( pOrg );
1406*cdf0e10cSrcweir }
1407*cdf0e10cSrcweir 
1408*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
1409*cdf0e10cSrcweir 
1410*cdf0e10cSrcweir void SAL_CALL IMPL_RTL_STRINGNAME( newToAsciiUpperCase )( IMPL_RTL_STRINGDATA** ppThis,
1411*cdf0e10cSrcweir                                                           IMPL_RTL_STRINGDATA* pStr )
1412*cdf0e10cSrcweir {
1413*cdf0e10cSrcweir     IMPL_RTL_STRINGDATA*    pOrg        = *ppThis;
1414*cdf0e10cSrcweir     int                     bChanged    = 0;
1415*cdf0e10cSrcweir     sal_Int32               nLen        = pStr->length;
1416*cdf0e10cSrcweir     const IMPL_RTL_STRCODE* pCharStr    = pStr->buffer;
1417*cdf0e10cSrcweir 
1418*cdf0e10cSrcweir     while ( nLen > 0 )
1419*cdf0e10cSrcweir     {
1420*cdf0e10cSrcweir         /* Between a-z (97-122), than to uppercase (-32) */
1421*cdf0e10cSrcweir         if ( (*pCharStr >= 97) && (*pCharStr <= 122) )
1422*cdf0e10cSrcweir         {
1423*cdf0e10cSrcweir             /* Copy String */
1424*cdf0e10cSrcweir             IMPL_RTL_STRCODE* pNewCharStr = IMPL_RTL_STRINGNAME( ImplNewCopy )( ppThis, pStr, pCharStr-pStr->buffer );
1425*cdf0e10cSrcweir 
1426*cdf0e10cSrcweir             /* replace/copy rest of the string */
1427*cdf0e10cSrcweir             if ( pNewCharStr )
1428*cdf0e10cSrcweir             {
1429*cdf0e10cSrcweir                 /* to uppercase (-32) */
1430*cdf0e10cSrcweir                 *pNewCharStr = *pCharStr-32;
1431*cdf0e10cSrcweir                 pNewCharStr++;
1432*cdf0e10cSrcweir                 pCharStr++;
1433*cdf0e10cSrcweir                 nLen--;
1434*cdf0e10cSrcweir 
1435*cdf0e10cSrcweir                 while ( nLen > 0 )
1436*cdf0e10cSrcweir                 {
1437*cdf0e10cSrcweir                     /* Between a-z (97-122), than to uppercase (-32) */
1438*cdf0e10cSrcweir                     if ( (*pCharStr >= 97) && (*pCharStr <= 122) )
1439*cdf0e10cSrcweir                         *pNewCharStr = *pCharStr-32;
1440*cdf0e10cSrcweir                     else
1441*cdf0e10cSrcweir                         *pNewCharStr = *pCharStr;
1442*cdf0e10cSrcweir 
1443*cdf0e10cSrcweir                     pNewCharStr++;
1444*cdf0e10cSrcweir                     pCharStr++;
1445*cdf0e10cSrcweir                     nLen--;
1446*cdf0e10cSrcweir                 }
1447*cdf0e10cSrcweir             }
1448*cdf0e10cSrcweir 
1449*cdf0e10cSrcweir             bChanged = 1;
1450*cdf0e10cSrcweir             break;
1451*cdf0e10cSrcweir         }
1452*cdf0e10cSrcweir 
1453*cdf0e10cSrcweir         pCharStr++;
1454*cdf0e10cSrcweir         nLen--;
1455*cdf0e10cSrcweir     }
1456*cdf0e10cSrcweir 
1457*cdf0e10cSrcweir     if ( !bChanged )
1458*cdf0e10cSrcweir     {
1459*cdf0e10cSrcweir         *ppThis = pStr;
1460*cdf0e10cSrcweir         IMPL_RTL_AQUIRE( pStr );
1461*cdf0e10cSrcweir     }
1462*cdf0e10cSrcweir 
1463*cdf0e10cSrcweir     /* must be done at least, if pStr == *ppThis */
1464*cdf0e10cSrcweir     if ( pOrg )
1465*cdf0e10cSrcweir         IMPL_RTL_STRINGNAME( release )( pOrg );
1466*cdf0e10cSrcweir }
1467*cdf0e10cSrcweir 
1468*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
1469*cdf0e10cSrcweir 
1470*cdf0e10cSrcweir void SAL_CALL IMPL_RTL_STRINGNAME( newTrim )( IMPL_RTL_STRINGDATA** ppThis,
1471*cdf0e10cSrcweir                                               IMPL_RTL_STRINGDATA* pStr )
1472*cdf0e10cSrcweir {
1473*cdf0e10cSrcweir     IMPL_RTL_STRINGDATA*    pOrg        = *ppThis;
1474*cdf0e10cSrcweir     const IMPL_RTL_STRCODE* pCharStr    = pStr->buffer;
1475*cdf0e10cSrcweir     sal_Int32               nPreSpaces  = 0;
1476*cdf0e10cSrcweir     sal_Int32               nPostSpaces = 0;
1477*cdf0e10cSrcweir     sal_Int32               nLen        = pStr->length;
1478*cdf0e10cSrcweir     sal_Int32               nIndex      = nLen-1;
1479*cdf0e10cSrcweir 
1480*cdf0e10cSrcweir     while ( (nPreSpaces < nLen) && rtl_ImplIsWhitespace( IMPL_RTL_USTRCODE(*(pCharStr+nPreSpaces)) ) )
1481*cdf0e10cSrcweir         nPreSpaces++;
1482*cdf0e10cSrcweir 
1483*cdf0e10cSrcweir     while ( (nIndex > nPreSpaces) && rtl_ImplIsWhitespace( IMPL_RTL_USTRCODE(*(pCharStr+nIndex)) ) )
1484*cdf0e10cSrcweir     {
1485*cdf0e10cSrcweir         nPostSpaces++;
1486*cdf0e10cSrcweir         nIndex--;
1487*cdf0e10cSrcweir     }
1488*cdf0e10cSrcweir 
1489*cdf0e10cSrcweir     if ( !nPreSpaces && !nPostSpaces )
1490*cdf0e10cSrcweir     {
1491*cdf0e10cSrcweir         *ppThis = pStr;
1492*cdf0e10cSrcweir         IMPL_RTL_AQUIRE( pStr );
1493*cdf0e10cSrcweir     }
1494*cdf0e10cSrcweir     else
1495*cdf0e10cSrcweir     {
1496*cdf0e10cSrcweir         nLen -= nPostSpaces+nPreSpaces;
1497*cdf0e10cSrcweir         *ppThis = IMPL_RTL_STRINGNAME( ImplAlloc )( nLen );
1498*cdf0e10cSrcweir         OSL_ASSERT(*ppThis != NULL);
1499*cdf0e10cSrcweir         if ( *ppThis )
1500*cdf0e10cSrcweir             rtl_str_ImplCopy( (*ppThis)->buffer, pStr->buffer+nPreSpaces, nLen );
1501*cdf0e10cSrcweir     }
1502*cdf0e10cSrcweir 
1503*cdf0e10cSrcweir     /* must be done at least, if pStr == *ppThis */
1504*cdf0e10cSrcweir     if ( pOrg )
1505*cdf0e10cSrcweir         IMPL_RTL_STRINGNAME( release )( pOrg );
1506*cdf0e10cSrcweir }
1507*cdf0e10cSrcweir 
1508*cdf0e10cSrcweir /* ----------------------------------------------------------------------- */
1509*cdf0e10cSrcweir 
1510*cdf0e10cSrcweir sal_Int32 SAL_CALL IMPL_RTL_STRINGNAME( getToken )( IMPL_RTL_STRINGDATA** ppThis,
1511*cdf0e10cSrcweir                                                     IMPL_RTL_STRINGDATA* pStr,
1512*cdf0e10cSrcweir                                                     sal_Int32 nToken,
1513*cdf0e10cSrcweir                                                     IMPL_RTL_STRCODE cTok,
1514*cdf0e10cSrcweir                                                     sal_Int32 nIndex )
1515*cdf0e10cSrcweir {
1516*cdf0e10cSrcweir     const IMPL_RTL_STRCODE* pCharStr        = pStr->buffer;
1517*cdf0e10cSrcweir     const IMPL_RTL_STRCODE* pCharStrStart;
1518*cdf0e10cSrcweir     const IMPL_RTL_STRCODE* pOrgCharStr;
1519*cdf0e10cSrcweir     sal_Int32               nLen            = pStr->length-nIndex;
1520*cdf0e10cSrcweir     sal_Int32               nTokCount       = 0;
1521*cdf0e10cSrcweir 
1522*cdf0e10cSrcweir     // Set ppThis to an empty string and return -1 if either nToken or nIndex is
1523*cdf0e10cSrcweir     // negative:
1524*cdf0e10cSrcweir     if (nIndex < 0) {
1525*cdf0e10cSrcweir         nToken = -1;
1526*cdf0e10cSrcweir     }
1527*cdf0e10cSrcweir 
1528*cdf0e10cSrcweir     pCharStr += nIndex;
1529*cdf0e10cSrcweir     pOrgCharStr = pCharStr;
1530*cdf0e10cSrcweir     pCharStrStart = pCharStr;
1531*cdf0e10cSrcweir     while ( nLen > 0 )
1532*cdf0e10cSrcweir     {
1533*cdf0e10cSrcweir         if ( *pCharStr == cTok )
1534*cdf0e10cSrcweir         {
1535*cdf0e10cSrcweir             nTokCount++;
1536*cdf0e10cSrcweir 
1537*cdf0e10cSrcweir             if ( nTokCount == nToken )
1538*cdf0e10cSrcweir                 pCharStrStart = pCharStr+1;
1539*cdf0e10cSrcweir             else
1540*cdf0e10cSrcweir             {
1541*cdf0e10cSrcweir                 if ( nTokCount > nToken )
1542*cdf0e10cSrcweir                     break;
1543*cdf0e10cSrcweir             }
1544*cdf0e10cSrcweir         }
1545*cdf0e10cSrcweir 
1546*cdf0e10cSrcweir         pCharStr++;
1547*cdf0e10cSrcweir         nLen--;
1548*cdf0e10cSrcweir     }
1549*cdf0e10cSrcweir 
1550*cdf0e10cSrcweir     if ( (nToken < 0) || (nTokCount < nToken) || (pCharStr == pCharStrStart) )
1551*cdf0e10cSrcweir     {
1552*cdf0e10cSrcweir         IMPL_RTL_STRINGNAME( new )( ppThis );
1553*cdf0e10cSrcweir         if( (nToken < 0) || (nTokCount < nToken ) )
1554*cdf0e10cSrcweir             return -1;
1555*cdf0e10cSrcweir         else if( nLen > 0 )
1556*cdf0e10cSrcweir             return nIndex+(pCharStr-pOrgCharStr)+1;
1557*cdf0e10cSrcweir         else return -1;
1558*cdf0e10cSrcweir     }
1559*cdf0e10cSrcweir     else
1560*cdf0e10cSrcweir     {
1561*cdf0e10cSrcweir         IMPL_RTL_STRINGNAME( newFromStr_WithLength )( ppThis, pCharStrStart, pCharStr-pCharStrStart );
1562*cdf0e10cSrcweir         if ( nLen )
1563*cdf0e10cSrcweir             return nIndex+(pCharStr-pOrgCharStr)+1;
1564*cdf0e10cSrcweir         else
1565*cdf0e10cSrcweir             return -1;
1566*cdf0e10cSrcweir     }
1567*cdf0e10cSrcweir }
1568