LCOV - code coverage report
Current view: top level - tools/source/string - strimp.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 193 218 88.5 %
Date: 2012-08-25 Functions: 21 23 91.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 80 104 76.9 %

           Branch data     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                 :          0 : static sal_Int32 ImplStringCompare( const STRCODE* pStr1, const STRCODE* pStr2,
      21                 :            :                                     xub_StrLen nCount )
      22                 :            : {
      23                 :          0 :     sal_Int32 nRet = 0;
      24 [ #  # ][ #  # ]:          0 :     while ( nCount &&
         [ #  # ][ #  # ]
      25                 :            :             ((nRet = ((sal_Int32)((STRCODEU)*pStr1))-((sal_Int32)((STRCODEU)*pStr2))) == 0) &&
      26                 :            :             *pStr2 )
      27                 :            :     {
      28                 :            :         ++pStr1,
      29                 :            :         ++pStr2,
      30                 :          0 :         --nCount;
      31                 :            :     }
      32                 :            : 
      33                 :          0 :     return nRet;
      34                 :            : }
      35                 :            : 
      36                 :   85419277 : static sal_Int32 ImplStringCompareWithoutZero( const STRCODE* pStr1, const STRCODE* pStr2,
      37                 :            :                                                sal_Int32 nCount )
      38                 :            : {
      39                 :   85419277 :     sal_Int32 nRet = 0;
      40 [ +  + ][ +  + ]:  131739968 :     while ( nCount &&
                 [ +  + ]
      41                 :            :             ((nRet = ((sal_Int32)((STRCODEU)*pStr1))-((sal_Int32)((STRCODEU)*pStr2))) == 0) )
      42                 :            :     {
      43                 :            :         ++pStr1,
      44                 :            :         ++pStr2,
      45                 :   46320691 :         --nCount;
      46                 :            :     }
      47                 :            : 
      48                 :   85419277 :     return nRet;
      49                 :            : }
      50                 :            : 
      51                 :            : #ifdef DBG_UTIL
      52                 :            : const char* DBGCHECKSTRING( const void* pString )
      53                 :            : {
      54                 :            :     STRING* p = (STRING*)pString;
      55                 :            : 
      56                 :            :     if ( p->GetBuffer()[p->Len()] != 0 )
      57                 :            :         return "String damaged: aStr[nLen] != 0";
      58                 :            : 
      59                 :            :     return NULL;
      60                 :            : }
      61                 :            : #endif
      62                 :            : 
      63                 :    9641823 : static STRINGDATA* ImplAllocData( sal_Int32 nLen )
      64                 :            : {
      65                 :    9641823 :     STRINGDATA* pData   = (STRINGDATA*)rtl_allocateMemory( sizeof(STRINGDATA)+(nLen*sizeof( STRCODE )) );
      66                 :    9641823 :     pData->mnRefCount   = 1;
      67                 :    9641823 :     pData->mnLen        = nLen;
      68                 :    9641823 :     pData->maStr[nLen]  = 0;
      69                 :    9641823 :     return pData;
      70                 :            : }
      71                 :            : 
      72                 :    1314720 : static STRINGDATA* _ImplCopyData( STRINGDATA* pData )
      73                 :            : {
      74                 :    1314720 :     unsigned int    nSize       = sizeof(STRINGDATA)+(pData->mnLen*sizeof( STRCODE ));
      75                 :    1314720 :     STRINGDATA*     pNewData    = (STRINGDATA*)rtl_allocateMemory( nSize );
      76                 :    1314720 :     memcpy( pNewData, pData, nSize );
      77                 :    1314720 :     pNewData->mnRefCount = 1;
      78                 :    1314720 :     STRING_RELEASE((STRING_TYPE *)pData);
      79                 :    1314720 :     return pNewData;
      80                 :            : }
      81                 :            : 
      82                 :    2267292 : inline void STRING::ImplCopyData()
      83                 :            : {
      84                 :            :     DBG_ASSERT( (mpData->mnRefCount != 0), "String::ImplCopyData() - RefCount == 0" );
      85                 :            : 
      86                 :            :     // Dereference data if this string is referenced
      87         [ +  + ]:    2267292 :     if ( mpData->mnRefCount != 1 )
      88                 :     710325 :         mpData = _ImplCopyData( mpData );
      89                 :    2267292 : }
      90                 :            : 
      91                 :    2111096 : inline STRCODE* STRING::ImplCopyStringData( STRCODE* pStr )
      92                 :            : {
      93         [ +  + ]:    2111096 :     if ( mpData->mnRefCount != 1 ) {
      94                 :            :         DBG_ASSERT( (pStr >= mpData->maStr) &&
      95                 :            :                     ((pStr-mpData->maStr) < mpData->mnLen),
      96                 :            :                     "ImplCopyStringData - pStr from other String-Instanz" );
      97                 :     604395 :         unsigned int nIndex = (unsigned int)(pStr-mpData->maStr);
      98                 :     604395 :         mpData = _ImplCopyData( mpData );
      99                 :     604395 :         pStr = mpData->maStr + nIndex;
     100                 :            :     }
     101                 :    2111096 :     return pStr;
     102                 :            : }
     103                 :            : 
     104                 :    2956740 : inline sal_Int32 ImplGetCopyLen( sal_Int32 nStrLen, sal_Int32 nCopyLen )
     105                 :            : {
     106                 :            :     OSL_ASSERT(nStrLen <= STRING_MAXLEN && nCopyLen <= STRING_MAXLEN);
     107         [ -  + ]:    2956740 :     if ( nCopyLen > STRING_MAXLEN-nStrLen )
     108                 :          0 :         nCopyLen = STRING_MAXLEN-nStrLen;
     109                 :    2956740 :     return nCopyLen;
     110                 :            : }
     111                 :            : 
     112                 :   20809310 : STRING::STRING()
     113                 :   20809310 :     : mpData(NULL)
     114                 :            : {
     115                 :            :     DBG_CTOR( STRING, DBGCHECKSTRING );
     116                 :            : 
     117                 :   20809310 :     STRING_NEW((STRING_TYPE **)&mpData);
     118                 :   20809311 : }
     119                 :            : 
     120                 :   42274693 : STRING::STRING( const STRING& rStr )
     121                 :            : {
     122                 :            :     DBG_CTOR( STRING, DBGCHECKSTRING );
     123                 :            :     DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING );
     124                 :            : 
     125                 :            :     // Set pointer to argument string and increase reference counter
     126                 :   42274693 :     STRING_ACQUIRE((STRING_TYPE *)rStr.mpData);
     127                 :   42274695 :     mpData = rStr.mpData;
     128                 :   42274695 : }
     129                 :            : 
     130                 :    1164178 : STRING::STRING( const STRING& rStr, xub_StrLen nPos, xub_StrLen nLen )
     131                 :    1164178 : : mpData( NULL )
     132                 :            : {
     133                 :            :     DBG_CTOR( STRING, DBGCHECKSTRING );
     134                 :            :     DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING );
     135                 :            : 
     136         [ +  + ]:    1164178 :     if ( nPos > rStr.mpData->mnLen )
     137                 :        174 :         nLen = 0;
     138                 :            :     else
     139                 :            :     {
     140                 :            :         // correct length if necessary
     141                 :    1164004 :         sal_Int32 nMaxLen = rStr.mpData->mnLen-nPos;
     142         [ +  + ]:    1164004 :         if ( nLen > nMaxLen )
     143                 :      84279 :             nLen = static_cast< xub_StrLen >(nMaxLen);
     144                 :            :     }
     145                 :            : 
     146         [ +  + ]:    1164178 :     if ( nLen )
     147                 :            :     {
     148                 :            :         // Increase reference counter if it suffices
     149 [ +  + ][ +  + ]:    1131709 :         if ( (nPos == 0) && (nLen == rStr.mpData->mnLen) )
     150                 :            :         {
     151                 :     356712 :             STRING_ACQUIRE((STRING_TYPE *)rStr.mpData);
     152                 :     356712 :             mpData = rStr.mpData;
     153                 :            :         }
     154                 :            :         else
     155                 :            :         {
     156                 :            :             // otherwise, copy string
     157                 :     774997 :             mpData = ImplAllocData( nLen );
     158                 :    1131709 :             memcpy( mpData->maStr, rStr.mpData->maStr+nPos, nLen*sizeof( STRCODE ) );
     159                 :            :         }
     160                 :            :     }
     161                 :            :     else
     162                 :            :     {
     163                 :      32469 :         STRING_NEW((STRING_TYPE **)&mpData);
     164                 :            :     }
     165                 :    1164178 : }
     166                 :            : 
     167                 :   82506604 : STRING::~STRING()
     168                 :            : {
     169                 :            :     DBG_DTOR( STRING, DBGCHECKSTRING );
     170                 :            : 
     171                 :            :     // free string data
     172                 :   82506604 :     STRING_RELEASE((STRING_TYPE *)mpData);
     173                 :   82506612 : }
     174                 :            : 
     175                 :   14786710 : STRING& STRING::Assign( const STRING& rStr )
     176                 :            : {
     177                 :            :     DBG_CHKTHIS( STRING, DBGCHECKSTRING );
     178                 :            :     DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING );
     179                 :            : 
     180                 :   14786710 :     STRING_ACQUIRE((STRING_TYPE *)rStr.mpData);
     181                 :   14786718 :     STRING_RELEASE((STRING_TYPE *)mpData);
     182                 :   14786710 :     mpData = rStr.mpData;
     183                 :   14786710 :     return *this;
     184                 :            : }
     185                 :            : 
     186                 :    2583711 : STRING& STRING::Append( const STRING& rStr )
     187                 :            : {
     188                 :            :     DBG_CHKTHIS( STRING, DBGCHECKSTRING );
     189                 :            :     DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING );
     190                 :            : 
     191                 :            :     // Assignment is sufficient if string is empty
     192                 :    2583711 :     sal_Int32 nLen = mpData->mnLen;
     193         [ +  + ]:    2583711 :     if ( !nLen )
     194                 :            :     {
     195                 :     376926 :         STRING_ACQUIRE((STRING_TYPE *)rStr.mpData);
     196                 :     376926 :         STRING_RELEASE((STRING_TYPE *)mpData);
     197                 :     376926 :         mpData = rStr.mpData;
     198                 :            :     }
     199                 :            :     else
     200                 :            :     {
     201                 :            :         // Detect overflow
     202                 :    2206785 :         sal_Int32 nCopyLen = ImplGetCopyLen( nLen, rStr.mpData->mnLen );
     203                 :            : 
     204         [ +  + ]:    2206785 :         if ( nCopyLen )
     205                 :            :         {
     206                 :            :             // allocate string of new size
     207                 :    2157260 :             STRINGDATA* pNewData = ImplAllocData( nLen+nCopyLen );
     208                 :            : 
     209                 :            :             // copy string
     210                 :    2157260 :             memcpy( pNewData->maStr, mpData->maStr, nLen*sizeof( STRCODE ) );
     211                 :    2157260 :             memcpy( pNewData->maStr+nLen, rStr.mpData->maStr, nCopyLen*sizeof( STRCODE ) );
     212                 :            : 
     213                 :            :             // free old string
     214                 :    2157260 :             STRING_RELEASE((STRING_TYPE *)mpData);
     215                 :    2157260 :             mpData = pNewData;
     216                 :            :         }
     217                 :            :     }
     218                 :            : 
     219                 :    2583711 :     return *this;
     220                 :            : }
     221                 :            : 
     222                 :      22380 : STRING& STRING::Append( const STRCODE* pCharStr )
     223                 :            : {
     224                 :            :     DBG_CHKTHIS( STRING, DBGCHECKSTRING );
     225                 :            :     DBG_ASSERT( pCharStr, "String::Append() - pCharStr is NULL" );
     226                 :            : 
     227                 :            :     // determine string length
     228                 :      22380 :     sal_Int32 nLen = mpData->mnLen;
     229                 :      22380 :     sal_Int32 nCopyLen = ImplStringLen( pCharStr );
     230                 :            : 
     231                 :            :     // detect overflow
     232                 :      22380 :     nCopyLen = ImplGetCopyLen( nLen, nCopyLen );
     233                 :            : 
     234         [ +  + ]:      22380 :     if ( nCopyLen )
     235                 :            :     {
     236                 :            :         // allocate string of new size
     237                 :      22360 :         STRINGDATA* pNewData = ImplAllocData( nLen+nCopyLen );
     238                 :            : 
     239                 :            :         // copy string
     240                 :      22360 :         memcpy( pNewData->maStr, mpData->maStr, nLen*sizeof( STRCODE ) );
     241                 :      22360 :         memcpy( pNewData->maStr+nLen, pCharStr, nCopyLen*sizeof( STRCODE ) );
     242                 :            : 
     243                 :            :         // free old string
     244                 :      22360 :         STRING_RELEASE((STRING_TYPE *)mpData);
     245                 :      22360 :         mpData = pNewData;
     246                 :            :     }
     247                 :            : 
     248                 :      22380 :     return *this;
     249                 :            : }
     250                 :            : 
     251                 :    2194280 : void STRING::SetChar( xub_StrLen nIndex, STRCODE c )
     252                 :            : {
     253                 :            :     DBG_CHKTHIS( STRING, DBGCHECKSTRING );
     254                 :            :     DBG_ASSERT( nIndex < mpData->mnLen, "String::SetChar() - nIndex > String.Len()" );
     255                 :            : 
     256                 :            :     // copy data if necessary
     257                 :    2194280 :     ImplCopyData();
     258                 :    2194280 :     mpData->maStr[nIndex] = c;
     259                 :    2194280 : }
     260                 :            : 
     261                 :     691603 : STRING& STRING::Insert( const STRING& rStr, xub_StrLen nIndex )
     262                 :            : {
     263                 :            :     DBG_CHKTHIS( STRING, DBGCHECKSTRING );
     264                 :            :     DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING );
     265                 :            : 
     266                 :            :     // detect overflow
     267                 :     691603 :     sal_Int32 nCopyLen = ImplGetCopyLen( mpData->mnLen, rStr.mpData->mnLen );
     268                 :            : 
     269         [ +  + ]:     691603 :     if ( !nCopyLen )
     270                 :       8034 :         return *this;
     271                 :            : 
     272                 :            :     // adjust index if necessary
     273         [ +  + ]:     683569 :     if ( nIndex > mpData->mnLen )
     274                 :        725 :         nIndex = static_cast< xub_StrLen >(mpData->mnLen);
     275                 :            : 
     276                 :            :     // allocate string of new size
     277                 :     683569 :     STRINGDATA* pNewData = ImplAllocData( mpData->mnLen+nCopyLen );
     278                 :            : 
     279                 :            :     // copy string
     280                 :     683569 :     memcpy( pNewData->maStr, mpData->maStr, nIndex*sizeof( STRCODE ) );
     281                 :     683569 :     memcpy( pNewData->maStr+nIndex, rStr.mpData->maStr, nCopyLen*sizeof( STRCODE ) );
     282                 :     683569 :     memcpy( pNewData->maStr+nIndex+nCopyLen, mpData->maStr+nIndex,
     283                 :    1367138 :             (mpData->mnLen-nIndex)*sizeof( STRCODE ) );
     284                 :            : 
     285                 :            :     // free old string
     286                 :     683569 :     STRING_RELEASE((STRING_TYPE *)mpData);
     287                 :     683569 :     mpData = pNewData;
     288                 :            : 
     289                 :     691603 :     return *this;
     290                 :            : }
     291                 :            : 
     292                 :     143033 : STRING& STRING::Replace( xub_StrLen nIndex, xub_StrLen nCount, const STRING& rStr )
     293                 :            : {
     294                 :            :     DBG_CHKTHIS( STRING, DBGCHECKSTRING );
     295                 :            :     DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING );
     296                 :            : 
     297                 :            :     // Append if index > current length
     298         [ +  + ]:     143033 :     if ( nIndex >= mpData->mnLen )
     299                 :            :     {
     300                 :          8 :         Append( rStr );
     301                 :          8 :         return *this;
     302                 :            :     }
     303                 :            : 
     304                 :            :     // assign if index = 0 and length >= stringlen
     305 [ +  + ][ +  + ]:     143025 :     if ( (nIndex == 0) && (nCount >= mpData->mnLen) )
     306                 :            :     {
     307                 :      52541 :         Assign( rStr );
     308                 :      52541 :         return *this;
     309                 :            :     }
     310                 :            : 
     311                 :            :     // Use erase if replacestring is empty
     312                 :      90484 :     sal_Int32 nStrLen = rStr.mpData->mnLen;
     313         [ +  + ]:      90484 :     if ( !nStrLen )
     314                 :       8859 :         return Erase( nIndex, nCount );
     315                 :            : 
     316                 :            :     // Adjust nCount if it's larger than the string
     317         [ -  + ]:      81625 :     if ( nCount > mpData->mnLen - nIndex )
     318                 :          0 :         nCount = static_cast< xub_StrLen >(mpData->mnLen-nIndex);
     319                 :            : 
     320         [ +  + ]:      81625 :     if ( !nCount )
     321                 :          8 :         return Insert( rStr, nIndex );
     322                 :            : 
     323                 :            :     // Use character-based assignment if length is equal
     324         [ +  + ]:      81617 :     if ( nCount == nStrLen )
     325                 :            :     {
     326                 :      69689 :         ImplCopyData();
     327                 :      69689 :         memcpy( mpData->maStr+nIndex, rStr.mpData->maStr, nCount*sizeof( STRCODE ) );
     328                 :      69689 :         return *this;
     329                 :            :     }
     330                 :            : 
     331                 :            :     // detect overflow
     332                 :      11928 :     nStrLen = ImplGetCopyLen( mpData->mnLen-nCount, nStrLen );
     333                 :            : 
     334                 :            :     // allocate string of new size
     335                 :      11928 :     STRINGDATA* pNewData = ImplAllocData( mpData->mnLen-nCount+nStrLen );
     336                 :            : 
     337                 :            :     // copy string
     338                 :      11928 :     memcpy( pNewData->maStr, mpData->maStr, nIndex*sizeof( STRCODE ) );
     339                 :      11928 :     memcpy( pNewData->maStr+nIndex, rStr.mpData->maStr, nStrLen*sizeof( STRCODE ) );
     340                 :      11928 :     memcpy( pNewData->maStr+nIndex+nStrLen, mpData->maStr+nIndex+nCount,
     341                 :      23856 :             (mpData->mnLen-nIndex-nCount+1)*sizeof( STRCODE ) );
     342                 :            : 
     343                 :            :     // free old string
     344                 :      11928 :     STRING_RELEASE((STRING_TYPE *)mpData);
     345                 :      11928 :     mpData = pNewData;
     346                 :            : 
     347                 :     143033 :     return *this;
     348                 :            : }
     349                 :            : 
     350                 :    4592595 : STRING& STRING::Erase( xub_StrLen nIndex, xub_StrLen nCount )
     351                 :            : {
     352                 :            :     DBG_CHKTHIS( STRING, DBGCHECKSTRING );
     353                 :            : 
     354                 :            :     // Return if index outside string or count = 0
     355 [ +  + ][ +  + ]:    4592595 :     if ( (nIndex >= mpData->mnLen) || !nCount )
     356                 :    1013596 :         return *this;
     357                 :            : 
     358                 :            :     // Adjust nCount if it's larger than the string
     359         [ +  + ]:    3578999 :     if ( nCount > mpData->mnLen - nIndex )
     360                 :    2271018 :         nCount = static_cast< xub_StrLen >(mpData->mnLen-nIndex);
     361                 :            : 
     362         [ +  + ]:    3578999 :     if ( mpData->mnLen - nCount )
     363                 :            :     {
     364                 :            :         // allocate string of new size
     365                 :    1154983 :         STRINGDATA* pNewData = ImplAllocData( mpData->mnLen-nCount );
     366                 :            : 
     367                 :            :         // copy string
     368                 :    1154983 :         memcpy( pNewData->maStr, mpData->maStr, nIndex*sizeof( STRCODE ) );
     369                 :    1154983 :         memcpy( pNewData->maStr+nIndex, mpData->maStr+nIndex+nCount,
     370                 :    2309966 :                 (mpData->mnLen-nIndex-nCount+1)*sizeof( STRCODE ) );
     371                 :            : 
     372                 :            :         // free old string
     373                 :    1154983 :         STRING_RELEASE((STRING_TYPE *)mpData);
     374                 :    1154983 :         mpData = pNewData;
     375                 :            :     }
     376                 :            :     else
     377                 :            :     {
     378                 :    2424016 :         STRING_NEW((STRING_TYPE **)&mpData);
     379                 :            :     }
     380                 :            : 
     381                 :    4592595 :     return *this;
     382                 :            : }
     383                 :            : 
     384                 :     743755 : STRING& STRING::ToLowerAscii()
     385                 :            : {
     386                 :            :     DBG_CHKTHIS( STRING, DBGCHECKSTRING );
     387                 :            : 
     388                 :     743755 :     sal_Int32 nIndex = 0;
     389                 :     743755 :     sal_Int32 nLen = mpData->mnLen;
     390                 :     743755 :     STRCODE*    pStr = mpData->maStr;
     391         [ +  + ]:   10948484 :     while ( nIndex < nLen )
     392                 :            :     {
     393                 :            :         // Convert if char is between 'A' and 'Z'
     394 [ +  + ][ +  + ]:   10204729 :         if ( (*pStr >= 65) && (*pStr <= 90) )
     395                 :            :         {
     396                 :            :             // allocate string of new size
     397                 :    2109129 :             pStr = ImplCopyStringData( pStr );
     398                 :    2109129 :             *pStr += 32;
     399                 :            :         }
     400                 :            : 
     401                 :            :         ++pStr,
     402                 :   10204729 :         ++nIndex;
     403                 :            :     }
     404                 :            : 
     405                 :     743755 :     return *this;
     406                 :            : }
     407                 :            : 
     408                 :    4437751 : xub_StrLen STRING::Search( STRCODE c, xub_StrLen nIndex ) const
     409                 :            : {
     410                 :            :     DBG_CHKTHIS( STRING, DBGCHECKSTRING );
     411                 :            : 
     412                 :    4437751 :     sal_Int32       nLen = mpData->mnLen;
     413                 :    4437751 :     const STRCODE*  pStr = mpData->maStr;
     414                 :    4437751 :     pStr += nIndex;
     415         [ +  + ]:   69373828 :     while ( nIndex < nLen )
     416                 :            :     {
     417         [ +  + ]:   65014654 :         if ( *pStr == c )
     418                 :      78577 :             return nIndex;
     419                 :            :         ++pStr,
     420                 :   64936077 :         ++nIndex;
     421                 :            :     }
     422                 :            : 
     423                 :    4437751 :     return STRING_NOTFOUND;
     424                 :            : }
     425                 :            : 
     426                 :   15860380 : xub_StrLen STRING::Search( const STRING& rStr, xub_StrLen nIndex ) const
     427                 :            : {
     428                 :            :     DBG_CHKTHIS( STRING, DBGCHECKSTRING );
     429                 :            :     DBG_CHKOBJ( &rStr, STRING, DBGCHECKSTRING );
     430                 :            : 
     431                 :   15860380 :     sal_Int32 nLen = mpData->mnLen;
     432                 :   15860380 :     sal_Int32 nStrLen = rStr.mpData->mnLen;
     433                 :            : 
     434                 :            :     // rStr was not found if its length is zero
     435                 :            :     // or index is larger than searched string
     436 [ +  + ][ +  + ]:   15860380 :     if ( !nStrLen || (nIndex >= nLen) )
     437                 :        346 :         return STRING_NOTFOUND;
     438                 :            : 
     439                 :   15860034 :     const STRCODE* pStr1 = mpData->maStr;
     440                 :   15860034 :     pStr1 += nIndex;
     441                 :            : 
     442         [ +  + ]:   15860034 :     if ( nStrLen == 1 )
     443                 :            :     {
     444                 :    4247543 :         STRCODE cSearch = rStr.mpData->maStr[0];
     445         [ +  + ]:   37077616 :         while ( nIndex < nLen )
     446                 :            :         {
     447         [ +  + ]:   33710682 :             if ( *pStr1 == cSearch )
     448                 :     880609 :                 return nIndex;
     449                 :            :             ++pStr1,
     450                 :   32830073 :             ++nIndex;
     451                 :            :         }
     452                 :            :     }
     453                 :            :     else
     454                 :            :     {
     455                 :   11612491 :         const STRCODE* pStr2 = rStr.mpData->maStr;
     456                 :            : 
     457                 :            :         // search only within string
     458         [ +  + ]:   88281539 :         while ( nLen - nIndex >= nStrLen )
     459                 :            :         {
     460                 :            :             // increase match if found
     461         [ +  + ]:   77778671 :             if ( ImplStringCompareWithoutZero( pStr1, pStr2, nStrLen ) == 0 )
     462                 :    1109623 :                 return nIndex;
     463                 :            :             ++pStr1,
     464                 :   76669048 :             ++nIndex;
     465                 :            :         }
     466                 :            :     }
     467                 :            : 
     468                 :   15860380 :     return STRING_NOTFOUND;
     469                 :            : }
     470                 :            : 
     471                 :          0 : xub_StrLen STRING::Search( const STRCODE* pCharStr, xub_StrLen nIndex ) const
     472                 :            : {
     473                 :            :     DBG_CHKTHIS( STRING, DBGCHECKSTRING );
     474                 :            : 
     475                 :          0 :     sal_Int32 nLen = mpData->mnLen;
     476                 :          0 :     xub_StrLen nStrLen  = ImplStringLen( pCharStr );
     477                 :            : 
     478                 :            :     // rStr was not found if its length is zero
     479                 :            :     // or index is larger than searched string
     480 [ #  # ][ #  # ]:          0 :     if ( !nStrLen || (nIndex >= nLen) )
     481                 :          0 :         return STRING_NOTFOUND;
     482                 :            : 
     483                 :          0 :     const STRCODE* pStr = mpData->maStr;
     484                 :          0 :     pStr += nIndex;
     485                 :            : 
     486         [ #  # ]:          0 :     if ( nStrLen == 1 )
     487                 :            :     {
     488                 :          0 :         STRCODE cSearch = *pCharStr;
     489         [ #  # ]:          0 :         while ( nIndex < nLen )
     490                 :            :         {
     491         [ #  # ]:          0 :             if ( *pStr == cSearch )
     492                 :          0 :                 return nIndex;
     493                 :            :             ++pStr,
     494                 :          0 :             ++nIndex;
     495                 :            :         }
     496                 :            :     }
     497                 :            :     else
     498                 :            :     {
     499                 :            :         // search only within string
     500         [ #  # ]:          0 :         while ( nLen - nIndex >= nStrLen )
     501                 :            :         {
     502                 :            :             // increase match if found
     503         [ #  # ]:          0 :             if ( ImplStringCompareWithoutZero( pStr, pCharStr, nStrLen ) == 0 )
     504                 :          0 :                 return nIndex;
     505                 :            :             ++pStr,
     506                 :          0 :             ++nIndex;
     507                 :            :         }
     508                 :            :     }
     509                 :            : 
     510                 :          0 :     return STRING_NOTFOUND;
     511                 :            : }
     512                 :            : 
     513                 :        955 : void STRING::SearchAndReplaceAll( STRCODE c, STRCODE cRep )
     514                 :            : {
     515                 :            :     DBG_CHKTHIS( STRING, DBGCHECKSTRING );
     516                 :            : 
     517                 :        955 :     sal_Int32       nLen    = mpData->mnLen;
     518                 :        955 :     const STRCODE*  pStr    = mpData->maStr;
     519                 :        955 :     sal_Int32       nIndex  = 0;
     520         [ +  + ]:      18665 :     while ( nIndex < nLen )
     521                 :            :     {
     522         [ +  + ]:      17710 :         if ( *pStr == c )
     523                 :            :         {
     524                 :         15 :             ImplCopyData();
     525                 :         15 :             mpData->maStr[nIndex] = cRep;
     526                 :            :         }
     527                 :            :         ++pStr,
     528                 :      17710 :         ++nIndex;
     529                 :            :     }
     530                 :        955 : }
     531                 :            : 
     532                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10