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