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

Generated by: LCOV version 1.10