LCOV - code coverage report
Current view: top level - sal/textenc - converter.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 28 49 57.1 %
Date: 2015-06-13 12:38:46 Functions: 2 2 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             : #include "sal/config.h"
      21             : 
      22             : #include "rtl/textcvt.h"
      23             : #include "sal/types.h"
      24             : 
      25             : #include "converter.hxx"
      26             : #include "tenchelp.hxx"
      27             : #include "unichars.hxx"
      28             : 
      29             : sal::detail::textenc::BadInputConversionAction
      30       27078 : sal::detail::textenc::handleBadInputTextToUnicodeConversion(
      31             :     bool bUndefined, bool bMultiByte, char cByte, sal_uInt32 nFlags,
      32             :     sal_Unicode ** pDestBufPtr, sal_Unicode * pDestBufEnd, sal_uInt32 * pInfo)
      33             : {
      34             :     *pInfo |= bUndefined
      35             :         ? (bMultiByte
      36             :            ? RTL_TEXTTOUNICODE_INFO_MBUNDEFINED
      37             :            : RTL_TEXTTOUNICODE_INFO_UNDEFINED)
      38       27078 :         : RTL_TEXTTOUNICODE_INFO_INVALID;
      39       27078 :     switch (nFlags
      40       27078 :             & (bUndefined
      41             :                ? (bMultiByte
      42             :                   ? RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_MASK
      43             :                   : RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_MASK)
      44             :                : RTL_TEXTTOUNICODE_FLAGS_INVALID_MASK))
      45             :     {
      46             :     case RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR:
      47             :     case RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR:
      48             :     case RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR:
      49         262 :         *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR;
      50         262 :         return BAD_INPUT_STOP;
      51             : 
      52             :     case RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_IGNORE:
      53             :     case RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_IGNORE:
      54             :     case RTL_TEXTTOUNICODE_FLAGS_INVALID_IGNORE:
      55           0 :         return BAD_INPUT_CONTINUE;
      56             : 
      57             :     case RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_MAPTOPRIVATE:
      58           0 :         if (*pDestBufPtr != pDestBufEnd)
      59             :         {
      60             :             *(*pDestBufPtr)++ = RTL_TEXTCVT_BYTE_PRIVATE_START
      61           0 :                 | ((unsigned char) cByte);
      62           0 :             return BAD_INPUT_CONTINUE;
      63             :         }
      64             :         else
      65           0 :             return BAD_INPUT_NO_OUTPUT;
      66             : 
      67             :     default: // RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_DEFAULT,
      68             :              // RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_DEFAULT,
      69             :              // RTL_TEXTTOUNICODE_FLAGS_INVALID_DEFAULT
      70       26816 :         if (*pDestBufPtr != pDestBufEnd)
      71             :         {
      72       26760 :             *(*pDestBufPtr)++ = RTL_TEXTENC_UNICODE_REPLACEMENT_CHARACTER;
      73       26760 :             return BAD_INPUT_CONTINUE;
      74             :         }
      75             :         else
      76          56 :             return BAD_INPUT_NO_OUTPUT;
      77             :     }
      78             : }
      79             : 
      80             : sal::detail::textenc::BadInputConversionAction
      81           6 : sal::detail::textenc::handleBadInputUnicodeToTextConversion(
      82             :     bool bUndefined, sal_uInt32 nUtf32, sal_uInt32 nFlags, char ** pDestBufPtr,
      83             :     char * pDestBufEnd, sal_uInt32 * pInfo, char const * pPrefix,
      84             :     sal_Size nPrefixLen, bool * pPrefixWritten)
      85             : {
      86             :     // TODO! RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACE
      87             :     // RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACESTR
      88             : 
      89             :     char cReplace;
      90             : 
      91           6 :     if (bUndefined)
      92             :     {
      93           4 :         if (ImplIsControlOrFormat(nUtf32))
      94             :         {
      95           0 :             if ((nFlags & RTL_UNICODETOTEXT_FLAGS_CONTROL_IGNORE) != 0)
      96           0 :                 nFlags = RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE;
      97             :         }
      98           4 :         else if (ImplIsPrivateUse(nUtf32))
      99             :         {
     100           0 :             if ((nFlags & RTL_UNICODETOTEXT_FLAGS_PRIVATE_IGNORE) != 0)
     101           0 :                 nFlags = RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE;
     102           0 :             else if ((nFlags & RTL_UNICODETOTEXT_FLAGS_PRIVATE_MAPTO0) != 0)
     103           0 :                 nFlags = RTL_UNICODETOTEXT_FLAGS_UNDEFINED_0;
     104             :         }
     105           4 :         else if (ImplIsZeroWidth(nUtf32))
     106             :         {
     107           0 :             if ((nFlags & RTL_UNICODETOTEXT_FLAGS_NONSPACING_IGNORE) != 0)
     108           0 :                 nFlags = RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE;
     109             :         }
     110             :     }
     111             :     *pInfo |= bUndefined ? RTL_UNICODETOTEXT_INFO_UNDEFINED :
     112           6 :                            RTL_UNICODETOTEXT_INFO_INVALID;
     113           6 :     switch (nFlags & (bUndefined ? RTL_UNICODETOTEXT_FLAGS_UNDEFINED_MASK :
     114             :                                    RTL_UNICODETOTEXT_FLAGS_INVALID_MASK))
     115             :     {
     116             :     case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR:
     117             :     case RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR:
     118           2 :         *pInfo |= RTL_UNICODETOTEXT_INFO_ERROR;
     119           2 :         return BAD_INPUT_STOP;
     120             : 
     121             :     case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE:
     122             :     case RTL_UNICODETOTEXT_FLAGS_INVALID_IGNORE:
     123           0 :         if (pPrefixWritten)
     124           0 :             *pPrefixWritten = false;
     125           0 :         return BAD_INPUT_CONTINUE;
     126             : 
     127             :     case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_0:
     128             :     case RTL_UNICODETOTEXT_FLAGS_INVALID_0:
     129           0 :         cReplace = 0;
     130           0 :         break;
     131             : 
     132             :     case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_QUESTIONMARK:
     133             :     case RTL_UNICODETOTEXT_FLAGS_INVALID_QUESTIONMARK:
     134             :     default: // RTL_UNICODETOTEXT_FLAGS_UNDEFINED_DEFAULT,
     135             :              // RTL_UNICODETOTEXT_FLAGS_INVALID_DEFAULT
     136           4 :         cReplace = '?';
     137           4 :         break;
     138             : 
     139             :     case RTL_UNICODETOTEXT_FLAGS_UNDEFINED_UNDERLINE:
     140             :     case RTL_UNICODETOTEXT_FLAGS_INVALID_UNDERLINE:
     141           0 :         cReplace = '_';
     142           0 :         break;
     143             :     }
     144           4 :     if ((sal_Size) (pDestBufEnd - *pDestBufPtr) > nPrefixLen)
     145             :     {
     146          14 :         while (nPrefixLen-- > 0)
     147           6 :             *(*pDestBufPtr)++ = *pPrefix++;
     148           4 :         *(*pDestBufPtr)++ = cReplace;
     149           4 :         if (pPrefixWritten)
     150           2 :             *pPrefixWritten = true;
     151           4 :         return BAD_INPUT_CONTINUE;
     152             :     }
     153             :     else
     154           0 :         return BAD_INPUT_NO_OUTPUT;
     155             : }
     156             : 
     157             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11