LCOV - code coverage report
Current view: top level - sal/rtl/source - ustrbuf.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 89 94 94.7 %
Date: 2012-08-25 Functions: 9 9 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 35 42 83.3 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <string.h>
      30                 :            : 
      31                 :            : #include <osl/interlck.h>
      32                 :            : 
      33                 :            : #include <rtl/ustrbuf.hxx>
      34                 :            : #include <rtl/memory.h>
      35                 :            : #include <strimp.hxx>
      36                 :            : 
      37                 :    3293000 : void SAL_CALL rtl_uStringbuffer_newFromStr_WithLength( rtl_uString ** newStr,
      38                 :            :                                                        const sal_Unicode * value,
      39                 :            :                                                        sal_Int32 count)
      40                 :            : {
      41         [ -  + ]:    3293000 :     if (!value)
      42                 :            :     {
      43                 :          0 :         rtl_uString_new_WithLength( newStr, 16 );
      44                 :          0 :         return;
      45                 :            :     }
      46                 :            : 
      47                 :    3293000 :     rtl_uString_new_WithLength( newStr, count + 16 );
      48                 :    3293001 :     (*newStr)->length = count;
      49                 :    3293001 :     memcpy( (*newStr)->buffer, value, count * sizeof(sal_Unicode));
      50                 :            :     RTL_LOG_STRING_NEW( *newStr );
      51                 :    3293001 :     return;
      52                 :            : }
      53                 :            : 
      54                 :   14963529 : rtl_uString * SAL_CALL rtl_uStringBuffer_refReturn( rtl_uString * pThis )
      55                 :            : {
      56                 :            :     RTL_LOG_STRING_NEW( pThis );
      57                 :   14963529 :     rtl_uString_acquire( pThis );
      58                 :   14963529 :     return pThis;
      59                 :            : }
      60                 :            : 
      61                 :   10478747 : rtl_uString * SAL_CALL rtl_uStringBuffer_makeStringAndClear( rtl_uString ** ppThis,
      62                 :            :                                                              sal_Int32 *nCapacity )
      63                 :            : {
      64                 :            :     // avoid an un-necessary atomic ref/unref pair
      65                 :   10478747 :     rtl_uString *pStr = *ppThis;
      66                 :   10478747 :     *ppThis = NULL;
      67                 :            : 
      68                 :   10478747 :     rtl_uString_new (ppThis);
      69                 :   10478747 :     *nCapacity = 0;
      70                 :            : 
      71                 :            :     RTL_LOG_STRING_NEW( pStr );
      72                 :            : 
      73                 :   10478747 :     return pStr;
      74                 :            : }
      75                 :            : 
      76                 :    1889902 : sal_Int32 SAL_CALL rtl_uStringbuffer_newFromStringBuffer( rtl_uString ** newStr,
      77                 :            :                                                           sal_Int32 capacity,
      78                 :            :                                                           rtl_uString * oldStr )
      79                 :            : {
      80                 :    1889902 :     sal_Int32 newCapacity = capacity;
      81                 :            : 
      82         [ -  + ]:    1889902 :     if (newCapacity < oldStr->length)
      83                 :          0 :         newCapacity = oldStr->length;
      84                 :            : 
      85                 :    1889902 :     rtl_uString_new_WithLength( newStr, newCapacity );
      86                 :            : 
      87         [ +  + ]:    1889902 :     if (oldStr->length > 0) {
      88                 :    1706731 :         (*newStr)->length = oldStr->length;
      89                 :    1706731 :         memcpy( (*newStr)->buffer, oldStr->buffer, oldStr->length * sizeof(sal_Unicode));
      90                 :            :     }
      91                 :            :     RTL_LOG_STRING_NEW( *newStr );
      92                 :    1889902 :     return newCapacity;
      93                 :            : }
      94                 :            : 
      95                 :    5027001 : void SAL_CALL rtl_uStringbuffer_ensureCapacity
      96                 :            :     (rtl_uString ** This, sal_Int32* capacity, sal_Int32 minimumCapacity)
      97                 :            : {
      98         [ +  + ]:    5027001 :     if (minimumCapacity > *capacity)
      99                 :            :     {
     100                 :    5026337 :         rtl_uString * pTmp = *This;
     101                 :    5026337 :         rtl_uString * pNew = NULL;
     102                 :    5026337 :         *capacity = ((*This)->length + 1) * 2;
     103         [ +  + ]:    5026337 :         if (minimumCapacity > *capacity)
     104                 :            :             /* still lower, set to the minimum capacity */
     105                 :    2928246 :             *capacity = minimumCapacity;
     106                 :            : 
     107                 :    5026337 :         rtl_uString_new_WithLength(&pNew, *capacity);
     108                 :    5026337 :         pNew->length = (*This)->length;
     109                 :    5026337 :         *This = pNew;
     110                 :            : 
     111                 :    5026337 :         memcpy( (*This)->buffer, pTmp->buffer, pTmp->length * sizeof(sal_Unicode) );
     112                 :            : 
     113                 :            :         RTL_LOG_STRING_NEW( pTmp ); // with accurate contents
     114                 :    5026337 :         rtl_uString_release( pTmp );
     115                 :            :     }
     116                 :    5027001 : }
     117                 :            : 
     118                 :  219142571 : void SAL_CALL rtl_uStringbuffer_insert( rtl_uString ** This,
     119                 :            :                                         sal_Int32 * capacity,
     120                 :            :                                         sal_Int32 offset,
     121                 :            :                                         const sal_Unicode * str,
     122                 :            :                                         sal_Int32 len)
     123                 :            : {
     124                 :            :     sal_Int32 nOldLen;
     125                 :            :     sal_Unicode * pBuf;
     126                 :            :     sal_Int32 n;
     127         [ +  + ]:  219142571 :     if( len != 0 )
     128                 :            :     {
     129         [ +  + ]:  218385618 :         if (*capacity < (*This)->length + len)
     130                 :    4351767 :             rtl_uStringbuffer_ensureCapacity( This, capacity, (*This)->length + len );
     131                 :            : 
     132                 :            :         /*
     133                 :            :         if( len == 1 )
     134                 :            :             This->buffer
     135                 :            :         */
     136                 :  218385632 :         nOldLen = (*This)->length;
     137                 :  218385632 :         pBuf = (*This)->buffer;
     138                 :            : 
     139                 :            :         /* copy the tail */
     140                 :  218385632 :         n = (nOldLen - offset);
     141         [ +  + ]:  218385632 :         if( n == 1 )
     142                 :            :                             /* optimized for 1 character */
     143                 :        817 :             pBuf[offset + len] = pBuf[offset];
     144         [ +  + ]:  218384815 :         else if( n > 1 )
     145                 :       1243 :             rtl_moveMemory( pBuf + offset + len, pBuf + offset, n * sizeof(sal_Unicode) );
     146                 :            : 
     147                 :            :         /* insert the new characters */
     148         [ +  + ]:  218385635 :         if( len == 1 )
     149                 :            :             /* optimized for 1 character */
     150                 :  209899347 :             pBuf[offset] = *str;
     151         [ +  - ]:    8486288 :         else if( len > 1 )
     152                 :    8486288 :             memcpy( pBuf + offset, str, len * sizeof(sal_Unicode) );
     153                 :  218385635 :         (*This)->length = nOldLen + len;
     154                 :  218385635 :         pBuf[ nOldLen + len ] = 0;
     155                 :            :     }
     156                 :  219142588 : }
     157                 :            : 
     158                 :         35 : void rtl_uStringbuffer_insertUtf32(
     159                 :            :     rtl_uString ** pThis, sal_Int32 * capacity, sal_Int32 offset, sal_uInt32 c)
     160                 :            :     SAL_THROW_EXTERN_C()
     161                 :            : {
     162                 :            :     sal_Unicode buf[2];
     163                 :            :     sal_Int32 len;
     164                 :            :     OSL_ASSERT(c <= 0x10FFFF && !(c >= 0xD800 && c <= 0xDFFF));
     165         [ +  + ]:         35 :     if (c <= 0xFFFF) {
     166                 :         25 :         buf[0] = (sal_Unicode) c;
     167                 :         25 :         len = 1;
     168                 :            :     } else {
     169                 :         10 :         c -= 0x10000;
     170                 :         10 :         buf[0] = (sal_Unicode) ((c >> 10) | 0xD800);
     171                 :         10 :         buf[1] = (sal_Unicode) ((c & 0x3FF) | 0xDC00);
     172                 :         10 :         len = 2;
     173                 :            :     }
     174         [ +  - ]:         35 :     rtl_uStringbuffer_insert(pThis, capacity, offset, buf, len);
     175                 :         35 : }
     176                 :            : 
     177                 :    3636408 : void SAL_CALL rtl_uStringbuffer_insert_ascii(   /*inout*/rtl_uString ** This,
     178                 :            :                                                 /*inout*/sal_Int32 * capacity,
     179                 :            :                                                 sal_Int32 offset,
     180                 :            :                                                 const sal_Char * str,
     181                 :            :                                                 sal_Int32 len)
     182                 :            : {
     183                 :            :     sal_Int32 nOldLen;
     184                 :            :     sal_Unicode * pBuf;
     185                 :            :     sal_Int32 n;
     186         [ +  + ]:    3636408 :     if( len != 0 )
     187                 :            :     {
     188         [ +  + ]:    3636404 :         if (*capacity < (*This)->length + len)
     189                 :      79687 :             rtl_uStringbuffer_ensureCapacity( This, capacity, (*This)->length + len );
     190                 :            : 
     191                 :    3636404 :         nOldLen = (*This)->length;
     192                 :    3636404 :         pBuf = (*This)->buffer;
     193                 :            : 
     194                 :            :         /* copy the tail */
     195                 :    3636404 :         n = (nOldLen - offset);
     196         [ -  + ]:    3636404 :         if( n == 1 )
     197                 :            :             /* optimized for 1 character */
     198                 :          0 :             pBuf[offset + len] = pBuf[offset];
     199         [ +  + ]:    3636404 :         else if( n > 1 )
     200                 :          5 :             rtl_moveMemory( pBuf + offset + len, pBuf + offset, n * sizeof(sal_Unicode) );
     201                 :            : 
     202                 :            :         /* insert the new characters */
     203         [ +  + ]:   25676991 :         for( n = 0; n < len; n++ )
     204                 :            :         {
     205                 :            :             /* Check ASCII range */
     206                 :            :             OSL_ENSURE( (*str & 0x80) == 0, "Found ASCII char > 127");
     207                 :            : 
     208                 :   22040587 :             pBuf[offset + n] = (sal_Unicode)*(str++);
     209                 :            :         }
     210                 :            : 
     211                 :    3636404 :         (*This)->length = nOldLen + len;
     212                 :    3636404 :         pBuf[ nOldLen + len ] = 0;
     213                 :            :     }
     214                 :    3636408 : }
     215                 :            : 
     216                 :            : /*************************************************************************
     217                 :            :  *  rtl_uStringbuffer_remove
     218                 :            :  */
     219                 :         50 : void SAL_CALL rtl_uStringbuffer_remove( rtl_uString ** This,
     220                 :            :                                        sal_Int32 start,
     221                 :            :                                        sal_Int32 len )
     222                 :            : {
     223                 :            :     sal_Int32 nTailLen;
     224                 :            :     sal_Unicode * pBuf;
     225                 :            : 
     226         [ -  + ]:         50 :     if (len > (*This)->length - start)
     227                 :          0 :         len = (*This)->length - start;
     228                 :            : 
     229                 :            :     //remove nothing
     230         [ -  + ]:         50 :     if (!len)
     231                 :         50 :         return;
     232                 :            : 
     233                 :         50 :     pBuf = (*This)->buffer;
     234                 :         50 :     nTailLen = (*This)->length - ( start + len );
     235                 :            : 
     236         [ +  + ]:         50 :     if (nTailLen)
     237                 :            :     {
     238                 :            :         /* move the tail */
     239                 :         10 :         rtl_moveMemory(pBuf + start, pBuf + start + len, nTailLen * sizeof(sal_Unicode));
     240                 :            :     }
     241                 :            : 
     242                 :         50 :     (*This)->length-=len;
     243                 :         50 :     pBuf[ (*This)->length ] = 0;
     244                 :            : }
     245                 :            : 
     246                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10