LCOV - code coverage report
Current view: top level - libreoffice/sal/textenc - textcvt.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 56 90 62.2 %
Date: 2012-12-27 Functions: 11 14 78.6 %
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             : #include "sal/config.h"
      21             : 
      22             : #include "rtl/textcvt.h"
      23             : 
      24             : #include "gettextencodingdata.hxx"
      25             : #include "tenchelp.hxx"
      26             : 
      27             : /* ======================================================================= */
      28             : 
      29         161 : static sal_Size ImplDummyToUnicode( const char* pSrcBuf, sal_Size nSrcBytes,
      30             :                                     sal_Unicode* pDestBuf, sal_Size nDestChars,
      31             :                                     sal_uInt32 nFlags, sal_uInt32* pInfo,
      32             :                                     sal_Size* pSrcCvtBytes )
      33             : {
      34             :     sal_Unicode*        pEndDestBuf;
      35             :     const char*     pEndSrcBuf;
      36             : 
      37         161 :     if ( ((nFlags & RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_MASK) == RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR) ||
      38             :          ((nFlags & RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_MASK) == RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR) )
      39             :     {
      40             :         *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR |
      41             :                   RTL_TEXTTOUNICODE_INFO_UNDEFINED |
      42           0 :                   RTL_TEXTTOUNICODE_INFO_MBUNDEFINED;
      43           0 :         return 0;
      44             :     }
      45             : 
      46         161 :     *pInfo = 0;
      47         161 :     pEndDestBuf = pDestBuf+nDestChars;
      48         161 :     pEndSrcBuf  = pSrcBuf+nSrcBytes;
      49        6528 :     while ( pSrcBuf < pEndSrcBuf )
      50             :     {
      51        6206 :         if ( pDestBuf == pEndDestBuf )
      52             :         {
      53           0 :             *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR | RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL;
      54           0 :             break;
      55             :         }
      56             : 
      57        6206 :         *pDestBuf = (sal_Unicode)(sal_uChar)*pSrcBuf;
      58        6206 :         pDestBuf++;
      59        6206 :         pSrcBuf++;
      60             :     }
      61             : 
      62         161 :     *pSrcCvtBytes = nSrcBytes - (pEndSrcBuf-pSrcBuf);
      63         161 :     return (nDestChars - (pEndDestBuf-pDestBuf));
      64             : }
      65             : 
      66             : /* ----------------------------------------------------------------------- */
      67             : 
      68           0 : static sal_Size ImplUnicodeToDummy( const sal_Unicode* pSrcBuf, sal_Size nSrcChars,
      69             :                                     char* pDestBuf, sal_Size nDestBytes,
      70             :                                     sal_uInt32 nFlags, sal_uInt32* pInfo,
      71             :                                     sal_Size* pSrcCvtChars )
      72             : {
      73             :     char*               pEndDestBuf;
      74             :     const sal_Unicode*      pEndSrcBuf;
      75             : 
      76           0 :     if ( ((nFlags & RTL_UNICODETOTEXT_FLAGS_UNDEFINED_MASK) == RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR) )
      77             :     {
      78             :         *pInfo |= RTL_UNICODETOTEXT_INFO_ERROR |
      79           0 :                   RTL_UNICODETOTEXT_INFO_UNDEFINED;
      80           0 :         return 0;
      81             :     }
      82             : 
      83           0 :     *pInfo = 0;
      84           0 :     pEndDestBuf = pDestBuf+nDestBytes;
      85           0 :     pEndSrcBuf  = pSrcBuf+nSrcChars;
      86           0 :     while ( pSrcBuf < pEndSrcBuf )
      87             :     {
      88           0 :         if ( pDestBuf == pEndDestBuf )
      89             :         {
      90           0 :             *pInfo |= RTL_UNICODETOTEXT_INFO_ERROR | RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL;
      91           0 :             break;
      92             :         }
      93             : 
      94           0 :         *pDestBuf = (char)(sal_uChar)(*pSrcBuf & 0x00FF);
      95           0 :         pDestBuf++;
      96           0 :         pSrcBuf++;
      97             :     }
      98             : 
      99           0 :     *pSrcCvtChars = nSrcChars - (pEndSrcBuf-pSrcBuf);
     100           0 :     return (nDestBytes - (pEndDestBuf-pDestBuf));
     101             : }
     102             : 
     103             : /* ======================================================================= */
     104             : 
     105      845849 : rtl_TextToUnicodeConverter SAL_CALL rtl_createTextToUnicodeConverter( rtl_TextEncoding eTextEncoding )
     106             : {
     107      845849 :     const ImplTextEncodingData* pData = Impl_getTextEncodingData( eTextEncoding );
     108      845849 :     if ( pData )
     109      845688 :         return (rtl_TextToUnicodeConverter) &pData->maConverter;
     110             :     else
     111         161 :         return 0;
     112             : }
     113             : 
     114             : /* ----------------------------------------------------------------------- */
     115             : 
     116     1464724 : void SAL_CALL rtl_destroyTextToUnicodeConverter(
     117             :     SAL_UNUSED_PARAMETER rtl_TextToUnicodeConverter )
     118     1464724 : {}
     119             : 
     120             : /* ----------------------------------------------------------------------- */
     121             : 
     122         642 : rtl_TextToUnicodeContext SAL_CALL rtl_createTextToUnicodeContext( rtl_TextToUnicodeConverter hConverter )
     123             : {
     124         642 :     const ImplTextConverter* pConverter = (const ImplTextConverter*)hConverter;
     125         642 :     if ( !pConverter )
     126           0 :         return 0;
     127         642 :     else if ( pConverter->mpCreateTextToUnicodeContext )
     128          72 :         return (rtl_TextToUnicodeContext)pConverter->mpCreateTextToUnicodeContext();
     129             :     else
     130         570 :         return (rtl_TextToUnicodeContext)1;
     131             : }
     132             : 
     133             : /* ----------------------------------------------------------------------- */
     134             : 
     135         622 : void SAL_CALL rtl_destroyTextToUnicodeContext( rtl_TextToUnicodeConverter hConverter,
     136             :                                                rtl_TextToUnicodeContext hContext )
     137             : {
     138         622 :     const ImplTextConverter* pConverter = (const ImplTextConverter*)hConverter;
     139         622 :     if ( pConverter && hContext && pConverter->mpDestroyTextToUnicodeContext )
     140          72 :         pConverter->mpDestroyTextToUnicodeContext( hContext );
     141         622 : }
     142             : 
     143             : /* ----------------------------------------------------------------------- */
     144             : 
     145           0 : void SAL_CALL rtl_resetTextToUnicodeContext( rtl_TextToUnicodeConverter hConverter,
     146             :                                              rtl_TextToUnicodeContext hContext )
     147             : {
     148           0 :     const ImplTextConverter* pConverter = (const ImplTextConverter*)hConverter;
     149           0 :     if ( pConverter && hContext && pConverter->mpResetTextToUnicodeContext )
     150           0 :         pConverter->mpResetTextToUnicodeContext( hContext );
     151           0 : }
     152             : 
     153             : /* ----------------------------------------------------------------------- */
     154             : 
     155     1335063 : sal_Size SAL_CALL rtl_convertTextToUnicode( rtl_TextToUnicodeConverter hConverter,
     156             :                                             rtl_TextToUnicodeContext hContext,
     157             :                                             const char* pSrcBuf, sal_Size nSrcBytes,
     158             :                                             sal_Unicode* pDestBuf, sal_Size nDestChars,
     159             :                                             sal_uInt32 nFlags, sal_uInt32* pInfo,
     160             :                                             sal_Size* pSrcCvtBytes )
     161             : {
     162     1335063 :     const ImplTextConverter* pConverter = (const ImplTextConverter*)hConverter;
     163             : 
     164             :     /* Only temporaer, because we don't want die, if we don't have a
     165             :        converter, because not all converters are implemented yet */
     166     1335063 :     if ( !pConverter )
     167             :     {
     168             :         return ImplDummyToUnicode( pSrcBuf, nSrcBytes,
     169             :                                    pDestBuf, nDestChars,
     170         161 :                                    nFlags, pInfo, pSrcCvtBytes );
     171             :     }
     172             : 
     173             :     return pConverter->mpConvertTextToUnicodeProc( pConverter->mpConvertData,
     174             :                                                    hContext,
     175             :                                                    pSrcBuf, nSrcBytes,
     176             :                                                    pDestBuf, nDestChars,
     177             :                                                    nFlags, pInfo,
     178     1334902 :                                                    pSrcCvtBytes );
     179             : }
     180             : 
     181             : /* ======================================================================= */
     182             : 
     183      155701 : rtl_UnicodeToTextConverter SAL_CALL rtl_createUnicodeToTextConverter( rtl_TextEncoding eTextEncoding )
     184             : {
     185      155701 :     const ImplTextEncodingData* pData = Impl_getTextEncodingData( eTextEncoding );
     186      155701 :     if ( pData )
     187      155701 :         return (rtl_TextToUnicodeConverter) &pData->maConverter;
     188             :     else
     189           0 :         return 0;
     190             : }
     191             : 
     192             : /* ----------------------------------------------------------------------- */
     193             : 
     194      119910 : void SAL_CALL rtl_destroyUnicodeToTextConverter(
     195             :     SAL_UNUSED_PARAMETER rtl_UnicodeToTextConverter )
     196      119910 : {}
     197             : 
     198             : /* ----------------------------------------------------------------------- */
     199             : 
     200         105 : rtl_UnicodeToTextContext SAL_CALL rtl_createUnicodeToTextContext( rtl_UnicodeToTextConverter hConverter )
     201             : {
     202         105 :     const ImplTextConverter* pConverter = (const ImplTextConverter*)hConverter;
     203         105 :     if ( !pConverter )
     204           0 :         return 0;
     205         105 :     else if ( pConverter->mpCreateUnicodeToTextContext )
     206          36 :         return (rtl_UnicodeToTextContext)pConverter->mpCreateUnicodeToTextContext();
     207             :     else
     208          69 :         return (rtl_UnicodeToTextContext)1;
     209             : }
     210             : 
     211             : /* ----------------------------------------------------------------------- */
     212             : 
     213         125 : void SAL_CALL rtl_destroyUnicodeToTextContext( rtl_UnicodeToTextConverter hConverter,
     214             :                                                rtl_UnicodeToTextContext hContext )
     215             : {
     216         125 :     const ImplTextConverter* pConverter = (const ImplTextConverter*)hConverter;
     217         125 :     if ( pConverter && hContext && pConverter->mpDestroyUnicodeToTextContext )
     218          36 :         pConverter->mpDestroyUnicodeToTextContext( hContext );
     219         125 : }
     220             : 
     221             : /* ----------------------------------------------------------------------- */
     222             : 
     223           0 : void SAL_CALL rtl_resetUnicodeToTextContext( rtl_UnicodeToTextConverter hConverter,
     224             :                                              rtl_UnicodeToTextContext hContext )
     225             : {
     226           0 :     const ImplTextConverter* pConverter = (const ImplTextConverter*)hConverter;
     227           0 :     if ( pConverter && hContext && pConverter->mpResetUnicodeToTextContext )
     228           0 :         pConverter->mpResetUnicodeToTextContext( hContext );
     229           0 : }
     230             : 
     231             : /* ----------------------------------------------------------------------- */
     232             : 
     233     1174540 : sal_Size SAL_CALL rtl_convertUnicodeToText( rtl_UnicodeToTextConverter hConverter,
     234             :                                             rtl_UnicodeToTextContext hContext,
     235             :                                             const sal_Unicode* pSrcBuf, sal_Size nSrcChars,
     236             :                                             char* pDestBuf, sal_Size nDestBytes,
     237             :                                             sal_uInt32 nFlags, sal_uInt32* pInfo,
     238             :                                             sal_Size* pSrcCvtChars )
     239             : {
     240     1174540 :     const ImplTextConverter* pConverter = (const ImplTextConverter*)hConverter;
     241             : 
     242             :     /* Only temporaer, because we don't want die, if we don't have a
     243             :        converter, because not all converters are implemented yet */
     244     1174540 :     if ( !pConverter )
     245             :     {
     246             :         return ImplUnicodeToDummy( pSrcBuf, nSrcChars,
     247             :                                    pDestBuf, nDestBytes,
     248           0 :                                    nFlags, pInfo, pSrcCvtChars );
     249             :     }
     250             : 
     251             :     return pConverter->mpConvertUnicodeToTextProc( pConverter->mpConvertData,
     252             :                                                    hContext,
     253             :                                                    pSrcBuf, nSrcChars,
     254             :                                                    pDestBuf, nDestBytes,
     255             :                                                    nFlags, pInfo,
     256     1174540 :                                                    pSrcCvtChars );
     257             : }
     258             : 
     259             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10