LCOV - code coverage report
Current view: top level - i18npool/source/collator - collator_unicode.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 71 0.0 %
Date: 2014-04-14 Functions: 0 10 0.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             :  * 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             : 
      20             : 
      21             : // generated list of languages
      22             : #include "lrl_include.hxx"
      23             : 
      24             : #include <rtl/ustrbuf.hxx>
      25             : #include <i18nlangtag/languagetag.hxx>
      26             : #include <i18nlangtag/languagetagicu.hxx>
      27             : #include <collator_unicode.hxx>
      28             : #include <localedata.hxx>
      29             : #include <com/sun/star/i18n/CollatorOptions.hpp>
      30             : #include <cppuhelper/supportsservice.hxx>
      31             : 
      32             : using namespace ::com::sun::star;
      33             : using namespace ::com::sun::star::lang;
      34             : using namespace ::com::sun::star::uno;
      35             : using namespace ::rtl;
      36             : 
      37             : namespace com { namespace sun { namespace star { namespace i18n {
      38             : 
      39           0 : Collator_Unicode::Collator_Unicode()
      40             : {
      41           0 :     implementationName = "com.sun.star.i18n.Collator_Unicode";
      42           0 :     collator = NULL;
      43           0 :     uca_base = NULL;
      44             : #ifndef DISABLE_DYNLOADING
      45           0 :     hModule = NULL;
      46             : #endif
      47           0 : }
      48             : 
      49           0 : Collator_Unicode::~Collator_Unicode()
      50             : {
      51           0 :     if (collator) delete collator;
      52           0 :     if (uca_base) delete uca_base;
      53             : #ifndef DISABLE_DYNLOADING
      54           0 :     if (hModule) osl_unloadModule(hModule);
      55             : #endif
      56           0 : }
      57             : 
      58             : #ifdef DISABLE_DYNLOADING
      59             : 
      60             : extern "C" {
      61             : 
      62             : // For DISABLE_DYNLOADING the generated functions have names that
      63             : // start with get_collator_data_ to avoid clashing with a few
      64             : // functions in the generated libindex_data that are called just
      65             : // get_zh_pinyin for instance.
      66             : 
      67             : const sal_uInt8* get_collator_data_ca_charset();
      68             : const sal_uInt8* get_collator_data_dz_charset();
      69             : const sal_uInt8* get_collator_data_hu_charset();
      70             : const sal_uInt8* get_collator_data_ja_charset();
      71             : const sal_uInt8* get_collator_data_ja_phonetic_alphanumeric_first();
      72             : const sal_uInt8* get_collator_data_ja_phonetic_alphanumeric_last();
      73             : const sal_uInt8* get_collator_data_ko_charset();
      74             : const sal_uInt8* get_collator_data_ku_alphanumeric();
      75             : const sal_uInt8* get_collator_data_ln_charset();
      76             : const sal_uInt8* get_collator_data_my_dictionary();
      77             : const sal_uInt8* get_collator_data_ne_charset();
      78             : const sal_uInt8* get_collator_data_sid_charset();
      79             : const sal_uInt8* get_collator_data_zh_TW_charset();
      80             : const sal_uInt8* get_collator_data_zh_TW_radical();
      81             : const sal_uInt8* get_collator_data_zh_TW_stroke();
      82             : const sal_uInt8* get_collator_data_zh_charset();
      83             : const sal_uInt8* get_collator_data_zh_pinyin();
      84             : const sal_uInt8* get_collator_data_zh_radical();
      85             : const sal_uInt8* get_collator_data_zh_stroke();
      86             : const sal_uInt8* get_collator_data_zh_zhuyin();
      87             : 
      88             : }
      89             : 
      90             : #endif
      91             : 
      92             : sal_Int32 SAL_CALL
      93           0 : Collator_Unicode::compareSubstring( const OUString& str1, sal_Int32 off1, sal_Int32 len1,
      94             :     const OUString& str2, sal_Int32 off2, sal_Int32 len2) throw(RuntimeException, std::exception)
      95             : {
      96           0 :     return collator->compare(reinterpret_cast<const UChar *>(str1.getStr()) + off1, len1, reinterpret_cast<const UChar *>(str2.getStr()) + off2, len2); // UChar != sal_Unicode in MinGW
      97             : }
      98             : 
      99             : sal_Int32 SAL_CALL
     100           0 : Collator_Unicode::compareString( const OUString& str1, const OUString& str2) throw(RuntimeException, std::exception)
     101             : {
     102           0 :     return collator->compare(reinterpret_cast<const UChar *>(str1.getStr()), reinterpret_cast<const UChar *>(str2.getStr()));   // UChar != sal_Unicode in MinGW
     103             : }
     104             : 
     105             : #ifndef DISABLE_DYNLOADING
     106             : 
     107           0 : extern "C" { static void SAL_CALL thisModule() {} }
     108             : 
     109             : #endif
     110             : 
     111             : sal_Int32 SAL_CALL
     112           0 : Collator_Unicode::loadCollatorAlgorithm(const OUString& rAlgorithm, const lang::Locale& rLocale, sal_Int32 options)
     113             :     throw(RuntimeException, std::exception)
     114             : {
     115           0 :     if (!collator) {
     116           0 :         UErrorCode status = U_ZERO_ERROR;
     117           0 :         OUString rule = LocaleDataImpl().getCollatorRuleByAlgorithm(rLocale, rAlgorithm);
     118           0 :         if (!rule.isEmpty()) {
     119           0 :             collator = new RuleBasedCollator(reinterpret_cast<const UChar *>(rule.getStr()), status);   // UChar != sal_Unicode in MinGW
     120           0 :             if (! U_SUCCESS(status)) throw RuntimeException();
     121             :         }
     122           0 :         if (!collator && OUString::createFromAscii(LOCAL_RULE_LANGS).indexOf(rLocale.Language) >= 0) {
     123           0 :             const sal_uInt8* (*func)() = NULL;
     124             : 
     125             : #ifndef DISABLE_DYNLOADING
     126           0 :             OUStringBuffer aBuf;
     127             : #ifdef SAL_DLLPREFIX
     128           0 :             aBuf.appendAscii(SAL_DLLPREFIX);
     129             : #endif
     130           0 :             aBuf.appendAscii( "collator_data" ).appendAscii( SAL_DLLEXTENSION );
     131           0 :             hModule = osl_loadModuleRelative( &thisModule, aBuf.makeStringAndClear().pData, SAL_LOADMODULE_DEFAULT );
     132           0 :             if (hModule) {
     133           0 :                 aBuf.appendAscii("get_").append(rLocale.Language).appendAscii("_");
     134           0 :                 if ( rLocale.Language == "zh" ) {
     135           0 :                     OUString func_base = aBuf.makeStringAndClear();
     136           0 :                     if (OUString("TW HK MO").indexOf(rLocale.Country) >= 0)
     137             :                         func=(const sal_uInt8* (*)()) osl_getFunctionSymbol(hModule,
     138           0 :                                     OUString(func_base + "TW_" + rAlgorithm).pData);
     139           0 :                     if (!func)
     140           0 :                         func=(const sal_uInt8* (*)()) osl_getFunctionSymbol(hModule, OUString(func_base + rAlgorithm).pData);
     141             :                 } else {
     142           0 :                     if ( rLocale.Language == "ja" ) {
     143             :                         // replace algorithm name to implementation name.
     144           0 :                         if (rAlgorithm == "phonetic (alphanumeric first)")
     145           0 :                             aBuf.appendAscii("phonetic_alphanumeric_first");
     146           0 :                         else if (rAlgorithm == "phonetic (alphanumeric last)")
     147           0 :                             aBuf.appendAscii("phonetic_alphanumeric_last");
     148             :                         else
     149           0 :                             aBuf.append(rAlgorithm);
     150             :                     } else {
     151           0 :                         aBuf.append(rAlgorithm);
     152             :                     }
     153           0 :                     func=(const sal_uInt8* (*)()) osl_getFunctionSymbol(hModule, aBuf.makeStringAndClear().pData);
     154             :                 }
     155             :             }
     156             : #else
     157             :             if ( rLocale.Language == "ca" ) {
     158             :                 if ( rAlgorithm == "charset" )
     159             :                     func = get_collator_data_ca_charset;
     160             :             } else if ( rLocale.Language == "dz" || rLocale.Language == "bo" ) {
     161             :                 // 'bo' Tibetan uses the same collation rules as 'dz' Dzongkha
     162             :                 if ( rAlgorithm == "charset" )
     163             :                     func = get_collator_data_dz_charset;
     164             :             } else if ( rLocale.Language == "hu" ) {
     165             :                 if ( rAlgorithm == "charset" )
     166             :                     func = get_collator_data_hu_charset;
     167             :             } else if ( rLocale.Language == "ja" ) {
     168             :                 if ( rAlgorithm == "charset" )
     169             :                     func = get_collator_data_ja_charset;
     170             :                 else if ( rAlgorithm == "phonetic (alphanumeric first)" )
     171             :                     func = get_collator_data_ja_phonetic_alphanumeric_first;
     172             :                 else if ( rAlgorithm == "phonetic (alphanumeric last)" )
     173             :                     func = get_collator_data_ja_phonetic_alphanumeric_last;
     174             :             } else if ( rLocale.Language == "ko" ) {
     175             :                 if ( rAlgorithm == "charset" )
     176             :                     func = get_collator_data_ko_charset;
     177             :             } else if ( rLocale.Language == "ku" ) {
     178             :                 if ( rAlgorithm == "alphanumeric" )
     179             :                     func = get_collator_data_ku_alphanumeric;
     180             :             } else if ( rLocale.Language == "ln" ) {
     181             :                 if ( rAlgorithm == "charset" )
     182             :                     func = get_collator_data_ln_charset;
     183             :             } else if ( rLocale.Language == "my" ) {
     184             :                 if ( rAlgorithm == "dictionary" )
     185             :                     func = get_collator_data_my_dictionary;
     186             :             } else if ( rLocale.Language == "ne" ) {
     187             :                 if ( rAlgorithm == "charset" )
     188             :                     func = get_collator_data_ne_charset;
     189             :             } else if ( rLocale.Language == "sid" ) {
     190             :                 if ( rAlgorithm == "charset" )
     191             :                     func = get_collator_data_sid_charset;
     192             :             } else if ( rLocale.Language == "zh" && (rLocale.Country == "TW" || rLocale.Country == "HK" || rLocale.Country == "MO") ) {
     193             :                 if ( rAlgorithm == "charset" )
     194             :                     func = get_collator_data_zh_TW_charset;
     195             :                 else if ( rAlgorithm == "radical" )
     196             :                     func = get_collator_data_zh_TW_radical;
     197             :                 else if ( rAlgorithm == "stroke" )
     198             :                     func = get_collator_data_zh_TW_stroke;
     199             :             } else if ( rLocale.Language == "zh" ) {
     200             :                 if ( rAlgorithm == "charset" )
     201             :                     func = get_collator_data_zh_charset;
     202             :                 else if ( rAlgorithm == "pinyin" )
     203             :                     func = get_collator_data_zh_pinyin;
     204             :                 else if ( rAlgorithm == "radical" )
     205             :                     func = get_collator_data_zh_radical;
     206             :                 else if ( rAlgorithm == "stroke" )
     207             :                     func = get_collator_data_zh_stroke;
     208             :                 else if ( rAlgorithm == "zhuyin" )
     209             :                     func = get_collator_data_zh_zhuyin;
     210             :             }
     211             : #endif
     212           0 :             if (func) {
     213           0 :                 const sal_uInt8* ruleImage=func();
     214           0 :                 uca_base = new RuleBasedCollator(static_cast<UChar*>(NULL), status);
     215           0 :                 if (! U_SUCCESS(status)) throw RuntimeException();
     216           0 :                 collator = new RuleBasedCollator(reinterpret_cast<const uint8_t*>(ruleImage), -1, uca_base, status);
     217           0 :                 if (! U_SUCCESS(status)) throw RuntimeException();
     218           0 :             }
     219             :         }
     220           0 :         if (!collator) {
     221             :             /** ICU collators are loaded using a locale only.
     222             :                 ICU uses Variant as collation algorithm name (like de__PHONEBOOK
     223             :                 locale), note the empty territory (Country) designator in this special
     224             :                 case here. The icu::Locale constructor changes the algorithm name to
     225             :                 uppercase itself, so we don't have to bother with that.
     226             :             */
     227           0 :             icu::Locale icuLocale( LanguageTagIcu::getIcuLocale( LanguageTag( rLocale), rAlgorithm));
     228             :             // load ICU collator
     229           0 :             collator = (RuleBasedCollator*) icu::Collator::createInstance(icuLocale, status);
     230           0 :             if (! U_SUCCESS(status)) throw RuntimeException();
     231           0 :         }
     232             :     }
     233             : 
     234           0 :     if (options & CollatorOptions::CollatorOptions_IGNORE_CASE_ACCENT)
     235           0 :         collator->setStrength(Collator::PRIMARY);
     236           0 :     else if (options & CollatorOptions::CollatorOptions_IGNORE_CASE)
     237           0 :         collator->setStrength(Collator::SECONDARY);
     238             :     else
     239           0 :         collator->setStrength(Collator::TERTIARY);
     240             : 
     241           0 :     return(0);
     242             : }
     243             : 
     244             : 
     245             : OUString SAL_CALL
     246           0 : Collator_Unicode::getImplementationName() throw( RuntimeException, std::exception )
     247             : {
     248           0 :     return OUString::createFromAscii(implementationName);
     249             : }
     250             : 
     251             : sal_Bool SAL_CALL
     252           0 : Collator_Unicode::supportsService(const OUString& rServiceName) throw( RuntimeException, std::exception )
     253             : {
     254           0 :     return cppu::supportsService(this, rServiceName);
     255             : }
     256             : 
     257             : Sequence< OUString > SAL_CALL
     258           0 : Collator_Unicode::getSupportedServiceNames() throw( RuntimeException, std::exception )
     259             : {
     260           0 :     Sequence< OUString > aRet(1);
     261           0 :     aRet[0] = OUString::createFromAscii(implementationName);
     262           0 :     return aRet;
     263             : }
     264             : 
     265             : } } } }
     266             : 
     267             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10