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