LCOV - code coverage report
Current view: top level - tools/source/reversemap - bestreversemap.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 60 60 100.0 %
Date: 2014-04-11 Functions: 7 7 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             : 
      10             : #include "sal/config.h"
      11             : #include "rtl/textcvt.h"
      12             : 
      13             : #include <stdio.h>
      14             : 
      15             : struct Encoder
      16             : {
      17             :     rtl_UnicodeToTextConverter m_aConverter;
      18             :     bool m_bCapable;
      19             :     rtl_TextEncoding m_nEncoding;
      20             :     const char *m_pEncoding;
      21          15 :     Encoder(rtl_TextEncoding nEncoding, const char *pEncoding)
      22             :         : m_bCapable(true)
      23             :         , m_nEncoding(nEncoding)
      24          15 :         , m_pEncoding(pEncoding)
      25             :     {
      26          15 :         m_aConverter = rtl_createUnicodeToTextConverter(m_nEncoding);
      27          15 :     }
      28          15 :     ~Encoder()
      29             :     {
      30          15 :         rtl_destroyUnicodeToTextConverter(m_aConverter);
      31          15 :     }
      32      437543 :     void checkSupports(sal_Unicode c)
      33             :     {
      34             :         sal_Char aTempArray[8];
      35             :         sal_Size nTempSize;
      36             :         sal_uInt32 nCvtInfo;
      37             : 
      38             :         sal_Size nChars = rtl_convertUnicodeToText(m_aConverter,
      39             :             NULL, &c, 1, aTempArray, sizeof(aTempArray),
      40             :               RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |  RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR,
      41      437543 :              &nCvtInfo, &nTempSize);
      42      437543 :         m_bCapable = nChars > 0;
      43      437543 :     }
      44        3855 :     void reset()
      45             :     {
      46        3855 :         m_bCapable = true;
      47        3855 :     }
      48     1601213 :     bool isOK() const
      49             :     {
      50     1601213 :         return m_bCapable;
      51             :     }
      52         257 :     const char* getName() const
      53             :     {
      54         257 :         return m_pEncoding;
      55             :     }
      56             : 
      57             : };
      58             : 
      59           1 : int main()
      60             : {
      61             : #   define EXP(x) Encoder(x, #x)
      62             : 
      63             :     Encoder aConverters[15] =
      64             :     {
      65             :         EXP(RTL_TEXTENCODING_MS_1361),
      66             :         EXP(RTL_TEXTENCODING_MS_950),
      67             :         EXP(RTL_TEXTENCODING_MS_949),
      68             :         EXP(RTL_TEXTENCODING_MS_936),
      69             :         EXP(RTL_TEXTENCODING_MS_932),
      70             :         EXP(RTL_TEXTENCODING_MS_874),
      71             :         EXP(RTL_TEXTENCODING_MS_1258),
      72             :         EXP(RTL_TEXTENCODING_MS_1257),
      73             :         EXP(RTL_TEXTENCODING_MS_1256),
      74             :         EXP(RTL_TEXTENCODING_MS_1255),
      75             :         EXP(RTL_TEXTENCODING_MS_1254),
      76             :         EXP(RTL_TEXTENCODING_MS_1253),
      77             :         EXP(RTL_TEXTENCODING_MS_1251),
      78             :         EXP(RTL_TEXTENCODING_MS_1250),
      79             :         EXP(RTL_TEXTENCODING_MS_1252)
      80          16 :     };
      81             : 
      82           1 :     printf("//Do not edit manually, generated from bestreversemap.cxx\n");
      83           1 :     printf("rtl_TextEncoding getBestMSEncodingByChar(sal_Unicode c)\n");
      84           1 :     printf("{\n");
      85             : 
      86           1 :     sal_Unicode c = 0;
      87         259 :     while (c < 0xFFFF)
      88             :     {
      89        4112 :         for (size_t i = 0; i < SAL_N_ELEMENTS(aConverters); ++i)
      90        3855 :             aConverters[i].reset();
      91             : 
      92         257 :         int nMostCapable = -1;
      93             : 
      94       41142 :         while(c < 0xFFFF)
      95             :         {
      96       40885 :             bool bSomethingCapable = false;
      97      654160 :             for (size_t i = 0; i < SAL_N_ELEMENTS(aConverters); ++i)
      98             :             {
      99      613275 :                 if (aConverters[i].isOK())
     100       62880 :                     aConverters[i].checkSupports(c);
     101      613275 :                 if (aConverters[i].isOK())
     102             :                 {
     103       59025 :                     bSomethingCapable = true;
     104       59025 :                     nMostCapable = i;
     105             :                 }
     106             :             }
     107       40885 :             if (!bSomethingCapable)
     108         257 :                 break;
     109       40628 :             ++c;
     110             :         }
     111         257 :         sal_Unicode cEnd = c;
     112         257 :         printf("    if (c < 0x%x)\n", c);
     113         257 :         printf("        return %s;\n", aConverters[nMostCapable].getName());
     114       25421 :         while(c < 0xFFFF)
     115             :         {
     116       25163 :             bool bNothingCapable = true;
     117      399570 :             for (size_t i = 0; i < SAL_N_ELEMENTS(aConverters); ++i)
     118             :             {
     119      374663 :                 aConverters[i].checkSupports(c);
     120      374663 :                 if (aConverters[i].isOK())
     121             :                 {
     122         256 :                     bNothingCapable = false;
     123         256 :                     break;
     124             :                 }
     125             :             }
     126       25163 :             if (!bNothingCapable)
     127         256 :                 break;
     128       24907 :             ++c;
     129             :         }
     130         257 :         if (cEnd != c)
     131             :         {
     132         211 :             if (c < 0xFFFF)
     133             :             {
     134         210 :                 printf("    if (c < 0x%x)\n", c);
     135         210 :                 printf("        return RTL_TEXTENCODING_DONTKNOW;\n");
     136             :             }
     137             :             else
     138           1 :                 printf("    return RTL_TEXTENCODING_DONTKNOW;\n");
     139             :         }
     140             :     }
     141             : 
     142           1 :     printf("}\n");
     143           1 :     fflush(stdout);
     144             : 
     145          16 :     return EXIT_SUCCESS;
     146             : }
     147             : 
     148             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10