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

Generated by: LCOV version 1.10