LCOV - code coverage report
Current view: top level - libreoffice/sal/rtl/source - strtmpl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 637 729 87.4 %
Date: 2012-12-17 Functions: 82 112 73.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : /* ======================================================================= */
      21             : /* Internal C-String help functions which could be used without the        */
      22             : /* String-Class                                                            */
      23             : /* ======================================================================= */
      24             : 
      25             : #include <string.h>
      26             : #include <sal/log.hxx>
      27             : 
      28             : /*
      29             : inline void rtl_str_ImplCopy( IMPL_RTL_STRCODE* pDest,
      30             :                               const IMPL_RTL_STRCODE* pSrc,
      31             :                               sal_Int32 nCount )
      32             : {
      33             :     while ( nCount > 0 )
      34             :     {
      35             :         *pDest = *pSrc;
      36             :         pDest++;
      37             :         pSrc++;
      38             :         nCount--;
      39             :     }
      40             : }
      41             : */
      42             : 
      43             : #define rtl_str_ImplCopy( _pDest, _pSrc, _nCount )                  \
      44             : {                                                                   \
      45             :     IMPL_RTL_STRCODE*       __mm_pDest      = _pDest;               \
      46             :     const IMPL_RTL_STRCODE* __mm_pSrc       = _pSrc;                \
      47             :     sal_Int32               __mm_nCount     = _nCount;              \
      48             :     while ( __mm_nCount > 0 )                                       \
      49             :     {                                                               \
      50             :         *__mm_pDest = *__mm_pSrc;                                   \
      51             :         __mm_pDest++;                                               \
      52             :         __mm_pSrc++;                                                \
      53             :         __mm_nCount--;                                              \
      54             :     }                                                               \
      55             : }
      56             : 
      57             : /* ======================================================================= */
      58             : /* C-String functions which could be used without the String-Class         */
      59             : /* ======================================================================= */
      60             : 
      61     5010524 : sal_Int32 SAL_CALL IMPL_RTL_STRNAME( getLength )( const IMPL_RTL_STRCODE* pStr )
      62             :     SAL_THROW_EXTERN_C()
      63             : {
      64     5010524 :     const IMPL_RTL_STRCODE* pTempStr = pStr;
      65   181473005 :     while( *pTempStr )
      66   171451957 :         pTempStr++;
      67     5010524 :     return pTempStr-pStr;
      68             : }
      69             : 
      70             : /* ----------------------------------------------------------------------- */
      71             : 
      72     1717307 : sal_Int32 SAL_CALL IMPL_RTL_STRNAME( compare )( const IMPL_RTL_STRCODE* pStr1,
      73             :                                                 const IMPL_RTL_STRCODE* pStr2 )
      74             :     SAL_THROW_EXTERN_C()
      75             : {
      76             :     sal_Int32 nRet;
      77    59960661 :     while ( ((nRet = ((sal_Int32)(IMPL_RTL_USTRCODE(*pStr1)))-
      78             :                      ((sal_Int32)(IMPL_RTL_USTRCODE(*pStr2)))) == 0) &&
      79             :             *pStr2 )
      80             :     {
      81    56526047 :         pStr1++;
      82    56526047 :         pStr2++;
      83             :     }
      84             : 
      85     1717307 :     return nRet;
      86             : }
      87             : 
      88             : /* ----------------------------------------------------------------------- */
      89             : 
      90   112057333 : sal_Int32 SAL_CALL IMPL_RTL_STRNAME( compare_WithLength )( const IMPL_RTL_STRCODE* pStr1,
      91             :                                                            sal_Int32 nStr1Len,
      92             :                                                            const IMPL_RTL_STRCODE* pStr2,
      93             :                                                            sal_Int32 nStr2Len )
      94             :     SAL_THROW_EXTERN_C()
      95             : {
      96   112057333 :     sal_Int32 nRet = nStr1Len - nStr2Len;
      97   112057333 :     int nCount = (nRet <= 0) ? nStr1Len : nStr2Len;
      98             : 
      99   112057333 :     --pStr1;
     100   112057333 :     --pStr2;
     101   112057333 :     while( (--nCount >= 0) && (*++pStr1 == *++pStr2) ) ;
     102             : 
     103   112057333 :     if( nCount >= 0 )
     104             :         nRet = ((sal_Int32)(IMPL_RTL_USTRCODE( *pStr1 )))
     105    71122700 :              - ((sal_Int32)(IMPL_RTL_USTRCODE( *pStr2 )));
     106             : 
     107   112057333 :     return nRet;
     108             : }
     109             : 
     110             : /* ----------------------------------------------------------------------- */
     111             : 
     112     2483684 : sal_Int32 SAL_CALL IMPL_RTL_STRNAME( shortenedCompare_WithLength )( const IMPL_RTL_STRCODE* pStr1,
     113             :                                                                     sal_Int32 nStr1Len,
     114             :                                                                     const IMPL_RTL_STRCODE* pStr2,
     115             :                                                                     sal_Int32 nStr2Len,
     116             :                                                                     sal_Int32 nShortenedLength )
     117             :     SAL_THROW_EXTERN_C()
     118             : {
     119     2483684 :     const IMPL_RTL_STRCODE* pStr1End = pStr1 + nStr1Len;
     120     2483684 :     const IMPL_RTL_STRCODE* pStr2End = pStr2 + nStr2Len;
     121             :     sal_Int32               nRet;
     122     6893736 :     while ( (nShortenedLength > 0) &&
     123             :             (pStr1 < pStr1End) && (pStr2 < pStr2End) )
     124             :     {
     125             :         nRet = ((sal_Int32)(IMPL_RTL_USTRCODE( *pStr1 )))-
     126     4254512 :                ((sal_Int32)(IMPL_RTL_USTRCODE( *pStr2 )));
     127     4254512 :         if ( nRet )
     128     2328144 :             return nRet;
     129             : 
     130     1926368 :         nShortenedLength--;
     131     1926368 :         pStr1++;
     132     1926368 :         pStr2++;
     133             :     }
     134             : 
     135      155540 :     if ( nShortenedLength <= 0 )
     136      122707 :         return 0;
     137       32833 :     return nStr1Len - nStr2Len;
     138             : }
     139             : 
     140             : /* ----------------------------------------------------------------------- */
     141             : 
     142     5728547 : sal_Int32 SAL_CALL IMPL_RTL_STRNAME( reverseCompare_WithLength )( const IMPL_RTL_STRCODE* pStr1,
     143             :                                                                   sal_Int32 nStr1Len,
     144             :                                                                   const IMPL_RTL_STRCODE* pStr2,
     145             :                                                                   sal_Int32 nStr2Len )
     146             :     SAL_THROW_EXTERN_C()
     147             : {
     148     5728547 :     const IMPL_RTL_STRCODE* pStr1Run = pStr1+nStr1Len;
     149     5728547 :     const IMPL_RTL_STRCODE* pStr2Run = pStr2+nStr2Len;
     150             :     sal_Int32               nRet;
     151    70785361 :     while ( (pStr1 < pStr1Run) && (pStr2 < pStr2Run) )
     152             :     {
     153    61705452 :         pStr1Run--;
     154    61705452 :         pStr2Run--;
     155             :         nRet = ((sal_Int32)(IMPL_RTL_USTRCODE( *pStr1Run )))-
     156    61705452 :                ((sal_Int32)(IMPL_RTL_USTRCODE( *pStr2Run )));
     157    61705452 :         if ( nRet )
     158     2377185 :             return nRet;
     159             :     }
     160             : 
     161     3351362 :     return nStr1Len - nStr2Len;
     162             : }
     163             : 
     164             : /* ----------------------------------------------------------------------- */
     165             : 
     166        7024 : sal_Int32 SAL_CALL IMPL_RTL_STRNAME( compareIgnoreAsciiCase )( const IMPL_RTL_STRCODE* pStr1,
     167             :                                                                const IMPL_RTL_STRCODE* pStr2 )
     168             :     SAL_THROW_EXTERN_C()
     169             : {
     170             :     sal_Int32   nRet;
     171             :     sal_Int32   c1;
     172             :     sal_Int32   c2;
     173        3664 :     do
     174             :     {
     175             :         /* If character between 'A' and 'Z', than convert it to lowercase */
     176        7024 :         c1 = (sal_Int32)IMPL_RTL_USTRCODE( *pStr1 );
     177        7024 :         c2 = (sal_Int32)IMPL_RTL_USTRCODE( *pStr2 );
     178        7024 :         if ( (c1 >= 65) && (c1 <= 90) )
     179        4976 :             c1 += 32;
     180        7024 :         if ( (c2 >= 65) && (c2 <= 90) )
     181        4972 :             c2 += 32;
     182        7024 :         nRet = c1-c2;
     183        7024 :         if ( nRet != 0 )
     184        3360 :             return nRet;
     185             : 
     186        3664 :         pStr1++;
     187        3664 :         pStr2++;
     188             :     }
     189             :     while ( c2 );
     190             : 
     191         604 :     return 0;
     192             : }
     193             : 
     194             : /* ----------------------------------------------------------------------- */
     195             : 
     196       39649 : sal_Int32 SAL_CALL IMPL_RTL_STRNAME( compareIgnoreAsciiCase_WithLength )( const IMPL_RTL_STRCODE* pStr1,
     197             :                                                                           sal_Int32 nStr1Len,
     198             :                                                                           const IMPL_RTL_STRCODE* pStr2,
     199             :                                                                           sal_Int32 nStr2Len )
     200             :     SAL_THROW_EXTERN_C()
     201             : {
     202       39649 :     const IMPL_RTL_STRCODE* pStr1End = pStr1 + nStr1Len;
     203       39649 :     const IMPL_RTL_STRCODE* pStr2End = pStr2 + nStr2Len;
     204             :     sal_Int32   nRet;
     205             :     sal_Int32   c1;
     206             :     sal_Int32   c2;
     207      273414 :     while ( (pStr1 < pStr1End) && (pStr2 < pStr2End) )
     208             :     {
     209             :         /* If character between 'A' and 'Z', than convert it to lowercase */
     210      217440 :         c1 = (sal_Int32)IMPL_RTL_USTRCODE( *pStr1 );
     211      217440 :         c2 = (sal_Int32)IMPL_RTL_USTRCODE( *pStr2 );
     212      217440 :         if ( (c1 >= 65) && (c1 <= 90) )
     213       45716 :             c1 += 32;
     214      217440 :         if ( (c2 >= 65) && (c2 <= 90) )
     215       24670 :             c2 += 32;
     216      217440 :         nRet = c1-c2;
     217      217440 :         if ( nRet != 0 )
     218       23324 :             return nRet;
     219             : 
     220      194116 :         pStr1++;
     221      194116 :         pStr2++;
     222             :     }
     223             : 
     224       16325 :     return nStr1Len - nStr2Len;
     225             : }
     226             : 
     227             : /* ----------------------------------------------------------------------- */
     228             : 
     229      351591 : sal_Int32 SAL_CALL IMPL_RTL_STRNAME( shortenedCompareIgnoreAsciiCase_WithLength )( const IMPL_RTL_STRCODE* pStr1,
     230             :                                                                                    sal_Int32 nStr1Len,
     231             :                                                                                    const IMPL_RTL_STRCODE* pStr2,
     232             :                                                                                    sal_Int32 nStr2Len,
     233             :                                                                                    sal_Int32 nShortenedLength )
     234             :     SAL_THROW_EXTERN_C()
     235             : {
     236      351591 :     const IMPL_RTL_STRCODE* pStr1End = pStr1 + nStr1Len;
     237      351591 :     const IMPL_RTL_STRCODE* pStr2End = pStr2 + nStr2Len;
     238             :     sal_Int32               nRet;
     239             :     sal_Int32               c1;
     240             :     sal_Int32               c2;
     241      766040 :     while ( (nShortenedLength > 0) &&
     242             :             (pStr1 < pStr1End) && (pStr2 < pStr2End) )
     243             :     {
     244             :         /* If character between 'A' and 'Z', than convert it to lowercase */
     245      369937 :         c1 = (sal_Int32)IMPL_RTL_USTRCODE( *pStr1 );
     246      369937 :         c2 = (sal_Int32)IMPL_RTL_USTRCODE( *pStr2 );
     247      369937 :         if ( (c1 >= 65) && (c1 <= 90) )
     248        1190 :             c1 += 32;
     249      369937 :         if ( (c2 >= 65) && (c2 <= 90) )
     250          18 :             c2 += 32;
     251      369937 :         nRet = c1-c2;
     252      369937 :         if ( nRet != 0 )
     253      307079 :             return nRet;
     254             : 
     255       62858 :         nShortenedLength--;
     256       62858 :         pStr1++;
     257       62858 :         pStr2++;
     258             :     }
     259             : 
     260       44512 :     if ( nShortenedLength <= 0 )
     261        6358 :         return 0;
     262       38154 :     return nStr1Len - nStr2Len;
     263             : }
     264             : 
     265             : /* ----------------------------------------------------------------------- */
     266             : 
     267     1542378 : sal_Int32 SAL_CALL IMPL_RTL_STRNAME( hashCode )( const IMPL_RTL_STRCODE* pStr )
     268             :     SAL_THROW_EXTERN_C()
     269             : {
     270     1542378 :     return IMPL_RTL_STRNAME( hashCode_WithLength )( pStr, IMPL_RTL_STRNAME( getLength )( pStr ) );
     271             : }
     272             : 
     273             : /* ----------------------------------------------------------------------- */
     274             : 
     275     7296307 : sal_Int32 SAL_CALL IMPL_RTL_STRNAME( hashCode_WithLength )( const IMPL_RTL_STRCODE* pStr,
     276             :                                                             sal_Int32 nLen )
     277             :     SAL_THROW_EXTERN_C()
     278             : {
     279     7296307 :     sal_Int32 h = nLen;
     280             : 
     281     7296307 :     if ( nLen < 256 )
     282             :     {
     283   178896949 :         while ( nLen > 0 )
     284             :         {
     285   164306571 :             h = (h*37) + IMPL_RTL_USTRCODE( *pStr );
     286   164306571 :             pStr++;
     287   164306571 :             nLen--;
     288             :         }
     289             :     }
     290             :     else
     291             :     {
     292             :         sal_Int32               nSkip;
     293        1118 :         const IMPL_RTL_STRCODE* pEndStr = pStr+nLen-5;
     294             : 
     295             :         /* only sample some characters */
     296             :         /* the first 3, some characters between, and the last 5 */
     297        1118 :         h = (h*39) + IMPL_RTL_USTRCODE( *pStr );
     298        1118 :         pStr++;
     299        1118 :         h = (h*39) + IMPL_RTL_USTRCODE( *pStr );
     300        1118 :         pStr++;
     301        1118 :         h = (h*39) + IMPL_RTL_USTRCODE( *pStr );
     302        1118 :         pStr++;
     303             : 
     304        1118 :         if ( nLen < 32 )
     305           0 :             nSkip = nLen / 4;
     306             :         else
     307        1118 :             nSkip = nLen / 8;
     308        1118 :         nLen -= 8;
     309       11180 :         while ( nLen > 0 )
     310             :         {
     311        8944 :             h = (h*39) + IMPL_RTL_USTRCODE( *pStr );
     312        8944 :             pStr += nSkip;
     313        8944 :             nLen -= nSkip;
     314             :         }
     315             : 
     316        1118 :         h = (h*39) + IMPL_RTL_USTRCODE( *pEndStr );
     317        1118 :         pEndStr++;
     318        1118 :         h = (h*39) + IMPL_RTL_USTRCODE( *pEndStr );
     319        1118 :         pEndStr++;
     320        1118 :         h = (h*39) + IMPL_RTL_USTRCODE( *pEndStr );
     321        1118 :         pEndStr++;
     322        1118 :         h = (h*39) + IMPL_RTL_USTRCODE( *pEndStr );
     323        1118 :         pEndStr++;
     324        1118 :         h = (h*39) + IMPL_RTL_USTRCODE( *pEndStr );
     325             :     }
     326             : 
     327     7296307 :     return h;
     328             : }
     329             : 
     330             : /* ----------------------------------------------------------------------- */
     331             : 
     332        2316 : sal_Int32 SAL_CALL IMPL_RTL_STRNAME( indexOfChar )( const IMPL_RTL_STRCODE* pStr,
     333             :                                                     IMPL_RTL_STRCODE c )
     334             :     SAL_THROW_EXTERN_C()
     335             : {
     336        2316 :     const IMPL_RTL_STRCODE* pTempStr = pStr;
     337       37700 :     while ( *pTempStr )
     338             :     {
     339       35384 :         if ( *pTempStr == c )
     340        2316 :             return pTempStr-pStr;
     341             : 
     342       33068 :         pTempStr++;
     343             :     }
     344             : 
     345           0 :     return -1;
     346             : }
     347             : 
     348             : /* ----------------------------------------------------------------------- */
     349             : 
     350    18896950 : sal_Int32 SAL_CALL IMPL_RTL_STRNAME( indexOfChar_WithLength )( const IMPL_RTL_STRCODE* pStr,
     351             :                                                                sal_Int32 nLen,
     352             :                                                                IMPL_RTL_STRCODE c )
     353             :     SAL_THROW_EXTERN_C()
     354             : {
     355    18896950 :     const IMPL_RTL_STRCODE* pTempStr = pStr;
     356   246189251 :     while ( nLen > 0 )
     357             :     {
     358   226795022 :         if ( *pTempStr == c )
     359    18399671 :             return pTempStr-pStr;
     360             : 
     361   208395351 :         pTempStr++;
     362   208395351 :         nLen--;
     363             :     }
     364             : 
     365      497279 :     return -1;
     366             : }
     367             : 
     368             : /* ----------------------------------------------------------------------- */
     369             : 
     370          24 : sal_Int32 SAL_CALL IMPL_RTL_STRNAME( lastIndexOfChar )( const IMPL_RTL_STRCODE* pStr,
     371             :                                                         IMPL_RTL_STRCODE c )
     372             :     SAL_THROW_EXTERN_C()
     373             : {
     374          24 :     return IMPL_RTL_STRNAME( lastIndexOfChar_WithLength )( pStr, IMPL_RTL_STRNAME( getLength )( pStr ), c );
     375             : }
     376             : 
     377             : /* ----------------------------------------------------------------------- */
     378             : 
     379      436492 : sal_Int32 SAL_CALL IMPL_RTL_STRNAME( lastIndexOfChar_WithLength )( const IMPL_RTL_STRCODE* pStr,
     380             :                                                                    sal_Int32 nLen,
     381             :                                                                    IMPL_RTL_STRCODE c )
     382             :     SAL_THROW_EXTERN_C()
     383             : {
     384      436492 :     pStr += nLen;
     385     6207059 :     while ( nLen > 0 )
     386             :     {
     387     5743404 :         nLen--;
     388     5743404 :         pStr--;
     389             : 
     390     5743404 :         if ( *pStr == c )
     391      409329 :             return nLen;
     392             :     }
     393             : 
     394       27163 :     return -1;
     395             : }
     396             : 
     397             : /* ----------------------------------------------------------------------- */
     398             : 
     399          98 : sal_Int32 SAL_CALL IMPL_RTL_STRNAME( indexOfStr )( const IMPL_RTL_STRCODE* pStr,
     400             :                                                    const IMPL_RTL_STRCODE* pSubStr )
     401             :     SAL_THROW_EXTERN_C()
     402             : {
     403             :     return IMPL_RTL_STRNAME( indexOfStr_WithLength )( pStr, IMPL_RTL_STRNAME( getLength )( pStr ),
     404          98 :                                                       pSubStr, IMPL_RTL_STRNAME( getLength )( pSubStr ) );
     405             : }
     406             : 
     407             : /* ----------------------------------------------------------------------- */
     408             : 
     409     5455897 : sal_Int32 SAL_CALL IMPL_RTL_STRNAME( indexOfStr_WithLength )( const IMPL_RTL_STRCODE* pStr,
     410             :                                                               sal_Int32 nStrLen,
     411             :                                                               const  IMPL_RTL_STRCODE* pSubStr,
     412             :                                                               sal_Int32 nSubLen )
     413             :     SAL_THROW_EXTERN_C()
     414             : {
     415             :     /* faster search for a single character */
     416     5455897 :     if ( nSubLen < 2 )
     417             :     {
     418             :         /* an empty SubString is always not foundable */
     419      882190 :         if ( nSubLen == 1 )
     420             :         {
     421      882182 :             IMPL_RTL_STRCODE        c = *pSubStr;
     422      882182 :             const IMPL_RTL_STRCODE* pTempStr = pStr;
     423     9028802 :             while ( nStrLen > 0 )
     424             :             {
     425     7641383 :                 if ( *pTempStr == c )
     426      376945 :                     return pTempStr-pStr;
     427             : 
     428     7264438 :                 pTempStr++;
     429     7264438 :                 nStrLen--;
     430             :             }
     431             :         }
     432             :     }
     433             :     else
     434             :     {
     435     4573707 :         const IMPL_RTL_STRCODE* pTempStr = pStr;
     436   103650324 :         while ( nStrLen > 0 )
     437             :         {
     438    95937832 :             if ( *pTempStr == *pSubStr )
     439             :             {
     440             :                 /* Compare SubString */
     441     3452071 :                 if ( nSubLen <= nStrLen )
     442             :                 {
     443     3273685 :                     const IMPL_RTL_STRCODE* pTempStr1 = pTempStr;
     444     3273685 :                     const IMPL_RTL_STRCODE* pTempStr2 = pSubStr;
     445     3273685 :                     sal_Int32               nTempLen = nSubLen;
     446    13605277 :                     while ( nTempLen )
     447             :                     {
     448     9075056 :                         if ( *pTempStr1 != *pTempStr2 )
     449     2017149 :                             break;
     450             : 
     451     7057907 :                         pTempStr1++;
     452     7057907 :                         pTempStr2++;
     453     7057907 :                         nTempLen--;
     454             :                     }
     455             : 
     456     3273685 :                     if ( !nTempLen )
     457     1256536 :                         return pTempStr-pStr;
     458             :                 }
     459             :                 else
     460      178386 :                     break;
     461             :             }
     462             : 
     463    94502910 :             nStrLen--;
     464    94502910 :             pTempStr++;
     465             :         }
     466             :     }
     467             : 
     468     3822416 :     return -1;
     469             : }
     470             : 
     471             : /* ----------------------------------------------------------------------- */
     472             : 
     473           0 : sal_Int32 SAL_CALL IMPL_RTL_STRNAME( lastIndexOfStr )( const IMPL_RTL_STRCODE* pStr,
     474             :                                                        const IMPL_RTL_STRCODE* pSubStr )
     475             :     SAL_THROW_EXTERN_C()
     476             : {
     477             :     return IMPL_RTL_STRNAME( lastIndexOfStr_WithLength )( pStr, IMPL_RTL_STRNAME( getLength )( pStr ),
     478           0 :                                                           pSubStr, IMPL_RTL_STRNAME( getLength )( pSubStr ) );
     479             : }
     480             : 
     481             : /* ----------------------------------------------------------------------- */
     482             : 
     483       64786 : sal_Int32 SAL_CALL IMPL_RTL_STRNAME( lastIndexOfStr_WithLength )( const IMPL_RTL_STRCODE* pStr,
     484             :                                                                   sal_Int32 nStrLen,
     485             :                                                                   const IMPL_RTL_STRCODE* pSubStr,
     486             :                                                                   sal_Int32 nSubLen )
     487             :     SAL_THROW_EXTERN_C()
     488             : {
     489             :     /* faster search for a single character */
     490       64786 :     if ( nSubLen < 2 )
     491             :     {
     492             :         /* an empty SubString is always not foundable */
     493         602 :         if ( nSubLen == 1 )
     494             :         {
     495         602 :             IMPL_RTL_STRCODE c = *pSubStr;
     496         602 :             pStr += nStrLen;
     497        5018 :             while ( nStrLen > 0 )
     498             :             {
     499        4406 :                 nStrLen--;
     500        4406 :                 pStr--;
     501             : 
     502        4406 :                 if ( *pStr == c )
     503         592 :                     return nStrLen;
     504             :             }
     505             :         }
     506             :     }
     507             :     else
     508             :     {
     509       64184 :         pStr += nStrLen;
     510       64184 :         nStrLen -= nSubLen;
     511       64184 :         pStr -= nSubLen;
     512     2133904 :         while ( nStrLen >= 0 )
     513             :         {
     514     2034323 :             const IMPL_RTL_STRCODE* pTempStr1 = pStr;
     515     2034323 :             const IMPL_RTL_STRCODE* pTempStr2 = pSubStr;
     516     2034323 :             sal_Int32               nTempLen = nSubLen;
     517     4178075 :             while ( nTempLen )
     518             :             {
     519     2114965 :                 if ( *pTempStr1 != *pTempStr2 )
     520     2005536 :                     break;
     521             : 
     522      109429 :                 pTempStr1++;
     523      109429 :                 pTempStr2++;
     524      109429 :                 nTempLen--;
     525             :             }
     526             : 
     527     2034323 :             if ( !nTempLen )
     528       28787 :                 return nStrLen;
     529             : 
     530     2005536 :             nStrLen--;
     531     2005536 :             pStr--;
     532             :         }
     533             :     }
     534             : 
     535       35407 :     return -1;
     536             : }
     537             : 
     538             : /* ----------------------------------------------------------------------- */
     539             : 
     540           0 : void SAL_CALL IMPL_RTL_STRNAME( replaceChar )( IMPL_RTL_STRCODE* pStr,
     541             :                                                IMPL_RTL_STRCODE cOld,
     542             :                                                IMPL_RTL_STRCODE cNew )
     543             :     SAL_THROW_EXTERN_C()
     544             : {
     545           0 :     while ( *pStr )
     546             :     {
     547           0 :         if ( *pStr == cOld )
     548           0 :             *pStr = cNew;
     549             : 
     550           0 :         pStr++;
     551             :     }
     552           0 : }
     553             : 
     554             : /* ----------------------------------------------------------------------- */
     555             : 
     556           0 : void SAL_CALL IMPL_RTL_STRNAME( replaceChar_WithLength )( IMPL_RTL_STRCODE* pStr,
     557             :                                                           sal_Int32 nLen,
     558             :                                                           IMPL_RTL_STRCODE cOld,
     559             :                                                           IMPL_RTL_STRCODE cNew )
     560             :     SAL_THROW_EXTERN_C()
     561             : {
     562           0 :     while ( nLen > 0 )
     563             :     {
     564           0 :         if ( *pStr == cOld )
     565           0 :             *pStr = cNew;
     566             : 
     567           0 :         pStr++;
     568           0 :         nLen--;
     569             :     }
     570           0 : }
     571             : 
     572             : /* ----------------------------------------------------------------------- */
     573             : 
     574           0 : void SAL_CALL IMPL_RTL_STRNAME( toAsciiLowerCase )( IMPL_RTL_STRCODE* pStr )
     575             :     SAL_THROW_EXTERN_C()
     576             : {
     577           0 :     while ( *pStr )
     578             :     {
     579             :         /* Between A-Z (65-90), than to lowercase (+32) */
     580           0 :         if ( (*pStr >= 65) && (*pStr <= 90) )
     581           0 :             *pStr += 32;
     582             : 
     583           0 :         pStr++;
     584             :     }
     585           0 : }
     586             : 
     587             : /* ----------------------------------------------------------------------- */
     588             : 
     589     1518419 : void SAL_CALL IMPL_RTL_STRNAME( toAsciiLowerCase_WithLength )( IMPL_RTL_STRCODE* pStr,
     590             :                                                                sal_Int32 nLen )
     591             :     SAL_THROW_EXTERN_C()
     592             : {
     593    15906699 :     while ( nLen > 0 )
     594             :     {
     595             :         /* Between A-Z (65-90), than to lowercase (+32) */
     596    12869861 :         if ( (*pStr >= 65) && (*pStr <= 90) )
     597        7658 :             *pStr += 32;
     598             : 
     599    12869861 :         pStr++;
     600    12869861 :         nLen--;
     601             :     }
     602     1518419 : }
     603             : 
     604             : /* ----------------------------------------------------------------------- */
     605             : 
     606           0 : void SAL_CALL IMPL_RTL_STRNAME( toAsciiUpperCase )( IMPL_RTL_STRCODE* pStr )
     607             :     SAL_THROW_EXTERN_C()
     608             : {
     609           0 :     while ( *pStr )
     610             :     {
     611             :         /* Between a-z (97-122), than to uppercase (-32) */
     612           0 :         if ( (*pStr >= 97) && (*pStr <= 122) )
     613           0 :             *pStr -= 32;
     614             : 
     615           0 :         pStr++;
     616             :     }
     617           0 : }
     618             : 
     619             : /* ----------------------------------------------------------------------- */
     620             : 
     621           0 : void SAL_CALL IMPL_RTL_STRNAME( toAsciiUpperCase_WithLength )( IMPL_RTL_STRCODE* pStr,
     622             :                                                                sal_Int32 nLen )
     623             :     SAL_THROW_EXTERN_C()
     624             : {
     625           0 :     while ( nLen > 0 )
     626             :     {
     627             :         /* Between a-z (97-122), than to uppercase (-32) */
     628           0 :         if ( (*pStr >= 97) && (*pStr <= 122) )
     629           0 :             *pStr -= 32;
     630             : 
     631           0 :         pStr++;
     632           0 :         nLen--;
     633             :     }
     634           0 : }
     635             : 
     636             : /* ----------------------------------------------------------------------- */
     637             : 
     638           0 : sal_Int32 SAL_CALL IMPL_RTL_STRNAME( trim )( IMPL_RTL_STRCODE* pStr )
     639             :     SAL_THROW_EXTERN_C()
     640             : {
     641           0 :     return IMPL_RTL_STRNAME( trim_WithLength )( pStr, IMPL_RTL_STRNAME( getLength )( pStr ) );
     642             : }
     643             : 
     644             : /* ----------------------------------------------------------------------- */
     645             : 
     646           0 : sal_Int32 SAL_CALL IMPL_RTL_STRNAME( trim_WithLength )( IMPL_RTL_STRCODE* pStr, sal_Int32 nLen )
     647             :     SAL_THROW_EXTERN_C()
     648             : {
     649           0 :     sal_Int32 nPreSpaces    = 0;
     650           0 :     sal_Int32 nPostSpaces   = 0;
     651           0 :     sal_Int32 nIndex        = nLen-1;
     652             : 
     653           0 :     while ( (nPreSpaces < nLen) && rtl_ImplIsWhitespace( IMPL_RTL_USTRCODE(*(pStr+nPreSpaces)) ) )
     654           0 :         nPreSpaces++;
     655             : 
     656           0 :     while ( (nIndex > nPreSpaces) && rtl_ImplIsWhitespace( IMPL_RTL_USTRCODE(*(pStr+nIndex)) ) )
     657             :     {
     658           0 :         nPostSpaces++;
     659           0 :         nIndex--;
     660             :     }
     661             : 
     662           0 :     if ( nPostSpaces )
     663             :     {
     664           0 :         nLen -= nPostSpaces;
     665           0 :         *(pStr+nLen) = 0;
     666             :     }
     667             : 
     668           0 :     if ( nPreSpaces )
     669             :     {
     670           0 :         IMPL_RTL_STRCODE* pNewStr = pStr+nPreSpaces;
     671             : 
     672           0 :         nLen -= nPreSpaces;
     673           0 :         nIndex = nLen;
     674             : 
     675           0 :         while ( nIndex )
     676             :         {
     677           0 :             *pStr = *pNewStr;
     678           0 :             pStr++;
     679           0 :             pNewStr++;
     680           0 :             nIndex--;
     681             :         }
     682           0 :         *pStr = 0;
     683             :     }
     684             : 
     685           0 :     return nLen;
     686             : }
     687             : 
     688             : /* ----------------------------------------------------------------------- */
     689             : 
     690          38 : sal_Int32 SAL_CALL IMPL_RTL_STRNAME( valueOfBoolean )( IMPL_RTL_STRCODE* pStr, sal_Bool b )
     691             :     SAL_THROW_EXTERN_C()
     692             : {
     693          38 :     if ( b )
     694             :     {
     695          22 :         *pStr = 't';
     696          22 :         pStr++;
     697          22 :         *pStr = 'r';
     698          22 :         pStr++;
     699          22 :         *pStr = 'u';
     700          22 :         pStr++;
     701          22 :         *pStr = 'e';
     702          22 :         pStr++;
     703          22 :         *pStr = 0;
     704          22 :         return 4;
     705             :     }
     706             :     else
     707             :     {
     708          16 :         *pStr = 'f';
     709          16 :         pStr++;
     710          16 :         *pStr = 'a';
     711          16 :         pStr++;
     712          16 :         *pStr = 'l';
     713          16 :         pStr++;
     714          16 :         *pStr = 's';
     715          16 :         pStr++;
     716          16 :         *pStr = 'e';
     717          16 :         pStr++;
     718          16 :         *pStr = 0;
     719          16 :         return 5;
     720             :     }
     721             : }
     722             : 
     723             : /* ----------------------------------------------------------------------- */
     724             : 
     725           0 : sal_Int32 SAL_CALL IMPL_RTL_STRNAME( valueOfChar )( IMPL_RTL_STRCODE* pStr,
     726             :                                                     IMPL_RTL_STRCODE c )
     727             :     SAL_THROW_EXTERN_C()
     728             : {
     729           0 :     *pStr++ = c;
     730           0 :     *pStr = 0;
     731           0 :     return 1;
     732             : }
     733             : 
     734             : /* ----------------------------------------------------------------------- */
     735             : 
     736     1322118 : sal_Int32 SAL_CALL IMPL_RTL_STRNAME( valueOfInt32 )( IMPL_RTL_STRCODE* pStr,
     737             :                                                      sal_Int32 n,
     738             :                                                      sal_Int16 nRadix )
     739             :     SAL_THROW_EXTERN_C()
     740             : {
     741             :     sal_Char    aBuf[RTL_STR_MAX_VALUEOFINT32];
     742     1322118 :     sal_Char*   pBuf = aBuf;
     743     1322118 :     sal_Int32   nLen = 0;
     744             :     sal_uInt32  nValue;
     745             : 
     746             :     /* Radix must be valid */
     747     1322118 :     if ( (nRadix < RTL_STR_MIN_RADIX) || (nRadix > RTL_STR_MAX_RADIX) )
     748          10 :         nRadix = 10;
     749             : 
     750             :     /* is value negativ */
     751     1322118 :     if ( n < 0 )
     752             :     {
     753         580 :         *pStr = '-';
     754         580 :         pStr++;
     755         580 :         nLen++;
     756         580 :         nValue = -n; /* FIXME this code is not portable for n == -2147483648
     757             :                         (smallest negative value for sal_Int32) */
     758             :     }
     759             :     else
     760     1321538 :         nValue = n;
     761             : 
     762             :     /* create a recursive buffer with all values, except the last one */
     763     2186670 :     do
     764             :     {
     765     2186670 :         sal_Char nDigit = (sal_Char)(nValue % nRadix);
     766     2186670 :         nValue /= nRadix;
     767     2186670 :         if ( nDigit > 9 )
     768      360381 :             *pBuf = (nDigit-10) + 'a';
     769             :         else
     770     1826289 :             *pBuf = (nDigit + '0' );
     771     2186670 :         pBuf++;
     772             :     }
     773             :     while ( nValue > 0 );
     774             : 
     775             :     /* copy the values in the right direction into the destination buffer */
     776     2186670 :     do
     777             :     {
     778     2186670 :         pBuf--;
     779     2186670 :         *pStr = *pBuf;
     780     2186670 :         pStr++;
     781     2186670 :         nLen++;
     782             :     }
     783             :     while ( pBuf != aBuf );
     784     1322118 :     *pStr = 0;
     785             : 
     786     1322118 :     return nLen;
     787             : }
     788             : 
     789             : /* ----------------------------------------------------------------------- */
     790             : 
     791       36955 : sal_Int32 SAL_CALL IMPL_RTL_STRNAME( valueOfInt64 )( IMPL_RTL_STRCODE* pStr,
     792             :                                                      sal_Int64 n,
     793             :                                                      sal_Int16 nRadix )
     794             :     SAL_THROW_EXTERN_C()
     795             : {
     796             :     sal_Char    aBuf[RTL_STR_MAX_VALUEOFINT64];
     797       36955 :     sal_Char*   pBuf = aBuf;
     798       36955 :     sal_Int32   nLen = 0;
     799             :     sal_uInt64  nValue;
     800             : 
     801             :     /* Radix must be valid */
     802       36955 :     if ( (nRadix < RTL_STR_MIN_RADIX) || (nRadix > RTL_STR_MAX_RADIX) )
     803          10 :         nRadix = 10;
     804             : 
     805             :     /* is value negativ */
     806       36955 :     if ( n < 0 )
     807             :     {
     808        6904 :         *pStr = '-';
     809        6904 :         pStr++;
     810        6904 :         nLen++;
     811        6904 :         nValue = -n; /* FIXME this code is not portable for
     812             :                         n == -9223372036854775808 (smallest negative value for
     813             :                         sal_Int64) */
     814             :     }
     815             :     else
     816       30051 :         nValue = n;
     817             : 
     818             :     /* create a recursive buffer with all values, except the last one */
     819      199789 :     do
     820             :     {
     821      199789 :         sal_Char nDigit = (sal_Char)(nValue % nRadix);
     822      199789 :         nValue /= nRadix;
     823      199789 :         if ( nDigit > 9 )
     824       49049 :             *pBuf = (nDigit-10) + 'a';
     825             :         else
     826      150740 :             *pBuf = (nDigit + '0' );
     827      199789 :         pBuf++;
     828             :     }
     829             :     while ( nValue > 0 );
     830             : 
     831             :     /* copy the values in the right direction into the destination buffer */
     832      199789 :     do
     833             :     {
     834      199789 :         pBuf--;
     835      199789 :         *pStr = *pBuf;
     836      199789 :         pStr++;
     837      199789 :         nLen++;
     838             :     }
     839             :     while ( pBuf != aBuf );
     840       36955 :     *pStr = 0;
     841             : 
     842       36955 :     return nLen;
     843             : }
     844             : 
     845             : /* ----------------------------------------------------------------------- */
     846             : 
     847         424 : sal_Bool SAL_CALL IMPL_RTL_STRNAME( toBoolean )( const IMPL_RTL_STRCODE* pStr )
     848             :     SAL_THROW_EXTERN_C()
     849             : {
     850         424 :     if ( *pStr == '1' )
     851           0 :         return sal_True;
     852             : 
     853         424 :     if ( (*pStr == 'T') || (*pStr == 't') )
     854             :     {
     855           0 :         pStr++;
     856           0 :         if ( (*pStr == 'R') || (*pStr == 'r') )
     857             :         {
     858           0 :             pStr++;
     859           0 :             if ( (*pStr == 'U') || (*pStr == 'u') )
     860             :             {
     861           0 :                 pStr++;
     862           0 :                 if ( (*pStr == 'E') || (*pStr == 'e') )
     863           0 :                     return sal_True;
     864             :             }
     865             :         }
     866             :     }
     867             : 
     868         424 :     return sal_False;
     869             : }
     870             : 
     871             : /* ----------------------------------------------------------------------- */
     872             : 
     873     1557568 : sal_Int32 SAL_CALL IMPL_RTL_STRNAME( toInt32 )( const IMPL_RTL_STRCODE* pStr,
     874             :                                                 sal_Int16 nRadix )
     875             :     SAL_THROW_EXTERN_C()
     876             : {
     877             :     sal_Bool    bNeg;
     878             :     sal_Int16   nDigit;
     879     1557568 :     sal_Int32   n = 0;
     880             : 
     881     1557568 :     if ( (nRadix < RTL_STR_MIN_RADIX) || (nRadix > RTL_STR_MAX_RADIX) )
     882           0 :         nRadix = 10;
     883             : 
     884             :     /* Skip whitespaces */
     885     3115148 :     while ( *pStr && rtl_ImplIsWhitespace( IMPL_RTL_USTRCODE( *pStr ) ) )
     886          12 :         pStr++;
     887             : 
     888     1557568 :     if ( *pStr == '-' )
     889             :     {
     890       11492 :         bNeg = sal_True;
     891       11492 :         pStr++;
     892             :     }
     893             :     else
     894             :     {
     895     1546076 :         if ( *pStr == '+' )
     896           0 :             pStr++;
     897     1546076 :         bNeg = sal_False;
     898             :     }
     899             : 
     900     6721021 :     while ( *pStr )
     901             :     {
     902     3635036 :         nDigit = rtl_ImplGetDigit( IMPL_RTL_USTRCODE( *pStr ), nRadix );
     903     3635036 :         if ( nDigit < 0 )
     904       29151 :             break;
     905             : 
     906     3605885 :         n *= nRadix;
     907     3605885 :         n += nDigit;
     908             : 
     909     3605885 :         pStr++;
     910             :     }
     911             : 
     912     1557568 :     if ( bNeg )
     913       11492 :         return -n;
     914             :     else
     915     1546076 :         return n;
     916             : }
     917             : 
     918             : /* ----------------------------------------------------------------------- */
     919             : 
     920        6680 : sal_Int64 SAL_CALL IMPL_RTL_STRNAME( toInt64 )( const IMPL_RTL_STRCODE* pStr,
     921             :                                                 sal_Int16 nRadix )
     922             :     SAL_THROW_EXTERN_C()
     923             : {
     924             :     sal_Bool    bNeg;
     925             :     sal_Int16   nDigit;
     926        6680 :     sal_Int64   n = 0;
     927             : 
     928        6680 :     if ( (nRadix < RTL_STR_MIN_RADIX) || (nRadix > RTL_STR_MAX_RADIX) )
     929           0 :         nRadix = 10;
     930             : 
     931             :     /* Skip whitespaces */
     932       13360 :     while ( *pStr && rtl_ImplIsWhitespace( IMPL_RTL_USTRCODE( *pStr ) ) )
     933           0 :         pStr++;
     934             : 
     935        6680 :     if ( *pStr == '-' )
     936             :     {
     937         168 :         bNeg = sal_True;
     938         168 :         pStr++;
     939             :     }
     940             :     else
     941             :     {
     942        6512 :         if ( *pStr == '+' )
     943           0 :             pStr++;
     944        6512 :         bNeg = sal_False;
     945             :     }
     946             : 
     947       51734 :     while ( *pStr )
     948             :     {
     949       38374 :         nDigit = rtl_ImplGetDigit( IMPL_RTL_USTRCODE( *pStr ), nRadix );
     950       38374 :         if ( nDigit < 0 )
     951           0 :             break;
     952             : 
     953       38374 :         n *= nRadix;
     954       38374 :         n += nDigit;
     955             : 
     956       38374 :         pStr++;
     957             :     }
     958             : 
     959        6680 :     if ( bNeg )
     960         168 :         return -n;
     961             :     else
     962        6512 :         return n;
     963             : }
     964             : 
     965             : /* ======================================================================= */
     966             : /* Internal String-Class help functions                                    */
     967             : /* ======================================================================= */
     968             : 
     969    41009106 : static IMPL_RTL_STRINGDATA* IMPL_RTL_STRINGNAME( ImplAlloc )( sal_Int32 nLen )
     970             : {
     971             :     IMPL_RTL_STRINGDATA * pData
     972    41009106 :         = (sal::static_int_cast< sal_uInt32 >(nLen)
     973             :            <= ((SAL_MAX_UINT32 - sizeof (IMPL_RTL_STRINGDATA))
     974             :                / sizeof (IMPL_RTL_STRCODE)))
     975             :         ? (IMPL_RTL_STRINGDATA *) rtl_allocateMemory(
     976    41009107 :             sizeof (IMPL_RTL_STRINGDATA) + nLen * sizeof (IMPL_RTL_STRCODE))
     977    82018214 :         : NULL;
     978    41009108 :     if (pData != NULL) {
     979    41009108 :         pData->refCount = 1;
     980    41009108 :         pData->length = nLen;
     981    41009108 :         pData->buffer[nLen] = 0;
     982             :     }
     983    41009108 :     return pData;
     984             : }
     985             : 
     986             : /* ----------------------------------------------------------------------- */
     987             : 
     988      169971 : static IMPL_RTL_STRCODE* IMPL_RTL_STRINGNAME( ImplNewCopy )( IMPL_RTL_STRINGDATA** ppThis,
     989             :                                                              IMPL_RTL_STRINGDATA* pStr,
     990             :                                                              sal_Int32 nCount )
     991             : {
     992             :     IMPL_RTL_STRCODE*       pDest;
     993             :     const IMPL_RTL_STRCODE* pSrc;
     994      169971 :     IMPL_RTL_STRINGDATA*    pData = IMPL_RTL_STRINGNAME( ImplAlloc )( pStr->length );
     995             :     OSL_ASSERT(pData != NULL);
     996             : 
     997      169971 :     pDest   = pData->buffer;
     998      169971 :     pSrc    = pStr->buffer;
     999      845242 :     while ( nCount > 0 )
    1000             :     {
    1001      505300 :         *pDest = *pSrc;
    1002      505300 :         pDest++;
    1003      505300 :         pSrc++;
    1004      505300 :         nCount--;
    1005             :     }
    1006             : 
    1007      169971 :     *ppThis = pData;
    1008             : 
    1009             :     RTL_LOG_STRING_NEW( pData );
    1010      169971 :     return pDest;
    1011             : }
    1012             : 
    1013             : /* ======================================================================= */
    1014             : /* String-Class functions                                                  */
    1015             : /* ======================================================================= */
    1016             : 
    1017             : #define IMPL_RTL_AQUIRE( pThis )                                \
    1018             : {                                                               \
    1019             :     if (!SAL_STRING_IS_STATIC (pThis))                          \
    1020             :         osl_atomic_increment( &((pThis)->refCount) );  \
    1021             : }
    1022             : 
    1023             : /* ----------------------------------------------------------------------- */
    1024             : 
    1025    79113430 : void SAL_CALL IMPL_RTL_STRINGNAME( acquire )( IMPL_RTL_STRINGDATA* pThis )
    1026             :     SAL_THROW_EXTERN_C()
    1027             : {
    1028    79113430 :     IMPL_RTL_AQUIRE( pThis );
    1029    79113430 : }
    1030             : 
    1031             : /* ----------------------------------------------------------------------- */
    1032             : 
    1033   207163499 : void SAL_CALL IMPL_RTL_STRINGNAME( release )( IMPL_RTL_STRINGDATA* pThis )
    1034             :     SAL_THROW_EXTERN_C()
    1035             : {
    1036   207163499 :     if (SAL_STRING_IS_STATIC (pThis))
    1037    95558709 :         return;
    1038             : 
    1039             : /* OString doesn't have an 'intern' */
    1040             : #ifdef IMPL_RTL_INTERN
    1041   121107489 :     if (SAL_STRING_IS_INTERN (pThis))
    1042             :     {
    1043      286807 :         internRelease (pThis);
    1044      286807 :         return;
    1045             :     }
    1046             : #endif
    1047             : 
    1048   223242567 :     if ( pThis->refCount == 1 ||
    1049    91076319 :          !osl_atomic_decrement( &(pThis->refCount) ) )
    1050             :     {
    1051             :         RTL_LOG_STRING_DELETE( pThis );
    1052    41089891 :         rtl_freeMemory( pThis );
    1053             :     }
    1054             : }
    1055             : 
    1056             : /* ----------------------------------------------------------------------- */
    1057             : 
    1058    51690544 : void SAL_CALL IMPL_RTL_STRINGNAME( new )( IMPL_RTL_STRINGDATA** ppThis )
    1059             :     SAL_THROW_EXTERN_C()
    1060             : {
    1061    51690544 :     if ( *ppThis)
    1062     1238330 :         IMPL_RTL_STRINGNAME( release )( *ppThis );
    1063             : 
    1064    51690544 :     *ppThis = (IMPL_RTL_STRINGDATA*) (&IMPL_RTL_EMPTYSTRING);
    1065    51690544 : }
    1066             : 
    1067             : /* ----------------------------------------------------------------------- */
    1068             : 
    1069     1027934 : IMPL_RTL_STRINGDATA* SAL_CALL IMPL_RTL_STRINGNAME( alloc )( sal_Int32 nLen )
    1070             :     SAL_THROW_EXTERN_C()
    1071             : {
    1072     1027934 :     if ( nLen <= 0 )
    1073          36 :         return (IMPL_RTL_STRINGDATA*) (&IMPL_RTL_EMPTYSTRING);
    1074             :     else
    1075     1027898 :         return IMPL_RTL_STRINGNAME( ImplAlloc )( nLen );
    1076             : }
    1077             : 
    1078             : /* ----------------------------------------------------------------------- */
    1079             : 
    1080     4431800 : void SAL_CALL IMPL_RTL_STRINGNAME( new_WithLength )( IMPL_RTL_STRINGDATA** ppThis, sal_Int32 nLen )
    1081             :     SAL_THROW_EXTERN_C()
    1082             : {
    1083     4431800 :     if ( nLen <= 0 )
    1084        2578 :         IMPL_RTL_STRINGNAME( new )( ppThis );
    1085             :     else
    1086             :     {
    1087     4429222 :         if ( *ppThis)
    1088      302883 :             IMPL_RTL_STRINGNAME( release )( *ppThis );
    1089             : 
    1090     4429222 :         *ppThis = IMPL_RTL_STRINGNAME( ImplAlloc )( nLen );
    1091             :         OSL_ASSERT(*ppThis != NULL);
    1092     4429222 :         (*ppThis)->length   = 0;
    1093             : 
    1094     4429222 :         IMPL_RTL_STRCODE* pTempStr = (*ppThis)->buffer;
    1095     4429222 :         memset(pTempStr, 0, nLen*sizeof(IMPL_RTL_STRCODE));
    1096             :     }
    1097     4431800 : }
    1098             : 
    1099             : /* ----------------------------------------------------------------------- */
    1100             : 
    1101       15511 : void SAL_CALL IMPL_RTL_STRINGNAME( newFromString )( IMPL_RTL_STRINGDATA** ppThis,
    1102             :                                                     const IMPL_RTL_STRINGDATA* pStr )
    1103             :     SAL_THROW_EXTERN_C()
    1104             : {
    1105             :     IMPL_RTL_STRINGDATA* pOrg;
    1106             : 
    1107       15511 :     if ( !pStr->length )
    1108             :     {
    1109           0 :         IMPL_RTL_STRINGNAME( new )( ppThis );
    1110       15511 :         return;
    1111             :     }
    1112             : 
    1113       15511 :     pOrg = *ppThis;
    1114       15511 :     *ppThis = IMPL_RTL_STRINGNAME( ImplAlloc )( pStr->length );
    1115             :     OSL_ASSERT(*ppThis != NULL);
    1116       15511 :     rtl_str_ImplCopy( (*ppThis)->buffer, pStr->buffer, pStr->length );
    1117             :     RTL_LOG_STRING_NEW( *ppThis );
    1118             : 
    1119             :     /* must be done last, if pStr == *ppThis */
    1120       15511 :     if ( pOrg )
    1121           0 :         IMPL_RTL_STRINGNAME( release )( pOrg );
    1122             : }
    1123             : 
    1124             : /* ----------------------------------------------------------------------- */
    1125             : 
    1126     5962871 : void SAL_CALL IMPL_RTL_STRINGNAME( newFromStr )( IMPL_RTL_STRINGDATA** ppThis,
    1127             :                                                  const IMPL_RTL_STRCODE* pCharStr )
    1128             :     SAL_THROW_EXTERN_C()
    1129             : {
    1130             :     IMPL_RTL_STRCODE*       pBuffer;
    1131             :     IMPL_RTL_STRINGDATA*    pOrg;
    1132             :     sal_Int32               nLen;
    1133             : 
    1134     5962871 :     if ( pCharStr )
    1135             :     {
    1136     5962871 :         const IMPL_RTL_STRCODE* pTempStr = pCharStr;
    1137    67478833 :         while( *pTempStr )
    1138    55553091 :             pTempStr++;
    1139     5962871 :         nLen = pTempStr-pCharStr;
    1140             :     }
    1141             :     else
    1142           0 :         nLen = 0;
    1143             : 
    1144     5962871 :     if ( !nLen )
    1145             :     {
    1146      958423 :         IMPL_RTL_STRINGNAME( new )( ppThis );
    1147     6921294 :         return;
    1148             :     }
    1149             : 
    1150     5004448 :     pOrg = *ppThis;
    1151     5004448 :     *ppThis = IMPL_RTL_STRINGNAME( ImplAlloc )( nLen );
    1152             :     OSL_ASSERT(*ppThis != NULL);
    1153     5004448 :     pBuffer = (*ppThis)->buffer;
    1154    55553091 :     do
    1155             :     {
    1156    55553091 :         *pBuffer = *pCharStr;
    1157    55553091 :         pBuffer++;
    1158    55553091 :         pCharStr++;
    1159             :     }
    1160             :     while ( *pCharStr );
    1161             : 
    1162             :     RTL_LOG_STRING_NEW( *ppThis );
    1163             : 
    1164             :     /* must be done last, if pCharStr == *ppThis */
    1165     5004448 :     if ( pOrg )
    1166       53527 :         IMPL_RTL_STRINGNAME( release )( pOrg );
    1167             : }
    1168             : 
    1169             : /* ----------------------------------------------------------------------- */
    1170             : 
    1171    10403293 : void SAL_CALL IMPL_RTL_STRINGNAME( newFromStr_WithLength )( IMPL_RTL_STRINGDATA** ppThis,
    1172             :                                                             const IMPL_RTL_STRCODE* pCharStr,
    1173             :                                                             sal_Int32 nLen )
    1174             :     SAL_THROW_EXTERN_C()
    1175             : {
    1176             :     IMPL_RTL_STRINGDATA* pOrg;
    1177             : 
    1178    10403293 :     if ( !pCharStr || (nLen <= 0) )
    1179             :     {
    1180      190734 :         IMPL_RTL_STRINGNAME( new )( ppThis );
    1181    10594027 :         return;
    1182             :     }
    1183             : 
    1184    10212559 :     pOrg = *ppThis;
    1185    10212559 :     *ppThis = IMPL_RTL_STRINGNAME( ImplAlloc )( nLen );
    1186             :     OSL_ASSERT(*ppThis != NULL);
    1187    10212559 :     rtl_str_ImplCopy( (*ppThis)->buffer, pCharStr, nLen );
    1188             : 
    1189             :     RTL_LOG_STRING_NEW( *ppThis );
    1190             : 
    1191             :     /* must be done last, if pCharStr == *ppThis */
    1192    10212559 :     if ( pOrg )
    1193      782381 :         IMPL_RTL_STRINGNAME( release )( pOrg );
    1194             : }
    1195             : 
    1196             : /* ----------------------------------------------------------------------- */
    1197             : 
    1198     1684302 : void SAL_CALL IMPL_RTL_STRINGNAME( newFromSubString )( IMPL_RTL_STRINGDATA** ppThis,
    1199             :                                                        const IMPL_RTL_STRINGDATA* pFrom,
    1200             :                                                        sal_Int32 beginIndex,
    1201             :                                                        sal_Int32 count )
    1202             :     SAL_THROW_EXTERN_C()
    1203             : {
    1204     1684302 :     if ( beginIndex == 0 && count == pFrom->length )
    1205             :     {
    1206      151544 :         IMPL_RTL_STRINGNAME( assign )( ppThis, const_cast< IMPL_RTL_STRINGDATA * >( pFrom ) );
    1207      151544 :         return;
    1208             :     }
    1209     1532758 :     if ( count < 0 || beginIndex < 0 || beginIndex + count > pFrom->length )
    1210             :     {
    1211             :         OSL_FAIL( "Out of bounds substring access" );
    1212           2 :         IMPL_RTL_STRINGNAME( newFromLiteral )( ppThis, "!!br0ken!!", 10, 0 );
    1213           2 :         return;
    1214             :     }
    1215             : 
    1216     1532756 :     IMPL_RTL_STRINGNAME( newFromStr_WithLength )( ppThis, pFrom->buffer + beginIndex, count );
    1217             : }
    1218             : 
    1219             : /* ----------------------------------------------------------------------- */
    1220             : 
    1221             : // Used when creating from string literals.
    1222     3968884 : void SAL_CALL IMPL_RTL_STRINGNAME( newFromLiteral )( IMPL_RTL_STRINGDATA** ppThis,
    1223             :                                                      const sal_Char* pCharStr,
    1224             :                                                      sal_Int32 nLen,
    1225             :                                                      sal_Int32 allocExtra )
    1226             :     SAL_THROW_EXTERN_C()
    1227             : {
    1228     3968884 :     if ( !nLen )
    1229             :     {
    1230      861031 :         IMPL_RTL_STRINGNAME( new )( ppThis );
    1231     4829915 :         return;
    1232             :     }
    1233             : 
    1234     3107853 :     if ( *ppThis )
    1235      369365 :         IMPL_RTL_STRINGNAME( release )( *ppThis );
    1236             : 
    1237     3107853 :     *ppThis = IMPL_RTL_STRINGNAME( ImplAlloc )( nLen + allocExtra );
    1238             :     assert( *ppThis != NULL );
    1239     3107853 :     if ( (*ppThis) )
    1240             :     {
    1241     3107853 :         (*ppThis)->length = nLen; // fix after possible allocExtra != 0
    1242     3107853 :         (*ppThis)->buffer[nLen] = 0;
    1243     3107853 :         IMPL_RTL_STRCODE* pBuffer = (*ppThis)->buffer;
    1244             :         sal_Int32 nCount;
    1245    57217056 :         for( nCount = nLen; nCount > 0; --nCount )
    1246             :         {
    1247             :             /* Check ASCII range */
    1248             :             SAL_WARN_IF( ((unsigned char)*pCharStr) > 127, "rtl.string",
    1249             :                         "rtl_uString_newFromLiteral - Found char > 127" );
    1250             :             SAL_WARN_IF( ((unsigned char)*pCharStr) == '\0', "rtl.string",
    1251             :                         "rtl_uString_newFromLiteral - Found embedded \\0 character" );
    1252             : 
    1253    54109203 :             *pBuffer = *pCharStr;
    1254    54109203 :             pBuffer++;
    1255    54109203 :             pCharStr++;
    1256             :         }
    1257             :     }
    1258             : 
    1259             :     RTL_LOG_STRING_NEW( *ppThis );
    1260             : }
    1261             : 
    1262             : /* ----------------------------------------------------------------------- */
    1263             : 
    1264    36475423 : void SAL_CALL IMPL_RTL_STRINGNAME( assign )( IMPL_RTL_STRINGDATA** ppThis,
    1265             :                                              IMPL_RTL_STRINGDATA* pStr )
    1266             :     SAL_THROW_EXTERN_C()
    1267             : {
    1268             :     /* must be done at first, if pStr == *ppThis */
    1269    36475423 :     IMPL_RTL_AQUIRE( pStr );
    1270             : 
    1271    36475423 :     if ( *ppThis )
    1272    36072154 :         IMPL_RTL_STRINGNAME( release )( *ppThis );
    1273             : 
    1274    36475423 :     *ppThis = pStr;
    1275    36475423 : }
    1276             : 
    1277             : /* ----------------------------------------------------------------------- */
    1278             : 
    1279      194571 : sal_Int32 SAL_CALL IMPL_RTL_STRINGNAME( getLength )( const IMPL_RTL_STRINGDATA* pThis )
    1280             :     SAL_THROW_EXTERN_C()
    1281             : {
    1282      194571 :     return pThis->length;
    1283             : }
    1284             : 
    1285             : /* ----------------------------------------------------------------------- */
    1286             : 
    1287      418772 : IMPL_RTL_STRCODE* SAL_CALL IMPL_RTL_STRINGNAME( getStr )( IMPL_RTL_STRINGDATA * pThis )
    1288             :     SAL_THROW_EXTERN_C()
    1289             : {
    1290      418772 :     return pThis->buffer;
    1291             : }
    1292             : 
    1293             : /* ----------------------------------------------------------------------- */
    1294             : 
    1295     4155345 : void SAL_CALL IMPL_RTL_STRINGNAME( newConcat )( IMPL_RTL_STRINGDATA** ppThis,
    1296             :                                                 IMPL_RTL_STRINGDATA* pLeft,
    1297             :                                                 IMPL_RTL_STRINGDATA* pRight )
    1298             :     SAL_THROW_EXTERN_C()
    1299             : {
    1300     4155345 :     IMPL_RTL_STRINGDATA* pOrg = *ppThis;
    1301             : 
    1302             :     /* Test for 0-Pointer - if not, change newReplaceStrAt! */
    1303     4155345 :     if ( !pRight || !pRight->length )
    1304             :     {
    1305      105767 :         *ppThis = pLeft;
    1306      105767 :         IMPL_RTL_AQUIRE( pLeft );
    1307             :     }
    1308     4049578 :     else if ( !pLeft || !pLeft->length )
    1309             :     {
    1310      729986 :         *ppThis = pRight;
    1311      729986 :         IMPL_RTL_AQUIRE( pRight );
    1312             :     }
    1313             :     else
    1314             :     {
    1315     3319592 :         IMPL_RTL_STRINGDATA* pTempStr = IMPL_RTL_STRINGNAME( ImplAlloc )( pLeft->length + pRight->length );
    1316             :         OSL_ASSERT(pTempStr != NULL);
    1317     3319592 :         rtl_str_ImplCopy( pTempStr->buffer, pLeft->buffer, pLeft->length );
    1318     3319592 :         rtl_str_ImplCopy( pTempStr->buffer+pLeft->length, pRight->buffer, pRight->length );
    1319     3319592 :         *ppThis = pTempStr;
    1320             : 
    1321             :         RTL_LOG_STRING_NEW( *ppThis );
    1322             :     }
    1323             : 
    1324             :     /* must be done last, if left or right == *ppThis */
    1325     4155345 :     if ( pOrg )
    1326     3995578 :         IMPL_RTL_STRINGNAME( release )( pOrg );
    1327     4155345 : }
    1328             : 
    1329             : /* ----------------------------------------------------------------------- */
    1330             : 
    1331        1171 : void SAL_CALL IMPL_RTL_STRINGNAME( ensureCapacity )( IMPL_RTL_STRINGDATA** ppThis,
    1332             :                                                      sal_Int32 size )
    1333             :     SAL_THROW_EXTERN_C()
    1334             : {
    1335        1171 :     IMPL_RTL_STRINGDATA* const pOrg = *ppThis;
    1336        1171 :     if ( pOrg->refCount == 1 && pOrg->length >= size )
    1337        1175 :         return;
    1338             :     assert( pOrg->length <= size ); // do not truncate
    1339        1167 :     IMPL_RTL_STRINGDATA* pTempStr = IMPL_RTL_STRINGNAME( ImplAlloc )( size );
    1340        1167 :     rtl_str_ImplCopy( pTempStr->buffer, pOrg->buffer, pOrg->length );
    1341             :     // right now the length is still the same as of the original
    1342        1167 :     pTempStr->length = pOrg->length;
    1343        1167 :     pTempStr->buffer[ pOrg->length ] = '\0';
    1344        1167 :     *ppThis = pTempStr;
    1345             :     RTL_LOG_STRING_NEW( *ppThis );
    1346             : 
    1347             :     /* must be done last, if pStr == *ppThis */
    1348        1167 :     if ( pOrg )
    1349        1167 :         IMPL_RTL_STRINGNAME( release )( pOrg );
    1350             : }
    1351             : 
    1352             : /* ----------------------------------------------------------------------- */
    1353             : 
    1354      198546 : void SAL_CALL IMPL_RTL_STRINGNAME( newReplaceStrAt )( IMPL_RTL_STRINGDATA** ppThis,
    1355             :                                                       IMPL_RTL_STRINGDATA* pStr,
    1356             :                                                       sal_Int32 nIndex,
    1357             :                                                       sal_Int32 nCount,
    1358             :                                                       IMPL_RTL_STRINGDATA* pNewSubStr )
    1359             :     SAL_THROW_EXTERN_C()
    1360             : {
    1361             :     /* Append? */
    1362      198546 :     if ( nIndex >= pStr->length )
    1363             :     {
    1364             :         /* newConcat test, if pNewSubStr is 0 */
    1365      159767 :         IMPL_RTL_STRINGNAME( newConcat )( ppThis, pStr, pNewSubStr );
    1366      159767 :         return;
    1367             :     }
    1368             : 
    1369             :     /* negativ index? */
    1370       38779 :     if ( nIndex < 0 )
    1371             :     {
    1372           0 :         nCount -= nIndex;
    1373           0 :         nIndex = 0;
    1374             :     }
    1375             : 
    1376             :     /* not more than the String length could be deleted */
    1377       38779 :     if ( nCount >= pStr->length-nIndex )
    1378             :     {
    1379       31062 :         nCount = pStr->length-nIndex;
    1380             : 
    1381             :         /* Assign of NewSubStr? */
    1382       31062 :         if ( !nIndex && (nCount >= pStr->length) )
    1383             :         {
    1384       11079 :             if ( !pNewSubStr )
    1385           0 :                 IMPL_RTL_STRINGNAME( new )( ppThis );
    1386             :             else
    1387       11079 :                 IMPL_RTL_STRINGNAME( assign )( ppThis, pNewSubStr );
    1388       11079 :             return;
    1389             :         }
    1390             :     }
    1391             : 
    1392             :     /* Assign of Str? */
    1393       27700 :     if ( !nCount && (!pNewSubStr || !pNewSubStr->length) )
    1394             :     {
    1395           0 :         IMPL_RTL_STRINGNAME( assign )( ppThis, pStr );
    1396           0 :         return;
    1397             :     }
    1398             : 
    1399       27700 :     IMPL_RTL_STRINGDATA*    pOrg = *ppThis;
    1400             :     IMPL_RTL_STRCODE*       pBuffer;
    1401             :     sal_Int32               nNewLen;
    1402             : 
    1403             :     /* Calculate length of the new string */
    1404       27700 :     nNewLen = pStr->length-nCount;
    1405       27700 :     if ( pNewSubStr )
    1406       27700 :         nNewLen += pNewSubStr->length;
    1407             : 
    1408             :     /* Alloc New Buffer */
    1409       27700 :     *ppThis = IMPL_RTL_STRINGNAME( ImplAlloc )( nNewLen );
    1410             :     OSL_ASSERT(*ppThis != NULL);
    1411       27700 :     pBuffer = (*ppThis)->buffer;
    1412       27700 :     if ( nIndex )
    1413             :     {
    1414       22926 :         rtl_str_ImplCopy( pBuffer, pStr->buffer, nIndex );
    1415       22926 :         pBuffer += nIndex;
    1416             :     }
    1417       27700 :     if ( pNewSubStr && pNewSubStr->length )
    1418             :     {
    1419       27267 :         rtl_str_ImplCopy( pBuffer, pNewSubStr->buffer, pNewSubStr->length );
    1420       27267 :         pBuffer += pNewSubStr->length;
    1421             :     }
    1422       27700 :     rtl_str_ImplCopy( pBuffer, pStr->buffer+nIndex+nCount, pStr->length-nIndex-nCount );
    1423             : 
    1424             :     RTL_LOG_STRING_NEW( *ppThis );
    1425             :     /* must be done last, if pStr or pNewSubStr == *ppThis */
    1426       27700 :     if ( pOrg )
    1427           0 :         IMPL_RTL_STRINGNAME( release )( pOrg );
    1428             : }
    1429             : 
    1430             : /* ----------------------------------------------------------------------- */
    1431             : 
    1432      127074 : void SAL_CALL IMPL_RTL_STRINGNAME( newReplace )( IMPL_RTL_STRINGDATA** ppThis,
    1433             :                                                  IMPL_RTL_STRINGDATA* pStr,
    1434             :                                                  IMPL_RTL_STRCODE cOld,
    1435             :                                                  IMPL_RTL_STRCODE cNew )
    1436             :     SAL_THROW_EXTERN_C()
    1437             : {
    1438      127074 :     IMPL_RTL_STRINGDATA*    pOrg        = *ppThis;
    1439      127074 :     int                     bChanged    = 0;
    1440      127074 :     sal_Int32               nLen        = pStr->length;
    1441      127074 :     const IMPL_RTL_STRCODE* pCharStr    = pStr->buffer;
    1442             : 
    1443      771842 :     while ( nLen > 0 )
    1444             :     {
    1445      593276 :         if ( *pCharStr == cOld )
    1446             :         {
    1447             :             /* Copy String */
    1448       75582 :             IMPL_RTL_STRCODE* pNewCharStr = IMPL_RTL_STRINGNAME( ImplNewCopy )( ppThis, pStr, pCharStr-pStr->buffer );
    1449             : 
    1450             :             /* replace/copy rest of the string */
    1451       75582 :             if ( pNewCharStr )
    1452             :             {
    1453       75582 :                 *pNewCharStr = cNew;
    1454       75582 :                 pNewCharStr++;
    1455       75582 :                 pCharStr++;
    1456       75582 :                 nLen--;
    1457             : 
    1458     2323594 :                 while ( nLen > 0 )
    1459             :                 {
    1460     2172430 :                     if ( *pCharStr == cOld )
    1461      230050 :                         *pNewCharStr = cNew;
    1462             :                     else
    1463     1942380 :                         *pNewCharStr = *pCharStr;
    1464             : 
    1465     2172430 :                     pNewCharStr++;
    1466     2172430 :                     pCharStr++;
    1467     2172430 :                     nLen--;
    1468             :                 }
    1469             :             }
    1470             : 
    1471       75582 :             bChanged = 1;
    1472       75582 :             break;
    1473             :         }
    1474             : 
    1475      517694 :         pCharStr++;
    1476      517694 :         nLen--;
    1477             :     }
    1478             : 
    1479      127074 :     if ( !bChanged )
    1480             :     {
    1481       51492 :         *ppThis = pStr;
    1482       51492 :         IMPL_RTL_AQUIRE( pStr );
    1483             :     }
    1484             : 
    1485             :     RTL_LOG_STRING_NEW( *ppThis );
    1486             :     /* must be done last, if pStr == *ppThis */
    1487      127074 :     if ( pOrg )
    1488           0 :         IMPL_RTL_STRINGNAME( release )( pOrg );
    1489      127074 : }
    1490             : 
    1491             : /* ----------------------------------------------------------------------- */
    1492             : 
    1493      327715 : void SAL_CALL IMPL_RTL_STRINGNAME( newToAsciiLowerCase )( IMPL_RTL_STRINGDATA** ppThis,
    1494             :                                                           IMPL_RTL_STRINGDATA* pStr )
    1495             :     SAL_THROW_EXTERN_C()
    1496             : {
    1497      327715 :     IMPL_RTL_STRINGDATA*    pOrg        = *ppThis;
    1498      327715 :     int                     bChanged    = 0;
    1499      327715 :     sal_Int32               nLen        = pStr->length;
    1500      327715 :     const IMPL_RTL_STRCODE* pCharStr    = pStr->buffer;
    1501             : 
    1502     1818868 :     while ( nLen > 0 )
    1503             :     {
    1504             :         /* Between A-Z (65-90), than to lowercase (+32) */
    1505     1254811 :         if ( (*pCharStr >= 65) && (*pCharStr <= 90) )
    1506             :         {
    1507             :             /* Copy String */
    1508       91373 :             IMPL_RTL_STRCODE* pNewCharStr = IMPL_RTL_STRINGNAME( ImplNewCopy )( ppThis, pStr, pCharStr-pStr->buffer );
    1509             : 
    1510             :             /* replace/copy rest of the string */
    1511       91373 :             if ( pNewCharStr )
    1512             :             {
    1513             :                 /* to lowercase (+32) */
    1514       91373 :                 *pNewCharStr = *pCharStr+32;
    1515       91373 :                 pNewCharStr++;
    1516       91373 :                 pCharStr++;
    1517       91373 :                 nLen--;
    1518             : 
    1519     1238221 :                 while ( nLen > 0 )
    1520             :                 {
    1521             :                     /* Between A-Z (65-90), than to lowercase (+32) */
    1522     1055475 :                     if ( (*pCharStr >= 65) && (*pCharStr <= 90) )
    1523      133060 :                         *pNewCharStr = *pCharStr+32;
    1524             :                     else
    1525      922415 :                         *pNewCharStr = *pCharStr;
    1526             : 
    1527     1055475 :                     pNewCharStr++;
    1528     1055475 :                     pCharStr++;
    1529     1055475 :                     nLen--;
    1530             :                 }
    1531             :             }
    1532             : 
    1533       91373 :             bChanged = 1;
    1534       91373 :             break;
    1535             :         }
    1536             : 
    1537     1163438 :         pCharStr++;
    1538     1163438 :         nLen--;
    1539             :     }
    1540             : 
    1541      327715 :     if ( !bChanged )
    1542             :     {
    1543      236342 :         *ppThis = pStr;
    1544      236342 :         IMPL_RTL_AQUIRE( pStr );
    1545             :     }
    1546             : 
    1547             :     RTL_LOG_STRING_NEW( *ppThis );
    1548             :     /* must be done last, if pStr == *ppThis */
    1549      327715 :     if ( pOrg )
    1550           0 :         IMPL_RTL_STRINGNAME( release )( pOrg );
    1551      327715 : }
    1552             : 
    1553             : /* ----------------------------------------------------------------------- */
    1554             : 
    1555      240571 : void SAL_CALL IMPL_RTL_STRINGNAME( newToAsciiUpperCase )( IMPL_RTL_STRINGDATA** ppThis,
    1556             :                                                           IMPL_RTL_STRINGDATA* pStr )
    1557             :     SAL_THROW_EXTERN_C()
    1558             : {
    1559      240571 :     IMPL_RTL_STRINGDATA*    pOrg        = *ppThis;
    1560      240571 :     int                     bChanged    = 0;
    1561      240571 :     sal_Int32               nLen        = pStr->length;
    1562      240571 :     const IMPL_RTL_STRCODE* pCharStr    = pStr->buffer;
    1563             : 
    1564      723640 :     while ( nLen > 0 )
    1565             :     {
    1566             :         /* Between a-z (97-122), than to uppercase (-32) */
    1567      245514 :         if ( (*pCharStr >= 97) && (*pCharStr <= 122) )
    1568             :         {
    1569             :             /* Copy String */
    1570        3016 :             IMPL_RTL_STRCODE* pNewCharStr = IMPL_RTL_STRINGNAME( ImplNewCopy )( ppThis, pStr, pCharStr-pStr->buffer );
    1571             : 
    1572             :             /* replace/copy rest of the string */
    1573        3016 :             if ( pNewCharStr )
    1574             :             {
    1575             :                 /* to uppercase (-32) */
    1576        3016 :                 *pNewCharStr = *pCharStr-32;
    1577        3016 :                 pNewCharStr++;
    1578        3016 :                 pCharStr++;
    1579        3016 :                 nLen--;
    1580             : 
    1581       50146 :                 while ( nLen > 0 )
    1582             :                 {
    1583             :                     /* Between a-z (97-122), than to uppercase (-32) */
    1584       44114 :                     if ( (*pCharStr >= 97) && (*pCharStr <= 122) )
    1585       23348 :                         *pNewCharStr = *pCharStr-32;
    1586             :                     else
    1587       20766 :                         *pNewCharStr = *pCharStr;
    1588             : 
    1589       44114 :                     pNewCharStr++;
    1590       44114 :                     pCharStr++;
    1591       44114 :                     nLen--;
    1592             :                 }
    1593             :             }
    1594             : 
    1595        3016 :             bChanged = 1;
    1596        3016 :             break;
    1597             :         }
    1598             : 
    1599      242498 :         pCharStr++;
    1600      242498 :         nLen--;
    1601             :     }
    1602             : 
    1603      240571 :     if ( !bChanged )
    1604             :     {
    1605      237555 :         *ppThis = pStr;
    1606      237555 :         IMPL_RTL_AQUIRE( pStr );
    1607             :     }
    1608             : 
    1609             :     RTL_LOG_STRING_NEW( *ppThis );
    1610             :     /* must be done last, if pStr == *ppThis */
    1611      240571 :     if ( pOrg )
    1612           0 :         IMPL_RTL_STRINGNAME( release )( pOrg );
    1613      240571 : }
    1614             : 
    1615             : /* ----------------------------------------------------------------------- */
    1616             : 
    1617       89601 : void SAL_CALL IMPL_RTL_STRINGNAME( newTrim )( IMPL_RTL_STRINGDATA** ppThis,
    1618             :                                               IMPL_RTL_STRINGDATA* pStr )
    1619             :     SAL_THROW_EXTERN_C()
    1620             : {
    1621       89601 :     IMPL_RTL_STRINGDATA*    pOrg        = *ppThis;
    1622       89601 :     const IMPL_RTL_STRCODE* pCharStr    = pStr->buffer;
    1623       89601 :     sal_Int32               nPreSpaces  = 0;
    1624       89601 :     sal_Int32               nPostSpaces = 0;
    1625       89601 :     sal_Int32               nLen        = pStr->length;
    1626       89601 :     sal_Int32               nIndex      = nLen-1;
    1627             : 
    1628      187712 :     while ( (nPreSpaces < nLen) && rtl_ImplIsWhitespace( IMPL_RTL_USTRCODE(*(pCharStr+nPreSpaces)) ) )
    1629        8510 :         nPreSpaces++;
    1630             : 
    1631      179630 :     while ( (nIndex > nPreSpaces) && rtl_ImplIsWhitespace( IMPL_RTL_USTRCODE(*(pCharStr+nIndex)) ) )
    1632             :     {
    1633         428 :         nPostSpaces++;
    1634         428 :         nIndex--;
    1635             :     }
    1636             : 
    1637       89601 :     if ( !nPreSpaces && !nPostSpaces )
    1638             :     {
    1639       87915 :         *ppThis = pStr;
    1640       87915 :         IMPL_RTL_AQUIRE( pStr );
    1641             :     }
    1642             :     else
    1643             :     {
    1644        1686 :         nLen -= nPostSpaces+nPreSpaces;
    1645        1686 :         *ppThis = IMPL_RTL_STRINGNAME( ImplAlloc )( nLen );
    1646             :         OSL_ASSERT(*ppThis != NULL);
    1647        1686 :         if ( *ppThis )
    1648        1686 :             rtl_str_ImplCopy( (*ppThis)->buffer, pStr->buffer+nPreSpaces, nLen );
    1649             :     }
    1650             : 
    1651             :     RTL_LOG_STRING_NEW( *ppThis );
    1652             :     /* must be done last, if pStr == *ppThis */
    1653       89601 :     if ( pOrg )
    1654           0 :         IMPL_RTL_STRINGNAME( release )( pOrg );
    1655       89601 : }
    1656             : 
    1657             : /* ----------------------------------------------------------------------- */
    1658             : 
    1659     1688889 : sal_Int32 SAL_CALL IMPL_RTL_STRINGNAME( getToken )( IMPL_RTL_STRINGDATA** ppThis,
    1660             :                                                     IMPL_RTL_STRINGDATA* pStr,
    1661             :                                                     sal_Int32 nToken,
    1662             :                                                     IMPL_RTL_STRCODE cTok,
    1663             :                                                     sal_Int32 nIndex )
    1664             :     SAL_THROW_EXTERN_C()
    1665             : {
    1666     1688889 :     const IMPL_RTL_STRCODE* pCharStr        = pStr->buffer;
    1667             :     const IMPL_RTL_STRCODE* pCharStrStart;
    1668             :     const IMPL_RTL_STRCODE* pOrgCharStr;
    1669     1688889 :     sal_Int32               nLen            = pStr->length-nIndex;
    1670     1688889 :     sal_Int32               nTokCount       = 0;
    1671             : 
    1672             :     // Set ppThis to an empty string and return -1 if either nToken or nIndex is
    1673             :     // negative:
    1674     1688889 :     if (nIndex < 0)
    1675         388 :         nToken = -1;
    1676             : 
    1677     1688889 :     pCharStr += nIndex;
    1678     1688889 :     pOrgCharStr = pCharStr;
    1679     1688889 :     pCharStrStart = pCharStr;
    1680    10112105 :     while ( nLen > 0 )
    1681             :     {
    1682     8112502 :         if ( *pCharStr == cTok )
    1683             :         {
    1684     1380018 :             nTokCount++;
    1685             : 
    1686     1380018 :             if ( nTokCount == nToken )
    1687        1837 :                 pCharStrStart = pCharStr+1;
    1688             :             else
    1689             :             {
    1690     1378181 :                 if ( nTokCount > nToken )
    1691     1378175 :                     break;
    1692             :             }
    1693             :         }
    1694             : 
    1695     6734327 :         pCharStr++;
    1696     6734327 :         nLen--;
    1697             :     }
    1698             : 
    1699     1688889 :     if ( (nToken < 0) || (nTokCount < nToken) || (pCharStr == pCharStrStart) )
    1700             :     {
    1701      260937 :         IMPL_RTL_STRINGNAME( new )( ppThis );
    1702      260937 :         if( (nToken < 0) || (nTokCount < nToken ) )
    1703         392 :             return -1;
    1704      260545 :         else if( nLen > 0 )
    1705       50145 :             return nIndex+(pCharStr-pOrgCharStr)+1;
    1706      210400 :         else return -1;
    1707             :     }
    1708             :     else
    1709             :     {
    1710     1427952 :         IMPL_RTL_STRINGNAME( newFromStr_WithLength )( ppThis, pCharStrStart, pCharStr-pCharStrStart );
    1711     1427952 :         if ( nLen )
    1712     1327822 :             return nIndex+(pCharStr-pOrgCharStr)+1;
    1713             :         else
    1714      100130 :             return -1;
    1715             :     }
    1716             : }
    1717             : 
    1718             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10