LCOV - code coverage report
Current view: top level - filter/source/msfilter - countryid.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 7 23 30.4 %
Date: 2012-08-25 Functions: 3 6 50.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 16 12.5 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "filter/msfilter/countryid.hxx"
      30                 :            : 
      31                 :            : #include <algorithm>
      32                 :            : #include <sal/macros.h>
      33                 :            : 
      34                 :            : // ----------------------------------------------------------------------------
      35                 :            : 
      36                 :            : namespace msfilter {
      37                 :            : 
      38                 :            : // Mapping table ==============================================================
      39                 :            : 
      40                 :            : namespace {
      41                 :            : 
      42                 :            : // ----------------------------------------------------------------------------
      43                 :            : 
      44                 :            : /** Table entry for Windows country ID <-> language type conversion.
      45                 :            : 
      46                 :            :     The first member is the Windows country ID, as defined in the header.
      47                 :            : 
      48                 :            :     The second member contains the corresponding language type for each country
      49                 :            :     ID. This must be a full language, not only the primary language type.
      50                 :            : 
      51                 :            :     The last bool flag defines, if the sub language type should be evaluated to
      52                 :            :     find the country ID from a language. If not set, all languages map to the
      53                 :            :     country which contain the given primary language type.
      54                 :            : 
      55                 :            :     Example: The language entry (COUNTRY_USA,LANGUAGE_ENGLISH_US,false) maps
      56                 :            :     the country ID for USA to the language LANGUAGE_ENGLISH_US. The clear sub
      57                 :            :     language flag causes all english languages LANGUAGE_ENGLISH_*** to map to
      58                 :            :     this country ID by default. To map the special case LANGUAGE_ENGLISH_EIRE
      59                 :            :     to the country ID COUNTRY_IRELAND, the sub language flag must be set in the
      60                 :            :     respective table entry, here (COUNTRY_IRELAND,LANGUAGE_ENGLISH_EIRE,true).
      61                 :            :  */
      62                 :            : struct CountryEntry
      63                 :            : {
      64                 :            :     CountryId                   meCountry;      /// Windows country ID.
      65                 :            :     LanguageType                meLanguage;     /// Corresponding language type.
      66                 :            :     bool                        mbUseSubLang;   /// false = Primary only, true = Primary and sub language.
      67                 :            : };
      68                 :            : 
      69                 :            : // ----------------------------------------------------------------------------
      70                 :            : 
      71                 :            : /** Table for Windows country ID <-> language type conversion.
      72                 :            : 
      73                 :            :     To map the same language to different country IDs, some of the entries
      74                 :            :     should contain a set sub language flag (see description of CountryEntry).
      75                 :            :     All table entries with a set flag take priority over the entry with the
      76                 :            :     same primary language, but cleared sub language flag, regardless of the
      77                 :            :     position in the table.
      78                 :            : 
      79                 :            :     To map different languages to the same country ID, several entries with the
      80                 :            :     same country ID may be inserted. In this case the conversion to a language
      81                 :            :     is done with the first found entry (starting from top) containing the given
      82                 :            :     country ID.
      83                 :            : 
      84                 :            :     For now all entries are sorted by country ID, but this is not required.
      85                 :            :  */
      86                 :            : static const CountryEntry pTable[] =
      87                 :            : {
      88                 :            :     { COUNTRY_USA,                  LANGUAGE_ENGLISH_US,                    false   },
      89                 :            :     { COUNTRY_DOMINICAN_REPUBLIC,   LANGUAGE_SPANISH_DOMINICAN_REPUBLIC,    true    },
      90                 :            :     { COUNTRY_JAMAICA,              LANGUAGE_ENGLISH_JAMAICA,               true    },
      91                 :            :     { COUNTRY_PUERTO_RICO,          LANGUAGE_SPANISH_PUERTO_RICO,           true    },
      92                 :            :     { COUNTRY_TRINIDAD_Y_TOBAGO,    LANGUAGE_ENGLISH_TRINIDAD,              true    },
      93                 :            :     { COUNTRY_CANADA,               LANGUAGE_ENGLISH_CAN,                   true    },
      94                 :            :     { COUNTRY_CANADA,               LANGUAGE_FRENCH_CANADIAN,               true    },
      95                 :            :     { COUNTRY_RUSSIA,               LANGUAGE_RUSSIAN,                       false   },
      96                 :            :     { COUNTRY_KAZAKHSTAN,           LANGUAGE_KAZAK,                         false   },
      97                 :            :     { COUNTRY_TATARSTAN,            LANGUAGE_TATAR,                         false   },
      98                 :            :     { COUNTRY_EGYPT,                LANGUAGE_ARABIC_EGYPT,                  true    },
      99                 :            :     { COUNTRY_SOUTH_AFRICA,         LANGUAGE_AFRIKAANS,                     false   },
     100                 :            :     { COUNTRY_SOUTH_AFRICA,         LANGUAGE_ENGLISH_SAFRICA,               true    },
     101                 :            :     { COUNTRY_SOUTH_AFRICA,         LANGUAGE_TSONGA,                        false   },
     102                 :            :     { COUNTRY_SOUTH_AFRICA,         LANGUAGE_VENDA,                         false   },
     103                 :            :     { COUNTRY_SOUTH_AFRICA,         LANGUAGE_XHOSA,                         false   },
     104                 :            :     { COUNTRY_SOUTH_AFRICA,         LANGUAGE_ZULU,                          false   },
     105                 :            :     { COUNTRY_GREECE,               LANGUAGE_GREEK,                         false   },
     106                 :            :     { COUNTRY_NETHERLANDS,          LANGUAGE_DUTCH,                         false   },
     107                 :            :     { COUNTRY_NETHERLANDS,          LANGUAGE_FRISIAN_NETHERLANDS,           false   },
     108                 :            :     { COUNTRY_BELGIUM,              LANGUAGE_DUTCH_BELGIAN,                 true    },
     109                 :            :     { COUNTRY_BELGIUM,              LANGUAGE_FRENCH_BELGIAN,                true    },
     110                 :            :     { COUNTRY_FRANCE,               LANGUAGE_FRENCH,                        false   },
     111                 :            :     { COUNTRY_SPAIN,                LANGUAGE_SPANISH_MODERN,                false   },
     112                 :            :     { COUNTRY_SPAIN,                LANGUAGE_SPANISH_DATED,                 false   },
     113                 :            :     { COUNTRY_SPAIN,                LANGUAGE_CATALAN,                       false   },
     114                 :            :     { COUNTRY_SPAIN,                LANGUAGE_BASQUE,                        false   },
     115                 :            :     { COUNTRY_SPAIN,                LANGUAGE_GALICIAN,                      false   },
     116                 :            :     { COUNTRY_HUNGARY,              LANGUAGE_HUNGARIAN,                     false   },
     117                 :            :     { COUNTRY_ITALY,                LANGUAGE_ITALIAN,                       false   },
     118                 :            :     { COUNTRY_ROMANIA,              LANGUAGE_ROMANIAN,                      false   },
     119                 :            :     { COUNTRY_SWITZERLAND,          LANGUAGE_GERMAN_SWISS,                  true    },
     120                 :            :     { COUNTRY_SWITZERLAND,          LANGUAGE_FRENCH_SWISS,                  true    },
     121                 :            :     { COUNTRY_SWITZERLAND,          LANGUAGE_ITALIAN_SWISS,                 true    },
     122                 :            :     { COUNTRY_SWITZERLAND,          LANGUAGE_RHAETO_ROMAN,                  false   },
     123                 :            :     { COUNTRY_AUSTRIA,              LANGUAGE_GERMAN_AUSTRIAN,               true    },
     124                 :            :     { COUNTRY_UNITED_KINGDOM,       LANGUAGE_ENGLISH_UK,                    true    },
     125                 :            :     { COUNTRY_UNITED_KINGDOM,       LANGUAGE_GAELIC_SCOTLAND,               true    },
     126                 :            :     { COUNTRY_UNITED_KINGDOM,       LANGUAGE_WELSH,                         false   },
     127                 :            :     { COUNTRY_DENMARK,              LANGUAGE_DANISH,                        false   },
     128                 :            :     { COUNTRY_SWEDEN,               LANGUAGE_SWEDISH,                       false   },
     129                 :            :     { COUNTRY_SWEDEN,               LANGUAGE_SAMI_LAPPISH,                  false   },
     130                 :            :     { COUNTRY_NORWAY,               LANGUAGE_NORWEGIAN_BOKMAL,              false   },
     131                 :            :     { COUNTRY_POLAND,               LANGUAGE_POLISH,                        false   },
     132                 :            :     { COUNTRY_GERMANY,              LANGUAGE_GERMAN,                        false   },
     133                 :            :     { COUNTRY_GERMANY,              LANGUAGE_SORBIAN,                       false   },
     134                 :            :     { COUNTRY_PERU,                 LANGUAGE_SPANISH_PERU,                  true    },
     135                 :            :     { COUNTRY_MEXICO,               LANGUAGE_SPANISH_MEXICAN,               true    },
     136                 :            :     { COUNTRY_ARGENTINIA,           LANGUAGE_SPANISH_ARGENTINA,             true    },
     137                 :            :     { COUNTRY_BRAZIL,               LANGUAGE_PORTUGUESE_BRAZILIAN,          true    },
     138                 :            :     { COUNTRY_CHILE,                LANGUAGE_SPANISH_CHILE,                 true    },
     139                 :            :     { COUNTRY_COLOMBIA,             LANGUAGE_SPANISH_COLOMBIA,              true    },
     140                 :            :     { COUNTRY_VENEZUELA,            LANGUAGE_SPANISH_VENEZUELA,             true    },
     141                 :            :     { COUNTRY_MALAYSIA,             LANGUAGE_MALAY_MALAYSIA,                false   },
     142                 :            :     { COUNTRY_AUSTRALIA,            LANGUAGE_ENGLISH_AUS,                   true    },
     143                 :            :     { COUNTRY_INDONESIA,            LANGUAGE_INDONESIAN,                    false   },
     144                 :            :     { COUNTRY_PHILIPPINES,          LANGUAGE_ENGLISH_PHILIPPINES,           true    },
     145                 :            :     { COUNTRY_NEW_ZEALAND,          LANGUAGE_MAORI_NEW_ZEALAND,             false   },
     146                 :            :     { COUNTRY_NEW_ZEALAND,          LANGUAGE_ENGLISH_NZ,                    true    },
     147                 :            :     { COUNTRY_SINGAPORE,            LANGUAGE_CHINESE_SINGAPORE,             true    },
     148                 :            :     { COUNTRY_THAILAND,             LANGUAGE_THAI,                          false   },
     149                 :            :     { COUNTRY_JAPAN,                LANGUAGE_JAPANESE,                      false   },
     150                 :            :     { COUNTRY_SOUTH_KOREA,          LANGUAGE_KOREAN,                        false   },
     151                 :            :     { COUNTRY_VIET_NAM,             LANGUAGE_VIETNAMESE,                    false   },
     152                 :            :     { COUNTRY_PR_CHINA,             LANGUAGE_CHINESE_SIMPLIFIED,            false   },
     153                 :            :     { COUNTRY_TIBET,                LANGUAGE_TIBETAN,                       false   },
     154                 :            :     { COUNTRY_TURKEY,               LANGUAGE_TURKISH,                       false   },
     155                 :            :     { COUNTRY_INDIA,                LANGUAGE_HINDI,                         false   },
     156                 :            :     { COUNTRY_INDIA,                LANGUAGE_URDU_INDIA,                    true    },
     157                 :            :     { COUNTRY_INDIA,                LANGUAGE_PUNJABI,                       false   },
     158                 :            :     { COUNTRY_INDIA,                LANGUAGE_GUJARATI,                      false   },
     159                 :            :     { COUNTRY_INDIA,                LANGUAGE_ORIYA,                         false   },
     160                 :            :     { COUNTRY_INDIA,                LANGUAGE_TAMIL,                         false   },
     161                 :            :     { COUNTRY_INDIA,                LANGUAGE_TELUGU,                        false   },
     162                 :            :     { COUNTRY_INDIA,                LANGUAGE_KANNADA,                       false   },
     163                 :            :     { COUNTRY_INDIA,                LANGUAGE_MALAYALAM,                     false   },
     164                 :            :     { COUNTRY_INDIA,                LANGUAGE_ASSAMESE,                      false   },
     165                 :            :     { COUNTRY_INDIA,                LANGUAGE_MARATHI,                       false   },
     166                 :            :     { COUNTRY_INDIA,                LANGUAGE_SANSKRIT,                      false   },
     167                 :            :     { COUNTRY_INDIA,                LANGUAGE_KONKANI,                       false   },
     168                 :            :     { COUNTRY_INDIA,                LANGUAGE_MANIPURI,                      false   },
     169                 :            :     { COUNTRY_INDIA,                LANGUAGE_SINDHI,                        false   },
     170                 :            :     { COUNTRY_INDIA,                LANGUAGE_KASHMIRI,                      false   },
     171                 :            :     { COUNTRY_PAKISTAN,             LANGUAGE_URDU_PAKISTAN,                 false   },
     172                 :            :     { COUNTRY_MYANMAR,              LANGUAGE_BURMESE,                       false   },
     173                 :            :     { COUNTRY_MOROCCO,              LANGUAGE_ARABIC_MOROCCO,                true    },
     174                 :            :     { COUNTRY_ALGERIA,              LANGUAGE_ARABIC_ALGERIA,                true    },
     175                 :            :     { COUNTRY_TUNISIA,              LANGUAGE_ARABIC_TUNISIA,                true    },
     176                 :            :     { COUNTRY_LIBYA,                LANGUAGE_ARABIC_LIBYA,                  true    },
     177                 :            :     { COUNTRY_SENEGAL,              LANGUAGE_FRENCH_SENEGAL,                true    },
     178                 :            :     { COUNTRY_MALI,                 LANGUAGE_FRENCH_MALI,                   true    },
     179                 :            :     { COUNTRY_COTE_D_IVOIRE,        LANGUAGE_FRENCH_COTE_D_IVOIRE,          true    },
     180                 :            :     { COUNTRY_CAMEROON,             LANGUAGE_FRENCH_CAMEROON,               true    },
     181                 :            :     { COUNTRY_ZAIRE,                LANGUAGE_FRENCH_ZAIRE,                  true    },
     182                 :            :     { COUNTRY_RWANDA,               LANGUAGE_KINYARWANDA_RWANDA,            false   },
     183                 :            :     { COUNTRY_KENYA,                LANGUAGE_SWAHILI,                       false   },
     184                 :            :     { COUNTRY_REUNION,              LANGUAGE_FRENCH_REUNION,                true    },
     185                 :            :     { COUNTRY_ZIMBABWE,             LANGUAGE_ENGLISH_ZIMBABWE,              true    },
     186                 :            :     { COUNTRY_LESOTHO,              LANGUAGE_SESOTHO,                       false   },
     187                 :            :     { COUNTRY_BOTSWANA,             LANGUAGE_TSWANA,                        false   },
     188                 :            :     { COUNTRY_FAEROE_ISLANDS,       LANGUAGE_FAEROESE,                      false   },
     189                 :            :     { COUNTRY_PORTUGAL,             LANGUAGE_PORTUGUESE,                    false   },
     190                 :            :     { COUNTRY_LUXEMBOURG,           LANGUAGE_GERMAN_LUXEMBOURG,             true    },
     191                 :            :     { COUNTRY_LUXEMBOURG,           LANGUAGE_FRENCH_LUXEMBOURG,             true    },
     192                 :            :     { COUNTRY_IRELAND,              LANGUAGE_ENGLISH_EIRE,                  true    },
     193                 :            :     { COUNTRY_IRELAND,              LANGUAGE_GAELIC_IRELAND,                true    },
     194                 :            :     { COUNTRY_ICELAND,              LANGUAGE_ICELANDIC,                     false   },
     195                 :            :     { COUNTRY_ALBANIA,              LANGUAGE_ALBANIAN,                      false   },
     196                 :            :     { COUNTRY_MALTA,                LANGUAGE_MALTESE,                       false   },
     197                 :            :     { COUNTRY_FINLAND,              LANGUAGE_FINNISH,                       false   },
     198                 :            :     { COUNTRY_FINLAND,              LANGUAGE_SWEDISH_FINLAND,               true    },
     199                 :            :     { COUNTRY_BULGARIA,             LANGUAGE_BULGARIAN,                     false   },
     200                 :            :     { COUNTRY_LITHUANIA,            LANGUAGE_LITHUANIAN,                    false   },
     201                 :            :     { COUNTRY_LATVIA,               LANGUAGE_LATVIAN,                       false   },
     202                 :            :     { COUNTRY_ESTONIA,              LANGUAGE_ESTONIAN,                      false   },
     203                 :            :     { COUNTRY_MOLDOVA,              LANGUAGE_ROMANIAN_MOLDOVA,              true    },
     204                 :            :     { COUNTRY_MOLDOVA,              LANGUAGE_RUSSIAN_MOLDOVA,               true    },
     205                 :            :     { COUNTRY_ARMENIA,              LANGUAGE_ARMENIAN,                      false   },
     206                 :            :     { COUNTRY_BELARUS,              LANGUAGE_BELARUSIAN,                    false   },
     207                 :            :     { COUNTRY_MONACO,               LANGUAGE_FRENCH_MONACO,                 true    },
     208                 :            :     { COUNTRY_UKRAINE,              LANGUAGE_UKRAINIAN,                     false   },
     209                 :            :     { COUNTRY_SERBIA,               LANGUAGE_SERBIAN_LATIN,                 false   },
     210                 :            :     { COUNTRY_CROATIA,              LANGUAGE_CROATIAN,                      true    },  // sub type of LANGUAGE_SERBIAN
     211                 :            :     { COUNTRY_SLOVENIA,             LANGUAGE_SLOVENIAN,                     false   },
     212                 :            :     { COUNTRY_MACEDONIA,            LANGUAGE_MACEDONIAN,                    false   },
     213                 :            :     { COUNTRY_CZECH,                LANGUAGE_CZECH,                         false   },
     214                 :            :     { COUNTRY_SLOVAK,               LANGUAGE_SLOVAK,                        false   },
     215                 :            :     { COUNTRY_LIECHTENSTEIN,        LANGUAGE_GERMAN_LIECHTENSTEIN,          true    },
     216                 :            :     { COUNTRY_BELIZE,               LANGUAGE_ENGLISH_BELIZE,                true    },
     217                 :            :     { COUNTRY_GUATEMALA,            LANGUAGE_SPANISH_GUATEMALA,             true    },
     218                 :            :     { COUNTRY_EL_SALVADOR,          LANGUAGE_SPANISH_EL_SALVADOR,           true    },
     219                 :            :     { COUNTRY_HONDURAS,             LANGUAGE_SPANISH_HONDURAS,              true    },
     220                 :            :     { COUNTRY_NICARAGUA,            LANGUAGE_SPANISH_NICARAGUA,             true    },
     221                 :            :     { COUNTRY_COSTA_RICA,           LANGUAGE_SPANISH_COSTARICA,             true    },
     222                 :            :     { COUNTRY_PANAMA,               LANGUAGE_SPANISH_PANAMA,                true    },
     223                 :            :     { COUNTRY_BOLIVIA,              LANGUAGE_SPANISH_BOLIVIA,               true    },
     224                 :            :     { COUNTRY_ECUADOR,              LANGUAGE_SPANISH_ECUADOR,               true    },
     225                 :            :     { COUNTRY_PARAGUAY,             LANGUAGE_SPANISH_PARAGUAY,              true    },
     226                 :            :     { COUNTRY_URUGUAY,              LANGUAGE_SPANISH_URUGUAY,               true    },
     227                 :            :     { COUNTRY_BRUNEI_DARUSSALAM,    LANGUAGE_MALAY_BRUNEI_DARUSSALAM,       true    },
     228                 :            :     { COUNTRY_HONG_KONG,            LANGUAGE_CHINESE_HONGKONG,              true    },
     229                 :            :     { COUNTRY_MACAU,                LANGUAGE_CHINESE_MACAU,                 true    },
     230                 :            :     { COUNTRY_CAMBODIA,             LANGUAGE_KHMER,                         false   },
     231                 :            :     { COUNTRY_LAOS,                 LANGUAGE_LAO,                           false   },
     232                 :            :     { COUNTRY_BANGLADESH,           LANGUAGE_BENGALI,                       false   },
     233                 :            :     { COUNTRY_TAIWAN,               LANGUAGE_CHINESE_TRADITIONAL,           true    },
     234                 :            :     { COUNTRY_MALDIVES,             LANGUAGE_DHIVEHI,                       false   },
     235                 :            :     { COUNTRY_LEBANON,              LANGUAGE_ARABIC_LEBANON,                true    },
     236                 :            :     { COUNTRY_JORDAN,               LANGUAGE_ARABIC_JORDAN,                 true    },
     237                 :            :     { COUNTRY_SYRIA,                LANGUAGE_ARABIC_SYRIA,                  true    },
     238                 :            :     { COUNTRY_IRAQ,                 LANGUAGE_ARABIC_IRAQ,                   true    },
     239                 :            :     { COUNTRY_KUWAIT,               LANGUAGE_ARABIC_KUWAIT,                 true    },
     240                 :            :     { COUNTRY_SAUDI_ARABIA,         LANGUAGE_ARABIC_SAUDI_ARABIA,           true    },
     241                 :            :     { COUNTRY_YEMEN,                LANGUAGE_ARABIC_YEMEN,                  true    },
     242                 :            :     { COUNTRY_OMAN,                 LANGUAGE_ARABIC_OMAN,                   true    },
     243                 :            :     { COUNTRY_UAE,                  LANGUAGE_ARABIC_UAE,                    true    },
     244                 :            :     { COUNTRY_ISRAEL,               LANGUAGE_HEBREW,                        false   },
     245                 :            :     { COUNTRY_BAHRAIN,              LANGUAGE_ARABIC_BAHRAIN,                true    },
     246                 :            :     { COUNTRY_QATAR,                LANGUAGE_ARABIC_QATAR,                  true    },
     247                 :            :     { COUNTRY_MONGOLIA,             LANGUAGE_MONGOLIAN,                     false   },
     248                 :            :     { COUNTRY_NEPAL,                LANGUAGE_NEPALI,                        false   },
     249                 :            :     { COUNTRY_IRAN,                 LANGUAGE_FARSI,                         false   },
     250                 :            :     { COUNTRY_TAJIKISTAN,           LANGUAGE_TAJIK,                         false   },
     251                 :            :     { COUNTRY_TURKMENISTAN,         LANGUAGE_TURKMEN,                       false   },
     252                 :            :     { COUNTRY_AZERBAIJAN,           LANGUAGE_AZERI_LATIN,                   false   },
     253                 :            :     { COUNTRY_GEORGIA,              LANGUAGE_GEORGIAN,                      false   },
     254                 :            :     { COUNTRY_KYRGYZSTAN,           LANGUAGE_KIRGHIZ,                       false   },
     255                 :            :     { COUNTRY_UZBEKISTAN,           LANGUAGE_UZBEK_LATIN,                   false   }
     256                 :            : };
     257                 :            : 
     258                 :            : const CountryEntry * const pEnd = pTable + SAL_N_ELEMENTS( pTable );
     259                 :            : 
     260                 :            : /** Predicate comparing a country ID with the member of a CountryEntry. */
     261                 :            : struct CountryEntryPred_Country
     262                 :            : {
     263                 :            :     CountryId                   meCountry;
     264                 :            : 
     265                 :        148 :     inline explicit             CountryEntryPred_Country( CountryId eCountry ) :
     266                 :        148 :                                     meCountry( eCountry ) {}
     267                 :            : 
     268                 :       1812 :     inline bool                 operator()( const CountryEntry& rCmp ) const
     269                 :       1812 :                                     { return rCmp.meCountry == meCountry; }
     270                 :            : };
     271                 :            : 
     272                 :            : /** Predicate comparing a language type with the member of a CountryEntry.
     273                 :            : 
     274                 :            :     Compares by primary language only, if the passed CountryEntry allows it
     275                 :            :     (the member mbUseSubLang is cleared), otherwise by full language type. */
     276                 :            : struct CountryEntryPred_Language
     277                 :            : {
     278                 :            :     LanguageType                meLanguage;
     279                 :            : 
     280                 :          0 :     inline explicit             CountryEntryPred_Language( LanguageType eLanguage ) :
     281                 :          0 :                                     meLanguage( eLanguage ) {}
     282                 :            : 
     283                 :            :     inline bool                 operator()( const CountryEntry& rCmp ) const;
     284                 :            : };
     285                 :            : 
     286                 :          0 : inline bool CountryEntryPred_Language::operator()( const CountryEntry& rCmp ) const
     287                 :            : {
     288                 :            :     //  rCmp.mbUseSubLang==true  -> compare full language type
     289                 :            :     //  rCmp.mbUseSubLang==false -> compare primary language only
     290                 :            :     return rCmp.mbUseSubLang ? (meLanguage == rCmp.meLanguage) :
     291         [ #  # ]:          0 :                 ((meLanguage & 0x03FF) == (rCmp.meLanguage & 0x03FF));
     292                 :            : }
     293                 :            : 
     294                 :            : } // namespace
     295                 :            : 
     296                 :            : // Country ID <-> Language type conversion ====================================
     297                 :            : 
     298                 :          0 : CountryId ConvertLanguageToCountry( LanguageType eLanguage )
     299                 :            : {
     300                 :            :     // country of a found primary language type
     301                 :          0 :     CountryId ePrimCountry = COUNTRY_DONTKNOW;
     302                 :            : 
     303                 :            :     // find an exact match and a primary-language-only match, in one pass
     304                 :          0 :     const CountryEntry* pEntry = pTable;
     305         [ #  # ]:          0 :     do
     306                 :            :     {
     307         [ #  # ]:          0 :         pEntry = std::find_if( pEntry, pEnd, CountryEntryPred_Language( eLanguage ) );
     308         [ #  # ]:          0 :         if( pEntry != pEnd )
     309                 :            :         {
     310         [ #  # ]:          0 :             if( pEntry->mbUseSubLang )
     311                 :          0 :                 return pEntry->meCountry;       // exact match found -> return
     312         [ #  # ]:          0 :             if( ePrimCountry == COUNTRY_DONTKNOW )
     313                 :          0 :                 ePrimCountry = pEntry->meCountry;
     314                 :          0 :             ++pEntry;   // one entry forward for next find_if() call
     315                 :            :         }
     316                 :            :     }
     317                 :            :     while( pEntry != pEnd );
     318                 :            : 
     319                 :          0 :     return ePrimCountry;
     320                 :            : }
     321                 :            : 
     322                 :        148 : LanguageType ConvertCountryToLanguage( CountryId eCountry )
     323                 :            : {
     324                 :            :     // just find the first occurrence of eCountry and return the language type
     325         [ +  - ]:        148 :     const CountryEntry* pEntry = std::find_if( pTable, pEnd, CountryEntryPred_Country( eCountry ) );
     326         [ +  - ]:        148 :     return (pEntry != pEnd) ? pEntry->meLanguage : LANGUAGE_DONTKNOW;
     327                 :            : }
     328                 :            : 
     329                 :            : } // namespace svx
     330                 :            : 
     331                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10