LCOV - code coverage report
Current view: top level - sal/textenc - textcvt.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 20 91 22.0 %
Date: 2014-04-14 Functions: 6 14 42.9 %
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           0 : 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           0 :     if ( ((nFlags & RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_MASK) == RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR) ||
      38           0 :          ((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           0 :     *pInfo = 0;
      47           0 :     pEndDestBuf = pDestBuf+nDestChars;
      48           0 :     pEndSrcBuf  = pSrcBuf+nSrcBytes;
      49           0 :     while ( pSrcBuf < pEndSrcBuf )
      50             :     {
      51           0 :         if ( pDestBuf == pEndDestBuf )
      52             :         {
      53           0 :             *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR | RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL;
      54           0 :             break;
      55             :         }
      56             : 
      57           0 :         *pDestBuf = (sal_Unicode)(unsigned char)*pSrcBuf;
      58           0 :         pDestBuf++;
      59           0 :         pSrcBuf++;
      60             :     }
      61             : 
      62           0 :     *pSrcCvtBytes = nSrcBytes - (pEndSrcBuf-pSrcBuf);
      63           0 :     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)(unsigned char)(*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       85156 : rtl_TextToUnicodeConverter SAL_CALL rtl_createTextToUnicodeConverter( rtl_TextEncoding eTextEncoding )
     106             : {
     107       85156 :     const ImplTextEncodingData* pData = Impl_getTextEncodingData( eTextEncoding );
     108       85156 :     if ( pData )
     109       85156 :         return (rtl_TextToUnicodeConverter) &pData->maConverter;
     110             :     else
     111           0 :         return 0;
     112             : }
     113             : 
     114             : /* ----------------------------------------------------------------------- */
     115             : 
     116       85156 : void SAL_CALL rtl_destroyTextToUnicodeConverter(
     117             :     SAL_UNUSED_PARAMETER rtl_TextToUnicodeConverter )
     118       85156 : {}
     119             : 
     120             : /* ----------------------------------------------------------------------- */
     121             : 
     122           0 : rtl_TextToUnicodeContext SAL_CALL rtl_createTextToUnicodeContext( rtl_TextToUnicodeConverter hConverter )
     123             : {
     124           0 :     const ImplTextConverter* pConverter = (const ImplTextConverter*)hConverter;
     125           0 :     if ( !pConverter )
     126           0 :         return 0;
     127           0 :     else if ( pConverter->mpCreateTextToUnicodeContext )
     128           0 :         return (rtl_TextToUnicodeContext)pConverter->mpCreateTextToUnicodeContext();
     129             :     else
     130           0 :         return (rtl_TextToUnicodeContext)1;
     131             : }
     132             : 
     133             : /* ----------------------------------------------------------------------- */
     134             : 
     135           0 : void SAL_CALL rtl_destroyTextToUnicodeContext( rtl_TextToUnicodeConverter hConverter,
     136             :                                                rtl_TextToUnicodeContext hContext )
     137             : {
     138           0 :     const ImplTextConverter* pConverter = (const ImplTextConverter*)hConverter;
     139           0 :     if ( pConverter && hContext && pConverter->mpDestroyTextToUnicodeContext )
     140           0 :         pConverter->mpDestroyTextToUnicodeContext( hContext );
     141           0 : }
     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     1147855 : 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     1147855 :     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     1147855 :     if ( !pConverter )
     167             :     {
     168             :         return ImplDummyToUnicode( pSrcBuf, nSrcBytes,
     169             :                                    pDestBuf, nDestChars,
     170           0 :                                    nFlags, pInfo, pSrcCvtBytes );
     171             :     }
     172             : 
     173             :     return pConverter->mpConvertTextToUnicodeProc( pConverter->mpConvertData,
     174             :                                                    hContext,
     175             :                                                    pSrcBuf, nSrcBytes,
     176             :                                                    pDestBuf, nDestChars,
     177             :                                                    nFlags, pInfo,
     178     1147855 :                                                    pSrcCvtBytes );
     179             : }
     180             : 
     181             : /* ======================================================================= */
     182             : 
     183      340048 : rtl_UnicodeToTextConverter SAL_CALL rtl_createUnicodeToTextConverter( rtl_TextEncoding eTextEncoding )
     184             : {
     185      340048 :     const ImplTextEncodingData* pData = Impl_getTextEncodingData( eTextEncoding );
     186      340048 :     if ( pData )
     187      340048 :         return (rtl_TextToUnicodeConverter) &pData->maConverter;
     188             :     else
     189           0 :         return 0;
     190             : }
     191             : 
     192             : /* ----------------------------------------------------------------------- */
     193             : 
     194      340048 : void SAL_CALL rtl_destroyUnicodeToTextConverter(
     195             :     SAL_UNUSED_PARAMETER rtl_UnicodeToTextConverter )
     196      340048 : {}
     197             : 
     198             : /* ----------------------------------------------------------------------- */
     199             : 
     200           0 : rtl_UnicodeToTextContext SAL_CALL rtl_createUnicodeToTextContext( rtl_UnicodeToTextConverter hConverter )
     201             : {
     202           0 :     const ImplTextConverter* pConverter = (const ImplTextConverter*)hConverter;
     203           0 :     if ( !pConverter )
     204           0 :         return 0;
     205           0 :     else if ( pConverter->mpCreateUnicodeToTextContext )
     206           0 :         return (rtl_UnicodeToTextContext)pConverter->mpCreateUnicodeToTextContext();
     207             :     else
     208           0 :         return (rtl_UnicodeToTextContext)1;
     209             : }
     210             : 
     211             : /* ----------------------------------------------------------------------- */
     212             : 
     213           0 : void SAL_CALL rtl_destroyUnicodeToTextContext( rtl_UnicodeToTextConverter hConverter,
     214             :                                                rtl_UnicodeToTextContext hContext )
     215             : {
     216           0 :     const ImplTextConverter* pConverter = (const ImplTextConverter*)hConverter;
     217           0 :     if ( pConverter && hContext && pConverter->mpDestroyUnicodeToTextContext )
     218           0 :         pConverter->mpDestroyUnicodeToTextContext( hContext );
     219           0 : }
     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     1785415 : 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     1785415 :     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     1785415 :     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     1785415 :                                                    pSrcCvtChars );
     257             : }
     258             : 
     259             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10