LCOV - code coverage report
Current view: top level - libreoffice/tools/source/string - strucvt.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 44 53 83.0 %
Date: 2012-12-27 Functions: 6 6 100.0 %
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       19399 : UniString::UniString( const char* pByteStr,
      21             :                       rtl_TextEncoding eTextEncoding, sal_uInt32 nCvtFlags )
      22             : {
      23             :     DBG_CTOR( UniString, DbgCheckUniString );
      24             :     DBG_ASSERT( pByteStr, "UniString::UniString() - pByteStr is NULL" );
      25             : 
      26       19399 :     mpData = NULL;
      27             :     rtl_string2UString( (rtl_uString **)(&mpData),
      28       19399 :                         pByteStr, ImplStringLen( pByteStr ),
      29       38798 :                         eTextEncoding, nCvtFlags );
      30       19399 : }
      31             : 
      32       34542 : UniString::UniString( const char* pByteStr, xub_StrLen nLen,
      33             :                       rtl_TextEncoding eTextEncoding, sal_uInt32 nCvtFlags )
      34             : {
      35             :     DBG_CTOR( UniString, DbgCheckUniString );
      36             :     DBG_ASSERT( pByteStr, "UniString::UniString() - pByteStr is NULL" );
      37             : 
      38       34542 :     if ( nLen == STRING_LEN )
      39           0 :         nLen = ImplStringLen( pByteStr );
      40             : 
      41       34542 :     mpData = NULL;
      42             :     rtl_string2UString( (rtl_uString **)(&mpData),
      43             :                         pByteStr, nLen,
      44       34542 :                         eTextEncoding, nCvtFlags );
      45       34542 : }
      46             : 
      47     2167646 : UniString::UniString( const rtl::OUString& rStr )
      48     2167646 :     : mpData(NULL)
      49             : {
      50             :     DBG_CTOR( UniString, DbgCheckUniString );
      51             : 
      52             :     OSL_ENSURE(rStr.pData->length < STRING_MAXLEN,
      53             :                "Overflowing rtl::OUString -> UniString cut to zero length");
      54             : 
      55             : 
      56     2167646 :     if (rStr.pData->length < STRING_MAXLEN)
      57             :     {
      58     2167646 :         mpData = reinterpret_cast< UniStringData * >(const_cast< rtl::OUString & >(rStr).pData);
      59     2167646 :         STRING_ACQUIRE((STRING_TYPE *)mpData);
      60             :     }
      61             :     else
      62             :     {
      63           0 :         STRING_NEW((STRING_TYPE **)&mpData);
      64             :     }
      65     2167646 : }
      66             : 
      67      368644 : UniString& UniString::Assign( const rtl::OUString& rStr )
      68             : {
      69             :     DBG_CHKTHIS( UniString, DbgCheckUniString );
      70             : 
      71             :     OSL_ENSURE(rStr.pData->length < STRING_MAXLEN,
      72             :                "Overflowing rtl::OUString -> UniString cut to zero length");
      73             : 
      74      368644 :     if (rStr.pData->length < STRING_MAXLEN)
      75             :     {
      76      368644 :         if( mpData != NULL )
      77      368643 :             STRING_RELEASE((STRING_TYPE *)mpData);
      78      368644 :         mpData = reinterpret_cast< UniStringData * >(const_cast< rtl::OUString & >(rStr).pData);
      79      368644 :         STRING_ACQUIRE((STRING_TYPE *)mpData);
      80             :     }
      81             :     else
      82             :     {
      83           0 :         STRING_NEW((STRING_TYPE **)&mpData);
      84             :     }
      85             : 
      86      368644 :     return *this;
      87             : }
      88             : 
      89             : #include <rtl/ustrbuf.hxx>
      90             : #include <tools/rc.hxx>
      91             : #include <tools/rcid.h>
      92             : 
      93       55130 : UniString::UniString( const ResId& rResId )
      94       55130 :     : mpData(NULL)
      95             : {
      96       55130 :     rtl::OUString sStr(rResId.toString());
      97             : 
      98             :     DBG_CTOR( UniString, DbgCheckUniString );
      99             : 
     100             :     OSL_ENSURE(sStr.pData->length < STRING_MAXLEN,
     101             :                "Overflowing rtl::OUString -> UniString cut to zero length");
     102             : 
     103       55130 :     if (sStr.pData->length < STRING_MAXLEN)
     104             :     {
     105       55130 :         mpData = reinterpret_cast< UniStringData * >(sStr.pData);
     106       55130 :         STRING_ACQUIRE((STRING_TYPE *)mpData);
     107             :     }
     108             :     else
     109             :     {
     110           0 :         STRING_NEW((STRING_TYPE **)&mpData);
     111       55130 :     }
     112       55130 : }
     113             : 
     114      133692 : rtl::OUString ResId::toString() const
     115             : {
     116      133692 :     SetRT( RSC_STRING );
     117      133692 :     ResMgr* pResMgr = GetResMgr();
     118             : 
     119      133692 :     if ( !pResMgr || !pResMgr->GetResource( *this ) )
     120             :     {
     121           0 :         rtl::OUString sRet;
     122             : 
     123             : #if OSL_DEBUG_LEVEL > 0
     124             :         sRet = rtl::OUStringBuffer().
     125             :             appendAscii(RTL_CONSTASCII_STRINGPARAM("<resource id ")).
     126             :             append(static_cast<sal_Int32>(GetId())).
     127             :             appendAscii(RTL_CONSTASCII_STRINGPARAM(" not found>")).
     128             :             makeStringAndClear();
     129             : #endif
     130             : 
     131           0 :         if( pResMgr )
     132           0 :             pResMgr->PopContext();
     133             : 
     134           0 :         return sRet;
     135             :     }
     136             : 
     137             :     // String loading
     138      133692 :     RSHEADER_TYPE * pResHdr = (RSHEADER_TYPE*)pResMgr->GetClass();
     139             : 
     140      133692 :     sal_Int32 nStringLen = rtl_str_getLength( (char*)(pResHdr+1) );
     141      133692 :     rtl::OUString sRet((const char*)(pResHdr+1), nStringLen, RTL_TEXTENCODING_UTF8);
     142             : 
     143             :     sal_uInt32 nSize = sizeof( RSHEADER_TYPE )
     144      133692 :         + sal::static_int_cast< sal_uInt32 >(nStringLen) + 1;
     145      133692 :     nSize += nSize % 2;
     146      133692 :     pResMgr->Increment( nSize );
     147             : 
     148      133692 :     ResHookProc pImplResHookProc = ResMgr::GetReadStringHook();
     149      133692 :     if ( pImplResHookProc )
     150           0 :         sRet = pImplResHookProc(sRet);
     151      133692 :     return sRet;
     152             : }
     153             : 
     154             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10