LibreOffice Module filter (master) 1
countryid.cxx
Go to the documentation of this file.
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
21
22#include <algorithm>
23#include <sal/macros.h>
24
25
26namespace msfilter {
27
28// Mapping table ==============================================================
29
30namespace {
31
32
51struct CountryEntry
52{
56};
57
58
74const CountryEntry pTable[] =
75{
102 { COUNTRY_SPAIN, LANGUAGE_BASQUE, false },
143 { COUNTRY_INDIA, LANGUAGE_HINDI, false },
147 { COUNTRY_INDIA, LANGUAGE_ODIA, false },
148 { COUNTRY_INDIA, LANGUAGE_TAMIL, false },
149 { COUNTRY_INDIA, LANGUAGE_TELUGU, false },
157 { COUNTRY_INDIA, LANGUAGE_SINDHI, false },
198 { COUNTRY_CROATIA, LANGUAGE_CROATIAN, true }, // sub type of LANGUAGE_SERBIAN
201 { COUNTRY_CZECH, LANGUAGE_CZECH, false },
219 { COUNTRY_LAOS, LANGUAGE_LAO, false },
236 { COUNTRY_NEPAL, LANGUAGE_NEPALI, false },
237 { COUNTRY_IRAN, LANGUAGE_FARSI, false },
244};
245
246const CountryEntry * const pEnd = pTable + std::size( pTable );
247
249struct CountryEntryPred_Country
250{
252
253 explicit CountryEntryPred_Country( CountryId eCountry ) :
254 meCountry( eCountry ) {}
255
256 bool operator()( const CountryEntry& rCmp ) const
257 { return rCmp.meCountry == meCountry; }
258};
259
264struct CountryEntryPred_Language
265{
267
268 explicit CountryEntryPred_Language( LanguageType eLanguage ) :
269 meLanguage( eLanguage ) {}
270
271 bool operator()( const CountryEntry& rCmp ) const;
272};
273
274bool CountryEntryPred_Language::operator()( const CountryEntry& rCmp ) const
275{
276 // rCmp.mbUseSubLang==true -> compare full language type
277 // rCmp.mbUseSubLang==false -> compare primary language only
278 return rCmp.mbUseSubLang ? (meLanguage == rCmp.meLanguage) :
279 (primary(meLanguage) == primary(rCmp.meLanguage));
280}
281
282} // namespace
283
284// Country ID <-> Language type conversion ====================================
285
287{
288 // country of a found primary language type
289 CountryId ePrimCountry = COUNTRY_DONTKNOW;
290
291 // find an exact match and a primary-language-only match, in one pass
292 const CountryEntry* pEntry = pTable;
293 do
294 {
295 pEntry = std::find_if( pEntry, pEnd, CountryEntryPred_Language( eLanguage ) );
296 if( pEntry != pEnd )
297 {
298 if( pEntry->mbUseSubLang )
299 return pEntry->meCountry; // exact match found -> return
300 if( ePrimCountry == COUNTRY_DONTKNOW )
301 ePrimCountry = pEntry->meCountry;
302 ++pEntry; // one entry forward for next find_if() call
303 }
304 }
305 while( pEntry != pEnd );
306
307 return ePrimCountry;
308}
309
311{
312 // just find the first occurrence of eCountry and return the language type
313 const CountryEntry* pEntry = std::find_if( pTable, pEnd, CountryEntryPred_Country( eCountry ) );
314 return (pEntry != pEnd) ? pEntry->meLanguage : LANGUAGE_DONTKNOW;
315}
316
317}
318
319/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool mbUseSubLang
Corresponding language type.
Definition: countryid.cxx:55
LanguageType meLanguage
Windows country ID.
Definition: countryid.cxx:54
CountryId meCountry
Definition: countryid.cxx:53
#define LANGUAGE_KIRGHIZ
#define LANGUAGE_ARMENIAN
#define LANGUAGE_GERMAN_AUSTRIAN
#define LANGUAGE_SANSKRIT
#define LANGUAGE_SPANISH_PARAGUAY
#define LANGUAGE_MANIPURI
#define LANGUAGE_KINYARWANDA_RWANDA
#define LANGUAGE_GERMAN_SWISS
#define LANGUAGE_SPANISH_BOLIVIA
#define LANGUAGE_VENDA
#define LANGUAGE_MALAY_MALAYSIA
#define LANGUAGE_LITHUANIAN
#define LANGUAGE_ROMANIAN
#define LANGUAGE_ENGLISH_AUS
#define LANGUAGE_CHINESE_TRADITIONAL
#define LANGUAGE_SPANISH_ECUADOR
#define LANGUAGE_FRENCH_LUXEMBOURG
#define LANGUAGE_PORTUGUESE
#define LANGUAGE_SORBIAN
#define LANGUAGE_GAELIC_IRELAND
#define LANGUAGE_HUNGARIAN
#define LANGUAGE_ARABIC_MOROCCO
#define LANGUAGE_FRENCH_CAMEROON
#define LANGUAGE_TIBETAN
#define LANGUAGE_THAI
#define LANGUAGE_ENGLISH_BELIZE
#define LANGUAGE_PUNJABI
#define LANGUAGE_SWEDISH_FINLAND
#define LANGUAGE_FRENCH_SENEGAL
#define LANGUAGE_BELARUSIAN
#define LANGUAGE_GERMAN_LUXEMBOURG
#define LANGUAGE_MACEDONIAN
#define LANGUAGE_FINNISH
#define LANGUAGE_BENGALI
#define LANGUAGE_SAMI_LAPPISH
#define LANGUAGE_NEPALI
#define LANGUAGE_ENGLISH_CAN
#define LANGUAGE_SWAHILI
#define LANGUAGE_CZECH
#define LANGUAGE_ITALIAN_SWISS
#define LANGUAGE_SPANISH_VENEZUELA
#define LANGUAGE_SESOTHO
#define LANGUAGE_FRENCH_SWISS
#define LANGUAGE_FRENCH
#define LANGUAGE_ITALIAN
#define LANGUAGE_ARABIC_UAE
#define LANGUAGE_DUTCH
#define LANGUAGE_FRENCH_MALI
#define LANGUAGE_GALICIAN
#define LANGUAGE_TURKMEN
#define LANGUAGE_ENGLISH_JAMAICA
#define LANGUAGE_ARABIC_TUNISIA
#define LANGUAGE_ICELANDIC
#define LANGUAGE_LAO
#define LANGUAGE_ARABIC_ALGERIA
#define LANGUAGE_KAZAKH
#define LANGUAGE_FRENCH_COTE_D_IVOIRE
#define LANGUAGE_SPANISH_COLOMBIA
#define LANGUAGE_CHINESE_SIMPLIFIED
#define LANGUAGE_SPANISH_PANAMA
#define LANGUAGE_ARABIC_JORDAN
#define LANGUAGE_SLOVAK
#define LANGUAGE_SPANISH_NICARAGUA
#define LANGUAGE_CATALAN
#define LANGUAGE_ODIA
#define LANGUAGE_ARABIC_IRAQ
#define LANGUAGE_TAMIL
#define LANGUAGE_SPANISH_GUATEMALA
#define LANGUAGE_SPANISH_COSTARICA
#define LANGUAGE_ZULU
#define LANGUAGE_JAPANESE
#define LANGUAGE_SPANISH_PERU
#define LANGUAGE_GREEK
#define LANGUAGE_GAELIC_SCOTLAND
#define LANGUAGE_CHINESE_SINGAPORE
#define LANGUAGE_ARABIC_EGYPT
#define LANGUAGE_FAEROESE
#define LANGUAGE_FRENCH_MONACO
#define LANGUAGE_RUSSIAN
#define LANGUAGE_CHINESE_MACAU
#define LANGUAGE_ENGLISH_EIRE
#define LANGUAGE_ARABIC_KUWAIT
#define LANGUAGE_MAORI_NEW_ZEALAND
#define LANGUAGE_RHAETO_ROMAN
#define LANGUAGE_SPANISH_CHILE
#define LANGUAGE_SPANISH_MODERN
#define LANGUAGE_KOREAN
#define LANGUAGE_ARABIC_LIBYA
#define LANGUAGE_SPANISH_EL_SALVADOR
#define LANGUAGE_ALBANIAN
#define LANGUAGE_ARABIC_LEBANON
#define LANGUAGE_SWEDISH
#define LANGUAGE_KONKANI
#define LANGUAGE_POLISH
#define LANGUAGE_ROMANIAN_MOLDOVA
#define LANGUAGE_BURMESE
#define LANGUAGE_ENGLISH_UK
#define LANGUAGE_DHIVEHI
#define LANGUAGE_ENGLISH_NZ
#define LANGUAGE_ASSAMESE
#define LANGUAGE_ENGLISH_ZIMBABWE
#define LANGUAGE_FRENCH_CANADIAN
#define LANGUAGE_UKRAINIAN
#define LANGUAGE_KHMER
#define LANGUAGE_SPANISH_DATED
#define LANGUAGE_SPANISH_PUERTO_RICO
#define LANGUAGE_FRISIAN_NETHERLANDS
#define LANGUAGE_VIETNAMESE
#define LANGUAGE_CHINESE_HONGKONG
#define LANGUAGE_TSONGA
#define LANGUAGE_ARABIC_QATAR
#define LANGUAGE_FRENCH_BELGIAN
#define LANGUAGE_ARABIC_SAUDI_ARABIA
#define LANGUAGE_DONTKNOW
#define LANGUAGE_HEBREW
#define LANGUAGE_DANISH
#define LANGUAGE_GERMAN
#define LANGUAGE_XHOSA
#define LANGUAGE_TSWANA
#define LANGUAGE_SPANISH_DOMINICAN_REPUBLIC
#define LANGUAGE_AFRIKAANS
#define LANGUAGE_HINDI
#define LANGUAGE_NORWEGIAN_BOKMAL
#define LANGUAGE_SPANISH_HONDURAS
#define LANGUAGE_ENGLISH_TRINIDAD
#define LANGUAGE_SINDHI
#define LANGUAGE_AZERI_LATIN
#define LANGUAGE_ENGLISH_SAFRICA
#define LANGUAGE_MALAY_BRUNEI_DARUSSALAM
#define LANGUAGE_ARABIC_OMAN
#define LANGUAGE_CROATIAN
#define LANGUAGE_GERMAN_LIECHTENSTEIN
#define LANGUAGE_SPANISH_ARGENTINA
#define LANGUAGE_KANNADA
#define LANGUAGE_MARATHI
#define LANGUAGE_MALAYALAM
constexpr LanguageType primary(LanguageType lt)
#define LANGUAGE_FRENCH_REUNION
#define LANGUAGE_ARABIC_YEMEN
#define LANGUAGE_SPANISH_MEXICAN
#define LANGUAGE_ENGLISH_PHILIPPINES
#define LANGUAGE_GEORGIAN
#define LANGUAGE_UZBEK_LATIN
#define LANGUAGE_PORTUGUESE_BRAZILIAN
#define LANGUAGE_URDU_INDIA
#define LANGUAGE_BULGARIAN
#define LANGUAGE_URDU_PAKISTAN
#define LANGUAGE_KASHMIRI
#define LANGUAGE_FARSI
#define LANGUAGE_TAJIK
#define LANGUAGE_DUTCH_BELGIAN
#define LANGUAGE_ESTONIAN
#define LANGUAGE_GUJARATI
#define LANGUAGE_SLOVENIAN
#define LANGUAGE_SPANISH_URUGUAY
#define LANGUAGE_SERBIAN_LATIN_SAM
#define LANGUAGE_ARABIC_SYRIA
#define LANGUAGE_WELSH
#define LANGUAGE_RUSSIAN_MOLDOVA
#define LANGUAGE_ARABIC_BAHRAIN
#define LANGUAGE_TURKISH
#define LANGUAGE_TELUGU
#define LANGUAGE_MONGOLIAN_CYRILLIC_MONGOLIA
#define LANGUAGE_ENGLISH_US
#define LANGUAGE_LATVIAN
#define LANGUAGE_MALTESE
#define LANGUAGE_FRENCH_ZAIRE
#define LANGUAGE_BASQUE
#define LANGUAGE_INDONESIAN
#define LANGUAGE_TATAR
const CountryId COUNTRY_ZIMBABWE
Definition: countryid.hxx:146
const CountryId COUNTRY_TUNISIA
Definition: countryid.hxx:101
const CountryId COUNTRY_IRAQ
Definition: countryid.hxx:240
const CountryId COUNTRY_ARGENTINA
Definition: countryid.hxx:76
const CountryId COUNTRY_RWANDA
Definition: countryid.hxx:133
const CountryId COUNTRY_VIET_NAM
Definition: countryid.hxx:90
const CountryId COUNTRY_INDONESIA
Definition: countryid.hxx:83
const CountryId COUNTRY_CHILE
Definition: countryid.hxx:78
const CountryId COUNTRY_ARMENIA
Definition: countryid.hxx:172
const CountryId COUNTRY_EGYPT
Definition: countryid.hxx:55
const CountryId COUNTRY_CANADA
Definition: countryid.hxx:51
const CountryId COUNTRY_FAEROE_ISLANDS
Definition: countryid.hxx:156
const CountryId COUNTRY_BOTSWANA
Definition: countryid.hxx:150
const CountryId COUNTRY_JAPAN
Definition: countryid.hxx:88
const CountryId COUNTRY_DENMARK
Definition: countryid.hxx:68
const CountryId COUNTRY_UAE
Definition: countryid.hxx:246
const CountryId COUNTRY_LESOTHO
Definition: countryid.hxx:149
const CountryId COUNTRY_CROATIA
Definition: countryid.hxx:180
const CountryId COUNTRY_HUNGARY
Definition: countryid.hxx:62
const CountryId COUNTRY_BRUNEI_DARUSSALAM
Definition: countryid.hxx:209
const CountryId COUNTRY_MALDIVES
Definition: countryid.hxx:236
const CountryId COUNTRY_GREECE
Definition: countryid.hxx:57
const CountryId COUNTRY_LIBYA
Definition: countryid.hxx:102
const CountryId COUNTRY_LATVIA
Definition: countryid.hxx:169
const CountryId COUNTRY_BELGIUM
Definition: countryid.hxx:59
const CountryId COUNTRY_OMAN
Definition: countryid.hxx:244
const CountryId COUNTRY_AZERBAIJAN
Definition: countryid.hxx:256
const CountryId COUNTRY_TAIWAN
Definition: countryid.hxx:235
const CountryId COUNTRY_LEBANON
Definition: countryid.hxx:237
const CountryId COUNTRY_ECUADOR
Definition: countryid.hxx:200
const CountryId COUNTRY_AUSTRIA
Definition: countryid.hxx:66
const CountryId COUNTRY_SWEDEN
Definition: countryid.hxx:69
const CountryId COUNTRY_PANAMA
Definition: countryid.hxx:194
const CountryId COUNTRY_URUGUAY
Definition: countryid.hxx:205
const CountryId COUNTRY_FRANCE
Definition: countryid.hxx:60
const CountryId COUNTRY_LUXEMBOURG
Definition: countryid.hxx:160
CountryId ConvertLanguageToCountry(LanguageType eLanguage)
Converts a language type to a Windows country ID.
Definition: countryid.cxx:286
const CountryId COUNTRY_MALTA
Definition: countryid.hxx:164
const CountryId COUNTRY_MOROCCO
Definition: countryid.hxx:99
const CountryId COUNTRY_PR_CHINA
Definition: countryid.hxx:91
const CountryId COUNTRY_SOUTH_KOREA
Definition: countryid.hxx:89
const CountryId COUNTRY_DOMINICAN_REPUBLIC
Definition: countryid.hxx:46
const CountryId COUNTRY_BANGLADESH
Definition: countryid.hxx:234
const CountryId COUNTRY_UZBEKISTAN
Definition: countryid.hxx:259
const CountryId COUNTRY_PORTUGAL
Definition: countryid.hxx:159
const CountryId COUNTRY_ISRAEL
Definition: countryid.hxx:247
const CountryId COUNTRY_SLOVAK
Definition: countryid.hxx:185
const CountryId COUNTRY_IRAN
Definition: countryid.hxx:253
const CountryId COUNTRY_ICELAND
Definition: countryid.hxx:162
const CountryId COUNTRY_MALI
Definition: countryid.hxx:106
const CountryId COUNTRY_NORWAY
Definition: countryid.hxx:70
const CountryId COUNTRY_MYANMAR
Definition: countryid.hxx:98
const CountryId COUNTRY_COTE_D_IVOIRE
Definition: countryid.hxx:108
const CountryId COUNTRY_PARAGUAY
Definition: countryid.hxx:202
const CountryId COUNTRY_JAMAICA
Definition: countryid.hxx:48
const CountryId COUNTRY_QATAR
Definition: countryid.hxx:249
const CountryId COUNTRY_DONTKNOW
Definition: countryid.hxx:44
const CountryId COUNTRY_SOUTH_AFRICA
Definition: countryid.hxx:56
const CountryId COUNTRY_NEW_ZEALAND
Definition: countryid.hxx:85
const CountryId COUNTRY_SERBIA
Definition: countryid.hxx:179
const CountryId COUNTRY_INDIA
Definition: countryid.hxx:94
const CountryId COUNTRY_ALBANIA
Definition: countryid.hxx:163
const CountryId COUNTRY_PUERTO_RICO
Definition: countryid.hxx:49
const CountryId COUNTRY_REUNION
Definition: countryid.hxx:145
const CountryId COUNTRY_SENEGAL
Definition: countryid.hxx:104
const CountryId COUNTRY_PAKISTAN
Definition: countryid.hxx:95
const CountryId COUNTRY_AUSTRALIA
Definition: countryid.hxx:82
const CountryId COUNTRY_EL_SALVADOR
Definition: countryid.hxx:190
const CountryId COUNTRY_MOLDOVA
Definition: countryid.hxx:171
const CountryId COUNTRY_MEXICO
Definition: countryid.hxx:74
const CountryId COUNTRY_FINLAND
Definition: countryid.hxx:166
const CountryId COUNTRY_YEMEN
Definition: countryid.hxx:243
const CountryId COUNTRY_JORDAN
Definition: countryid.hxx:238
const CountryId COUNTRY_UNITED_KINGDOM
Definition: countryid.hxx:67
const CountryId COUNTRY_SYRIA
Definition: countryid.hxx:239
const CountryId COUNTRY_ROMANIA
Definition: countryid.hxx:64
const CountryId COUNTRY_ALGERIA
Definition: countryid.hxx:100
const CountryId COUNTRY_COSTA_RICA
Definition: countryid.hxx:193
const CountryId COUNTRY_BRAZIL
Definition: countryid.hxx:77
const CountryId COUNTRY_NETHERLANDS
Definition: countryid.hxx:58
const CountryId COUNTRY_USA
Definition: countryid.hxx:45
const CountryId COUNTRY_BULGARIA
Definition: countryid.hxx:167
const CountryId COUNTRY_CAMEROON
Definition: countryid.hxx:120
const CountryId COUNTRY_TIBET
Definition: countryid.hxx:92
const CountryId COUNTRY_PHILIPPINES
Definition: countryid.hxx:84
const CountryId COUNTRY_SAUDI_ARABIA
Definition: countryid.hxx:242
const CountryId COUNTRY_SPAIN
Definition: countryid.hxx:61
const CountryId COUNTRY_VENEZUELA
Definition: countryid.hxx:80
const CountryId COUNTRY_SLOVENIA
Definition: countryid.hxx:181
const CountryId COUNTRY_ESTONIA
Definition: countryid.hxx:170
const CountryId COUNTRY_BAHRAIN
Definition: countryid.hxx:248
sal_uInt16 CountryId
Represents a Windows country ID.
Definition: countryid.hxx:42
const CountryId COUNTRY_MACEDONIA
Definition: countryid.hxx:183
const CountryId COUNTRY_GUATEMALA
Definition: countryid.hxx:189
const CountryId COUNTRY_SWITZERLAND
Definition: countryid.hxx:65
const CountryId COUNTRY_UKRAINE
Definition: countryid.hxx:178
const CountryId COUNTRY_KYRGYZSTAN
Definition: countryid.hxx:258
const CountryId COUNTRY_KENYA
Definition: countryid.hxx:137
const CountryId COUNTRY_NEPAL
Definition: countryid.hxx:252
const CountryId COUNTRY_GEORGIA
Definition: countryid.hxx:257
const CountryId COUNTRY_BELARUS
Definition: countryid.hxx:173
const CountryId COUNTRY_COLOMBIA
Definition: countryid.hxx:79
const CountryId COUNTRY_BOLIVIA
Definition: countryid.hxx:198
const CountryId COUNTRY_TURKEY
Definition: countryid.hxx:93
const CountryId COUNTRY_LITHUANIA
Definition: countryid.hxx:168
const CountryId COUNTRY_PERU
Definition: countryid.hxx:73
const CountryId COUNTRY_KUWAIT
Definition: countryid.hxx:241
const CountryId COUNTRY_SINGAPORE
Definition: countryid.hxx:86
const CountryId COUNTRY_TURKMENISTAN
Definition: countryid.hxx:255
const CountryId COUNTRY_GERMANY
Definition: countryid.hxx:72
const CountryId COUNTRY_RUSSIA
Definition: countryid.hxx:52
const CountryId COUNTRY_TAJIKISTAN
Definition: countryid.hxx:254
const CountryId COUNTRY_BELIZE
Definition: countryid.hxx:188
const CountryId COUNTRY_THAILAND
Definition: countryid.hxx:87
const CountryId COUNTRY_TATARSTAN
Definition: countryid.hxx:54
const CountryId COUNTRY_MALAYSIA
Definition: countryid.hxx:81
const CountryId COUNTRY_ITALY
Definition: countryid.hxx:63
const CountryId COUNTRY_LAOS
Definition: countryid.hxx:233
const CountryId COUNTRY_CAMBODIA
Definition: countryid.hxx:232
const CountryId COUNTRY_TRINIDAD_Y_TOBAGO
Definition: countryid.hxx:50
const CountryId COUNTRY_ZAIRE
Definition: countryid.hxx:126
const CountryId COUNTRY_MACAU
Definition: countryid.hxx:231
const CountryId COUNTRY_HONG_KONG
Definition: countryid.hxx:230
const CountryId COUNTRY_LIECHTENSTEIN
Definition: countryid.hxx:186
const CountryId COUNTRY_CZECH
Definition: countryid.hxx:184
const CountryId COUNTRY_MONGOLIA
Definition: countryid.hxx:251
const CountryId COUNTRY_IRELAND
Definition: countryid.hxx:161
const CountryId COUNTRY_HONDURAS
Definition: countryid.hxx:191
const CountryId COUNTRY_MONACO
Definition: countryid.hxx:175
LanguageType ConvertCountryToLanguage(CountryId eCountry)
Converts a Windows country ID to a language type.
Definition: countryid.cxx:310
const CountryId COUNTRY_KAZAKHSTAN
Definition: countryid.hxx:53
const CountryId COUNTRY_NICARAGUA
Definition: countryid.hxx:192
const CountryId COUNTRY_POLAND
Definition: countryid.hxx:71