LCOV - code coverage report
Current view: top level - filter/source/msfilter - rtfutil.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 50 62 80.6 %
Date: 2012-08-25 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 35 67 52.2 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * Version: MPL 1.1 / GPLv3+ / LGPLv3+
       4                 :            :  *
       5                 :            :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :            :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :            :  * the License. You may obtain a copy of the License at
       8                 :            :  * http://www.mozilla.org/MPL/
       9                 :            :  *
      10                 :            :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :            :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :            :  * for the specific language governing rights and limitations under the
      13                 :            :  * License.
      14                 :            :  *
      15                 :            :  * The Initial Developer of the Original Code is
      16                 :            :  *       Miklos Vajna <vmiklos@suse.cz> (SUSE, Inc.)
      17                 :            :  * Portions created by the Initial Developer are Copyright (C) 2012 the
      18                 :            :  * Initial Developer. All Rights Reserved.
      19                 :            :  *
      20                 :            :  * Contributor(s):
      21                 :            :  *
      22                 :            :  * Alternatively, the contents of this file may be used under the terms of
      23                 :            :  * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
      24                 :            :  * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
      25                 :            :  * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
      26                 :            :  * instead of those above.
      27                 :            :  */
      28                 :            : 
      29                 :            : #include <filter/msfilter/rtfutil.hxx>
      30                 :            : #include <rtl/strbuf.hxx>
      31                 :            : #include <svtools/rtfkeywd.hxx>
      32                 :            : 
      33                 :            : namespace msfilter {
      34                 :            : namespace rtfutil {
      35                 :            : 
      36                 :        305 : OString OutHex(sal_uLong nHex, sal_uInt8 nLen)
      37                 :            : {
      38                 :        305 :     sal_Char aNToABuf[] = "0000000000000000";
      39                 :            : 
      40                 :            :     OSL_ENSURE( nLen < sizeof(aNToABuf), "nLen is too big" );
      41         [ -  + ]:        305 :     if( nLen >= sizeof(aNToABuf) )
      42                 :          0 :         nLen = (sizeof(aNToABuf)-1);
      43                 :            : 
      44                 :            :     // Set pointer to the buffer end
      45                 :        305 :     sal_Char* pStr = aNToABuf + (sizeof(aNToABuf)-1);
      46         [ +  + ]:        915 :     for( sal_uInt8 n = 0; n < nLen; ++n )
      47                 :            :     {
      48                 :        610 :         *(--pStr) = (sal_Char)(nHex & 0xf ) + 48;
      49         [ +  + ]:        610 :         if( *pStr > '9' )
      50                 :        190 :             *pStr += 39;
      51                 :        610 :         nHex >>= 4;
      52                 :            :     }
      53                 :        305 :     return OString(pStr);
      54                 :            : }
      55                 :            : 
      56                 :       8910 : OString OutChar(sal_Unicode c, int *pUCMode, rtl_TextEncoding eDestEnc)
      57                 :            : {
      58                 :       8910 :     OStringBuffer aBuf;
      59                 :       8910 :     const sal_Char* pStr = 0;
      60                 :            :     // 0x0b instead of \n, etc because of the replacements in SwWW8AttrIter::GetSnippet()
      61   [ -  -  +  +  :       8910 :     switch (c)
                +  +  + ]
      62                 :            :     {
      63                 :            :         case 0x0b:
      64                 :            :             // hard line break
      65                 :          0 :             pStr = OOO_STRING_SVTOOLS_RTF_LINE;
      66                 :          0 :             break;
      67                 :            :         case '\t':
      68                 :          0 :             pStr = OOO_STRING_SVTOOLS_RTF_TAB;
      69                 :          0 :             break;
      70                 :            :         case '\\':
      71                 :            :         case '}':
      72                 :            :         case '{':
      73         [ +  - ]:         20 :             aBuf.append('\\');
      74         [ +  - ]:         20 :             aBuf.append((sal_Char)c);
      75                 :         20 :             break;
      76                 :            :         case 0xa0:
      77                 :            :             // non-breaking space
      78                 :          5 :             pStr = "\\~";
      79                 :          5 :             break;
      80                 :            :         case 0x1e:
      81                 :            :             // non-breaking hyphen
      82                 :          5 :             pStr = "\\_";
      83                 :          5 :             break;
      84                 :            :         case 0x1f:
      85                 :            :             // optional hyphen
      86                 :          5 :             pStr = "\\-";
      87                 :          5 :             break;
      88                 :            :         default:
      89 [ +  + ][ +  + ]:       8875 :             if (c >= ' ' && c <= '~')
      90         [ +  - ]:       8570 :                 aBuf.append((sal_Char)c);
      91                 :            :             else {
      92                 :        305 :                 OUString sBuf(&c, 1);
      93                 :        305 :                 OString sConverted;
      94                 :        305 :                 sBuf.convertToString(&sConverted, eDestEnc, OUSTRING_TO_OSTRING_CVTFLAGS);
      95                 :        305 :                 const sal_Int32 nLen = sConverted.getLength();
      96                 :            : 
      97         [ +  - ]:        305 :                 if (pUCMode)
      98                 :            :                 {
      99         [ -  + ]:        305 :                     if (*pUCMode != nLen)
     100                 :            :                     {
     101         [ #  # ]:          0 :                         aBuf.append("\\uc");
     102         [ #  # ]:          0 :                         aBuf.append((sal_Int32)nLen);
     103                 :            :                         // #i47831# add an additional whitespace, so that "document whitespaces" are not ignored.
     104         [ #  # ]:          0 :                         aBuf.append(' ');
     105                 :          0 :                         *pUCMode = nLen;
     106                 :            :                     }
     107         [ +  - ]:        305 :                     aBuf.append("\\u");
     108         [ +  - ]:        305 :                     aBuf.append((sal_Int32)c);
     109                 :            :                 }
     110                 :            : 
     111         [ +  + ]:        610 :                 for (sal_Int32 nI = 0; nI < nLen; ++nI)
     112                 :            :                 {
     113         [ +  - ]:        305 :                     aBuf.append("\\'");
     114 [ +  - ][ +  - ]:        305 :                     aBuf.append(OutHex(sConverted.getStr()[nI], 2));
     115                 :        305 :                 }
     116                 :            :             }
     117                 :            :     }
     118         [ +  + ]:       8910 :     if (pStr) {
     119         [ +  - ]:         15 :         aBuf.append(pStr);
     120         [ +  - ]:         15 :         switch (c)
     121                 :            :         {
     122                 :            :             case 0xa0:
     123                 :            :             case 0x1e:
     124                 :            :             case 0x1f:
     125                 :         15 :                 break;
     126                 :            :             default:
     127         [ #  # ]:         15 :                 aBuf.append(' ');
     128                 :            :         }
     129                 :            :     }
     130                 :       8910 :     return aBuf.makeStringAndClear();
     131                 :            : }
     132                 :            : 
     133                 :       3440 : OString OutString(const String &rStr, rtl_TextEncoding eDestEnc)
     134                 :            : {
     135                 :            :     SAL_INFO("filter.ms", OSL_THIS_FUNC << ", rStr = '" << OUString(rStr) << "'");
     136                 :       3440 :     OStringBuffer aBuf;
     137                 :       3440 :     int nUCMode = 1;
     138         [ +  + ]:      12350 :     for (xub_StrLen n = 0; n < rStr.Len(); ++n)
     139 [ +  - ][ +  - ]:       8910 :         aBuf.append(OutChar(rStr.GetChar(n), &nUCMode, eDestEnc));
     140         [ -  + ]:       3440 :     if (nUCMode != 1) {
     141         [ #  # ]:          0 :         aBuf.append(OOO_STRING_SVTOOLS_RTF_UC);
     142         [ #  # ]:          0 :         aBuf.append((sal_Int32)1);
     143         [ #  # ]:          0 :         aBuf.append(" "); // #i47831# add an additional whitespace, so that "document whitespaces" are not ignored.;
     144                 :            :     }
     145                 :       3440 :     return aBuf.makeStringAndClear();
     146                 :            : }
     147                 :            : 
     148                 :            : }
     149                 :            : }
     150                 :            : 
     151                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10