LCOV - code coverage report
Current view: top level - rsc/source/tools - rscchar.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 48 75 64.0 %
Date: 2012-08-25 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 31 68 45.6 %

           Branch data     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                 :            : /****************** I N C L U D E S **************************************/
      21                 :            : #include <stdio.h>
      22                 :            : #include <string.h>
      23                 :            : #include <ctype.h>
      24                 :            : 
      25                 :            : // Solar Definitionen
      26                 :            : #include <tools/solar.h>
      27                 :            : #include <rsctools.hxx>
      28                 :            : 
      29                 :            : #include <rtl/textcvt.h>
      30                 :            : #include <rtl/textenc.h>
      31                 :            : #include <rtl/alloc.h>
      32                 :            : 
      33                 :            : /*************************************************************************
      34                 :            : |*
      35                 :            : |*    RscChar::MakeChar()
      36                 :            : |*
      37                 :            : |*    Beschreibung      Der String wird nach C-Konvention umgesetzt
      38                 :            : |*
      39                 :            : *************************************************************************/
      40                 :      73494 : char * RscChar::MakeUTF8( char * pStr, sal_uInt16 nTextEncoding )
      41                 :            : {
      42                 :      73494 :     sal_Size nMaxUniCodeBuf = strlen( pStr ) + 1;
      43         [ -  + ]:      73494 :     if( nMaxUniCodeBuf * 6 > 0x0FFFFF )
      44         [ #  # ]:          0 :         RscExit( 10 );
      45                 :            : 
      46         [ +  - ]:      73494 :     char *          pOrgStr = new char[ nMaxUniCodeBuf ];
      47                 :      73494 :     sal_uInt32      nOrgLen = 0;
      48                 :            : 
      49                 :      73494 :     char cOld = '1';
      50         [ +  + ]:    1758626 :     while( cOld != 0 )
      51                 :            :     {
      52                 :            :         char c;
      53                 :            : 
      54         [ +  + ]:    1685132 :         if( *pStr == '\\' )
      55                 :            :         {
      56                 :       1988 :             ++pStr;
      57   [ -  +  -  +  :       1988 :             switch( *pStr )
          -  +  -  +  -  
                +  +  + ]
      58                 :            :             {
      59                 :            :                 case 'a':
      60                 :          0 :                     c = '\a';
      61                 :          0 :                     break;
      62                 :            :                 case 'b':
      63                 :          2 :                     c = '\b';
      64                 :          2 :                     break;
      65                 :            :                 case 'f':
      66                 :          0 :                     c = '\f';
      67                 :          0 :                     break;
      68                 :            :                 case 'n':
      69                 :       1144 :                     c = '\n';
      70                 :       1144 :                     break;
      71                 :            :                 case 'r':
      72                 :          0 :                     c = '\r';
      73                 :          0 :                     break;
      74                 :            :                 case 't':
      75                 :        114 :                     c = '\t';
      76                 :        114 :                     break;
      77                 :            :                 case 'v':
      78                 :          0 :                     c = '\v';
      79                 :          0 :                     break;
      80                 :            :                 case '\\':
      81                 :         10 :                     c = '\\';
      82                 :         10 :                     break;
      83                 :            :                 case '?':
      84                 :          0 :                     c = '\?';
      85                 :          0 :                     break;
      86                 :            :                 case '\'':
      87                 :        160 :                     c = '\'';
      88                 :        160 :                     break;
      89                 :            :                 case '\"':
      90                 :        554 :                     c = '\"';
      91                 :        554 :                     break;
      92                 :            :                 default:
      93                 :            :                 {
      94 [ +  - ][ +  - ]:          4 :                     if( '0' <= *pStr && '7' >= *pStr )
      95                 :            :                     {
      96                 :          4 :                         sal_uInt16  nChar = 0;
      97                 :          4 :                         int  i = 0;
      98 [ +  - ][ +  - ]:         16 :                         while( '0' <= *pStr && '7' >= *pStr && i != 3 )
         [ +  + ][ +  + ]
      99                 :            :                         {
     100                 :         12 :                             nChar = nChar * 8 + (sal_uInt8)*pStr - (sal_uInt8)'0';
     101                 :         12 :                             ++pStr;
     102                 :         12 :                             i++;
     103                 :            :                         }
     104         [ -  + ]:          4 :                         if( nChar > 255 )
     105                 :            :                         {
     106                 :            :                             // Wert zu gross, oder kein 3 Ziffern
     107         [ #  # ]:          0 :                             delete [] pOrgStr;
     108                 :          0 :                             return( NULL );
     109                 :            :                         }
     110                 :          4 :                         c = (char)nChar;
     111                 :          4 :                         pStr--;
     112                 :            :                     }
     113         [ #  # ]:          0 :                     else if( 'x' == *pStr )
     114                 :            :                     {
     115                 :          0 :                         sal_uInt16  nChar = 0;
     116                 :          0 :                         int  i = 0;
     117                 :          0 :                         ++pStr;
     118 [ #  # ][ #  # ]:          0 :                         while( isxdigit( *pStr ) && i != 2 )
                 [ #  # ]
     119                 :            :                         {
     120         [ #  # ]:          0 :                             if( isdigit( *pStr ) )
     121                 :          0 :                                 nChar = nChar * 16 + (sal_uInt8)*pStr - (sal_uInt8)'0';
     122         [ #  # ]:          0 :                             else if( isupper( *pStr ) )
     123                 :          0 :                                 nChar = nChar * 16 + (sal_uInt8)*pStr - (sal_uInt8)'A' +10;
     124                 :            :                             else
     125                 :          0 :                                 nChar = nChar * 16 + (sal_uInt8)*pStr - (sal_uInt8)'a' +10;
     126                 :          0 :                             ++pStr;
     127                 :          0 :                             i++;
     128                 :            :                         }
     129                 :          0 :                         c = (char)nChar;
     130                 :          0 :                         pStr--;
     131                 :            :                     }
     132                 :            :                     else
     133                 :       1988 :                         c = *pStr;
     134                 :            :                 };
     135                 :            :             }
     136                 :            :         }
     137                 :            :         else
     138                 :    1683144 :             c = *pStr;
     139                 :    1685132 :         pOrgStr[ nOrgLen++ ] = c;
     140                 :    1685132 :         cOld = *pStr;
     141                 :    1685132 :         pStr++;
     142                 :            :     }
     143                 :            : 
     144         [ +  - ]:      73494 :     sal_Unicode *   pUniCode = new sal_Unicode[ nMaxUniCodeBuf ];
     145         [ +  - ]:      73494 :     rtl_TextToUnicodeConverter hConv = rtl_createTextToUnicodeConverter( nTextEncoding );
     146                 :            : 
     147                 :            :     sal_uInt32 nInfo;
     148                 :            :     sal_Size   nSrcCvtBytes;
     149                 :            :     sal_Size nUniSize = rtl_convertTextToUnicode( hConv, 0,
     150                 :            :                                                 pOrgStr, nOrgLen,
     151                 :            :                                                 pUniCode, nMaxUniCodeBuf,
     152                 :            :                                                 RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_DEFAULT
     153                 :            :                                                 | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_DEFAULT
     154                 :            :                                                 | RTL_TEXTTOUNICODE_FLAGS_INVALID_DEFAULT
     155                 :            :                                                 | RTL_TEXTTOUNICODE_FLAGS_FLUSH,
     156                 :            :                                                 &nInfo,
     157         [ +  - ]:      73494 :                                                 &nSrcCvtBytes );
     158                 :            : 
     159         [ +  - ]:      73494 :     rtl_destroyTextToUnicodeConverter( hConv );
     160         [ +  - ]:      73494 :     delete[] pOrgStr, pOrgStr = 0;
     161                 :            : 
     162         [ +  - ]:      73494 :     hConv = rtl_createUnicodeToTextConverter( RTL_TEXTENCODING_UTF8 );
     163                 :            :     // factor fo 6 is the maximum size of an UNICODE character as utf8
     164                 :      73494 :     char * pUtf8 = (char *)rtl_allocateMemory( nUniSize * 6 );
     165                 :            :     rtl_convertUnicodeToText( hConv, 0,
     166                 :            :                             pUniCode, nUniSize,
     167                 :            :                             pUtf8, nUniSize * 6,
     168                 :            :                             RTL_UNICODETOTEXT_FLAGS_UNDEFINED_DEFAULT
     169                 :            :                             | RTL_UNICODETOTEXT_FLAGS_INVALID_DEFAULT
     170                 :            :                             | RTL_UNICODETOTEXT_FLAGS_FLUSH,
     171                 :            :                             &nInfo,
     172         [ +  - ]:      73494 :                             &nSrcCvtBytes );
     173                 :            : 
     174         [ +  - ]:      73494 :     rtl_destroyTextToUnicodeConverter( hConv );
     175         [ +  - ]:      73494 :     delete[] pUniCode, pUniCode = 0;
     176                 :            : 
     177                 :      73494 :     return pUtf8;
     178                 :            : };
     179                 :            : 
     180                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10