LCOV - code coverage report
Current view: top level - i18npool/source/indexentry - indexentrysupplier_asian.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 65 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 8 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             : #include <rtl/ustrbuf.hxx>
      22             : #include <indexentrysupplier_asian.hxx>
      23             : #include <data/indexdata_alphanumeric.h>
      24             : 
      25             : using namespace ::com::sun::star::uno;
      26             : using namespace ::com::sun::star::lang;
      27             : 
      28             : namespace com { namespace sun { namespace star { namespace i18n {
      29             : 
      30             : #ifndef DISABLE_DYNLOADING
      31             : 
      32           0 : extern "C" { static void SAL_CALL thisModule() {} }
      33             : 
      34             : #endif
      35             : 
      36           0 : IndexEntrySupplier_asian::IndexEntrySupplier_asian(
      37           0 :     const Reference < XComponentContext >& rxContext ) : IndexEntrySupplier_Common(rxContext)
      38             : {
      39           0 :     implementationName = "com.sun.star.i18n.IndexEntrySupplier_asian";
      40             : #ifndef DISABLE_DYNLOADING
      41             : #ifdef SAL_DLLPREFIX
      42           0 :     OUString lib(SAL_DLLPREFIX"index_data" SAL_DLLEXTENSION);
      43             : #else
      44             :     OUString lib("index_data" SAL_DLLEXTENSION);
      45             : #endif
      46             :     hModule = osl_loadModuleRelative(
      47           0 :         &thisModule, lib.pData, SAL_LOADMODULE_DEFAULT );
      48             : #endif
      49           0 : }
      50             : 
      51           0 : IndexEntrySupplier_asian::~IndexEntrySupplier_asian()
      52             : {
      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             : sal_uInt16** get_indexdata_ko_dict(sal_Int16*);
      63             : sal_uInt16** get_indexdata_zh_TW_radical(sal_Int16*);
      64             : sal_uInt16** get_indexdata_zh_TW_stroke(sal_Int16*);
      65             : sal_uInt16** get_indexdata_zh_pinyin(sal_Int16*);
      66             : sal_uInt16** get_indexdata_zh_radical(sal_Int16*);
      67             : sal_uInt16** get_indexdata_zh_stroke(sal_Int16*);
      68             : sal_uInt16** get_indexdata_zh_zhuyin(sal_Int16*);
      69             : 
      70             : sal_uInt16** get_ko_phonetic(sal_Int16*);
      71             : sal_uInt16** get_zh_pinyin(sal_Int16*);
      72             : sal_uInt16** get_zh_zhuyin(sal_Int16*);
      73             : 
      74             : }
      75             : 
      76             : #endif
      77             : 
      78             : OUString SAL_CALL
      79           0 : IndexEntrySupplier_asian::getIndexCharacter( const OUString& rIndexEntry,
      80             :     const Locale& rLocale, const OUString& rAlgorithm ) throw (RuntimeException, std::exception)
      81             : {
      82           0 :     sal_Int32 i=0;
      83           0 :     sal_uInt32 ch = rIndexEntry.iterateCodePoints(&i, 0);
      84             : 
      85           0 :     sal_uInt16** (*func)(sal_Int16*)=NULL;
      86             : #ifndef DISABLE_DYNLOADING
      87           0 :     if (hModule) {
      88           0 :         OUString get("get_indexdata_");
      89           0 :         if ( rLocale.Language == "zh" && OUString( "TW HK MO" ).indexOf(rLocale.Country) >= 0 )
      90           0 :             func=reinterpret_cast<sal_uInt16** (*)(sal_Int16*)>(osl_getFunctionSymbol(hModule, OUString(get+rLocale.Language+"_TW_"+rAlgorithm).pData));
      91           0 :         if (!func)
      92           0 :             func=reinterpret_cast<sal_uInt16** (*)(sal_Int16*)>(osl_getFunctionSymbol(hModule, OUString(get+rLocale.Language+"_"+rAlgorithm).pData));
      93             :     }
      94             : #else
      95             :     if ( rLocale.Language == "zh" && OUString( "TW HK MO" ).indexOf(rLocale.Country) >= 0 ) {
      96             :         if ( rAlgorithm == "radical" )
      97             :             func = get_indexdata_zh_TW_radical;
      98             :         else if ( rAlgorithm == "stroke" )
      99             :             func = get_indexdata_zh_TW_stroke;
     100             :     }
     101             :     if (!func) {
     102             :         if ( rLocale.Language == "ko" ) {
     103             :             if ( rAlgorithm == "dict" )
     104             :                 func = get_indexdata_ko_dict;
     105             :         } else if ( rLocale.Language == "zh" ) {
     106             :             if ( rAlgorithm == "pinyin" )
     107             :                 func = get_indexdata_zh_pinyin;
     108             :             else if ( rAlgorithm == "radical" )
     109             :                 func = get_indexdata_zh_radical;
     110             :             else if ( rAlgorithm == "stroke" )
     111             :                 func = get_indexdata_zh_stroke;
     112             :             else if ( rAlgorithm == "zhuyin" )
     113             :                 func = get_indexdata_zh_zhuyin;
     114             :         }
     115             :     }
     116             : #endif
     117           0 :     if (func) {
     118             :         sal_Int16 max_index;
     119           0 :         sal_uInt16** idx=func(&max_index);
     120           0 :         if (((sal_Int16)(ch >> 8)) <= max_index) {
     121           0 :             sal_uInt16 address=idx[0][ch >> 8];
     122           0 :             if (address != 0xFFFF) {
     123           0 :                 address=idx[1][address+(ch & 0xFF)];
     124           0 :                 return idx[2] ? OUString(&idx[2][address]) : OUString(address);
     125             :             }
     126             :         }
     127             :     }
     128             : 
     129             :     // using alphanumeric index for non-define stirng
     130           0 :     return OUString(&idxStr[(ch & 0xFFFFFF00) ? 0 : ch], 1);
     131             : }
     132             : 
     133             : OUString SAL_CALL
     134           0 : IndexEntrySupplier_asian::getIndexKey( const OUString& rIndexEntry,
     135             :     const OUString& rPhoneticEntry, const Locale& rLocale) throw (RuntimeException, std::exception)
     136             : {
     137           0 :     return getIndexCharacter(getEntry(rIndexEntry, rPhoneticEntry, rLocale), rLocale, aAlgorithm);
     138             : }
     139             : 
     140             : sal_Int16 SAL_CALL
     141           0 : IndexEntrySupplier_asian::compareIndexEntry(
     142             :     const OUString& rIndexEntry1, const OUString& rPhoneticEntry1, const Locale& rLocale1,
     143             :     const OUString& rIndexEntry2, const OUString& rPhoneticEntry2, const Locale& rLocale2 )
     144             :     throw (RuntimeException, std::exception)
     145             : {
     146           0 :     sal_Int32 result = collator->compareString(getEntry(rIndexEntry1, rPhoneticEntry1, rLocale1),
     147           0 :                                     getEntry(rIndexEntry2, rPhoneticEntry2, rLocale2));
     148             : 
     149             :     // equivalent of phonetic entries does not mean equivalent of index entries.
     150             :     // we have to continue comparing index entry here.
     151           0 :     if (result == 0 && usePhonetic && !rPhoneticEntry1.isEmpty() &&
     152           0 :             rLocale1.Language == rLocale2.Language && rLocale1.Country == rLocale2.Country &&
     153           0 :             rLocale1.Variant == rLocale2.Variant)
     154           0 :         result = collator->compareString(rIndexEntry1, rIndexEntry2);
     155           0 :     return sal::static_int_cast< sal_Int16 >(result); // result in { -1, 0, 1 }
     156             : }
     157             : 
     158             : OUString SAL_CALL
     159           0 : IndexEntrySupplier_asian::getPhoneticCandidate( const OUString& rIndexEntry,
     160             :         const Locale& rLocale ) throw (RuntimeException, std::exception)
     161             : {
     162           0 :     sal_uInt16 **(*func)(sal_Int16*)=NULL;
     163             : #ifndef DISABLE_DYNLOADING
     164           0 :     if (hModule) {
     165           0 :         const sal_Char *func_name=NULL;
     166           0 :         if ( rLocale.Language == "zh" )
     167           0 :             func_name=(OUString("TW HK MO").indexOf(rLocale.Country) >= 0) ?  "get_zh_zhuyin" : "get_zh_pinyin";
     168           0 :         else if ( rLocale.Language == "ko" )
     169           0 :             func_name="get_ko_phonetic";
     170           0 :         if (func_name)
     171           0 :             func=reinterpret_cast<sal_uInt16 **(*)(sal_Int16*)>(osl_getFunctionSymbol(hModule, OUString::createFromAscii(func_name).pData));
     172             :     }
     173             : #else
     174             :     if ( rLocale.Language == "zh" )
     175             :         func = (OUString("TW HK MO").indexOf(rLocale.Country) >= 0) ?  get_zh_zhuyin : get_zh_pinyin;
     176             :     else if ( rLocale.Language == "ko" )
     177             :         func = get_ko_phonetic;
     178             : 
     179             : #endif
     180           0 :     if (func) {
     181           0 :         OUStringBuffer candidate;
     182             :         sal_Int16 max_index;
     183           0 :         sal_uInt16** idx=func(&max_index);
     184           0 :         for (sal_Int32 i=0,j=0; i < rIndexEntry.getLength(); i=j) {
     185           0 :             sal_uInt32 ch = rIndexEntry.iterateCodePoints(&j, 1);
     186           0 :             if (((sal_Int16)(ch>>8)) <= max_index) {
     187           0 :                 sal_uInt16 address = idx[0][ch>>8];
     188           0 :                 if (address != 0xFFFF) {
     189           0 :                     address = idx[1][address + (ch & 0xFF)];
     190           0 :                     if ( i > 0 && rLocale.Language == "zh" )
     191           0 :                         candidate.appendAscii(" ");
     192           0 :                     if (idx[2])
     193           0 :                         candidate.append(&idx[2][address]);
     194             :                     else
     195           0 :                         candidate.append(address);
     196             :                 } else
     197           0 :                     candidate.appendAscii(" ");
     198             :             }
     199             :         }
     200           0 :         return candidate.makeStringAndClear();
     201             :     }
     202           0 :     return OUString();
     203             : }
     204             : } } } }
     205             : 
     206             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11