LCOV - code coverage report
Current view: top level - i18npool/source/transliteration - textToPronounce_zh.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 72 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 12 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             : #include <rtl/ustring.hxx>
      21             : #include <rtl/ustrbuf.hxx>
      22             : 
      23             : #include <textToPronounce_zh.hxx>
      24             : 
      25             : using namespace com::sun::star::uno;
      26             : 
      27             : namespace com { namespace sun { namespace star { namespace i18n {
      28             : 
      29           0 : sal_Int16 SAL_CALL TextToPronounce_zh::getType() throw (RuntimeException, std::exception)
      30             : {
      31           0 :     return TransliterationType::ONE_TO_ONE| TransliterationType::IGNORE;
      32             : }
      33             : 
      34             : const sal_Unicode* SAL_CALL
      35           0 : TextToPronounce_zh::getPronounce(const sal_Unicode ch)
      36             : {
      37             :     static const sal_Unicode emptyString[]={0};
      38           0 :     if (idx) {
      39           0 :         sal_uInt16 address = idx[0][ch>>8];
      40           0 :         if (address != 0xFFFF)
      41           0 :             return &idx[2][idx[1][address + (ch & 0xFF)]];
      42             :     }
      43           0 :     return emptyString;
      44             : }
      45             : 
      46             : OUString SAL_CALL
      47           0 : TextToPronounce_zh::folding(const OUString & inStr, sal_Int32 startPos,
      48             :         sal_Int32 nCount, Sequence< sal_Int32 > & offset) throw (RuntimeException, std::exception)
      49             : {
      50           0 :     OUStringBuffer sb;
      51           0 :     const sal_Unicode * chArr = inStr.getStr() + startPos;
      52             : 
      53           0 :     if (startPos < 0)
      54           0 :         throw RuntimeException();
      55             : 
      56           0 :     if (startPos + nCount > inStr.getLength())
      57           0 :         nCount = inStr.getLength() - startPos;
      58             : 
      59           0 :     offset[0] = 0;
      60           0 :     for (sal_Int32 i = 0; i < nCount; i++) {
      61           0 :         OUString pron(getPronounce(chArr[i]));
      62           0 :         sb.append(pron);
      63             : 
      64           0 :         if (useOffset)
      65           0 :             offset[i + 1] = offset[i] + pron.getLength();
      66           0 :     }
      67           0 :     return sb.makeStringAndClear();
      68             : }
      69             : 
      70             : OUString SAL_CALL
      71           0 : TextToPronounce_zh::transliterateChar2String( sal_Unicode inChar) throw(RuntimeException, std::exception)
      72             : {
      73           0 :     return OUString(getPronounce(inChar));
      74             : }
      75             : 
      76             : sal_Unicode SAL_CALL
      77           0 : TextToPronounce_zh::transliterateChar2Char( sal_Unicode inChar) throw(RuntimeException, MultipleCharsOutputException, std::exception)
      78             : {
      79           0 :     const sal_Unicode* pron=getPronounce(inChar);
      80           0 :     if (!pron || !pron[0])
      81           0 :         return 0;
      82           0 :     if (pron[1])
      83           0 :         throw MultipleCharsOutputException();
      84           0 :     return *pron;
      85             : }
      86             : 
      87             : sal_Bool SAL_CALL
      88           0 : TextToPronounce_zh::equals( const OUString & str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32 & nMatch1,
      89             :         const OUString & str2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32 & nMatch2)
      90             :         throw (RuntimeException, std::exception)
      91             : {
      92             :     sal_Int32 realCount;
      93             :     int i;  // loop variable
      94             :     const sal_Unicode * s1, * s2;
      95             : 
      96           0 :     if (nCount1 + pos1 > str1.getLength())
      97           0 :         nCount1 = str1.getLength() - pos1;
      98             : 
      99           0 :     if (nCount2 + pos2 > str2.getLength())
     100           0 :         nCount2 = str2.getLength() - pos2;
     101             : 
     102           0 :     realCount = ((nCount1 > nCount2) ? nCount2 : nCount1);
     103             : 
     104           0 :     s1 = str1.getStr() + pos1;
     105           0 :     s2 = str2.getStr() + pos2;
     106           0 :     for (i = 0; i < realCount; i++) {
     107           0 :         const sal_Unicode *pron1 = getPronounce(*s1++);
     108           0 :         const sal_Unicode *pron2 = getPronounce(*s2++);
     109           0 :         if (pron1 != pron2) {
     110           0 :             nMatch1 = nMatch2 = i;
     111           0 :             return sal_False;
     112             :         }
     113             :     }
     114           0 :     nMatch1 = nMatch2 = realCount;
     115           0 :     return (nCount1 == nCount2);
     116             : }
     117             : 
     118             : #ifdef DISABLE_DYNLOADING
     119             : 
     120             : extern "C" {
     121             : 
     122             : sal_uInt16** get_zh_zhuyin();
     123             : sal_uInt16** get_zh_pinyin();
     124             : 
     125             : }
     126             : 
     127             : #endif
     128             : 
     129           0 : TextToPinyin_zh_CN::TextToPinyin_zh_CN() :
     130             : #ifndef DISABLE_DYNLOADING
     131           0 :     TextToPronounce_zh("get_zh_pinyin")
     132             : #else
     133             :     TextToPronounce_zh(get_zh_pinyin)
     134             : #endif
     135             : {
     136           0 :         transliterationName = "ChineseCharacterToPinyin";
     137           0 :         implementationName = "com.sun.star.i18n.Transliteration.TextToPinyin_zh_CN";
     138           0 : }
     139             : 
     140           0 : TextToChuyin_zh_TW::TextToChuyin_zh_TW() :
     141             : #ifndef DISABLE_DYNLOADING
     142           0 :     TextToPronounce_zh("get_zh_zhuyin")
     143             : #else
     144             :     TextToPronounce_zh(get_zh_zhuyin)
     145             : #endif
     146             : {
     147           0 :         transliterationName = "ChineseCharacterToChuyin";
     148           0 :         implementationName = "com.sun.star.i18n.Transliteration.TextToChuyin_zh_TW";
     149           0 : }
     150             : 
     151             : #ifndef DISABLE_DYNLOADING
     152             : 
     153           0 : extern "C" { static void SAL_CALL thisModule() {} }
     154             : 
     155           0 : TextToPronounce_zh::TextToPronounce_zh(const sal_Char* func_name)
     156             : {
     157             : #ifdef SAL_DLLPREFIX
     158           0 :     OUString lib(SAL_DLLPREFIX"index_data" SAL_DLLEXTENSION);
     159             : #else
     160             :     OUString lib("index_data" SAL_DLLEXTENSION);
     161             : #endif
     162             :     hModule = osl_loadModuleRelative(
     163           0 :         &thisModule, lib.pData, SAL_LOADMODULE_DEFAULT );
     164           0 :     idx=NULL;
     165           0 :     if (hModule) {
     166           0 :         sal_uInt16** (*function)() = reinterpret_cast<sal_uInt16** (*)()>(osl_getFunctionSymbol(hModule, OUString::createFromAscii(func_name).pData));
     167           0 :         if (function)
     168           0 :             idx=function();
     169           0 :     }
     170           0 : }
     171             : 
     172             : #else
     173             : 
     174             : TextToPronounce_zh::TextToPronounce_zh(sal_uInt16 ** (*function)())
     175             : {
     176             :     idx = function();
     177             : }
     178             : 
     179             : #endif
     180             : 
     181           0 : TextToPronounce_zh::~TextToPronounce_zh()
     182             : {
     183             : #ifndef DISABLE_DYNLOADING
     184           0 :     if (hModule) osl_unloadModule(hModule);
     185             : #endif
     186           0 : }
     187             : } } } }
     188             : 
     189             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11