1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_i18npool.hxx" 30 31 // prevent internal compiler error with MSVC6SP3 32 #include <utility> 33 34 #include <rtl/string.hxx> 35 #include <rtl/ustrbuf.hxx> 36 #define TRANSLITERATION_ALL 37 #include <textToPronounce_zh.hxx> 38 39 using namespace com::sun::star::uno; 40 using namespace rtl; 41 42 namespace com { namespace sun { namespace star { namespace i18n { 43 44 sal_Int16 SAL_CALL TextToPronounce_zh::getType() throw (RuntimeException) 45 { 46 return TransliterationType::ONE_TO_ONE| TransliterationType::IGNORE; 47 } 48 49 const sal_Unicode* SAL_CALL 50 TextToPronounce_zh::getPronounce(const sal_Unicode ch) 51 { 52 static const sal_Unicode emptyString[]={0}; 53 if (idx) { 54 sal_uInt16 address = idx[0][ch>>8]; 55 if (address != 0xFFFF) 56 return &idx[2][idx[1][address + (ch & 0xFF)]]; 57 } 58 return emptyString; 59 } 60 61 OUString SAL_CALL 62 TextToPronounce_zh::folding(const OUString & inStr, sal_Int32 startPos, 63 sal_Int32 nCount, Sequence< sal_Int32 > & offset) throw (RuntimeException) 64 { 65 OUStringBuffer sb; 66 const sal_Unicode * chArr = inStr.getStr() + startPos; 67 68 if (startPos < 0) 69 throw RuntimeException(); 70 71 if (startPos + nCount > inStr.getLength()) 72 nCount = inStr.getLength() - startPos; 73 74 offset[0] = 0; 75 for (sal_Int32 i = 0; i < nCount; i++) { 76 OUString pron(getPronounce(chArr[i])); 77 sb.append(pron); 78 79 if (useOffset) 80 offset[i + 1] = offset[i] + pron.getLength(); 81 } 82 return sb.makeStringAndClear(); 83 } 84 85 OUString SAL_CALL 86 TextToPronounce_zh::transliterateChar2String( sal_Unicode inChar) throw(RuntimeException) 87 { 88 return OUString(getPronounce(inChar)); 89 } 90 91 sal_Unicode SAL_CALL 92 TextToPronounce_zh::transliterateChar2Char( sal_Unicode inChar) throw(RuntimeException, MultipleCharsOutputException) 93 { 94 const sal_Unicode* pron=getPronounce(inChar); 95 if (!pron || !pron[0]) 96 return 0; 97 if (pron[1]) 98 throw MultipleCharsOutputException(); 99 return *pron; 100 } 101 102 sal_Bool SAL_CALL 103 TextToPronounce_zh::equals( const OUString & str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32 & nMatch1, 104 const OUString & str2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32 & nMatch2) 105 throw (RuntimeException) 106 { 107 sal_Int32 realCount; 108 int i; // loop variable 109 const sal_Unicode * s1, * s2; 110 const sal_Unicode *pron1, *pron2; 111 112 if (nCount1 + pos1 > str1.getLength()) 113 nCount1 = str1.getLength() - pos1; 114 115 if (nCount2 + pos2 > str2.getLength()) 116 nCount2 = str2.getLength() - pos2; 117 118 realCount = ((nCount1 > nCount2) ? nCount2 : nCount1); 119 120 s1 = str1.getStr() + pos1; 121 s2 = str2.getStr() + pos2; 122 for (i = 0; i < realCount; i++) { 123 pron1=getPronounce(*s1++); 124 pron2=getPronounce(*s2++); 125 if (pron1 != pron2) { 126 nMatch1 = nMatch2 = i; 127 return sal_False; 128 } 129 } 130 nMatch1 = nMatch2 = realCount; 131 return (nCount1 == nCount2); 132 } 133 134 TextToPinyin_zh_CN::TextToPinyin_zh_CN() : TextToPronounce_zh("get_zh_pinyin") 135 { 136 transliterationName = "ChineseCharacterToPinyin"; 137 implementationName = "com.sun.star.i18n.Transliteration.TextToPinyin_zh_CN"; 138 } 139 140 TextToChuyin_zh_TW::TextToChuyin_zh_TW() : TextToPronounce_zh("get_zh_zhuyin") 141 { 142 transliterationName = "ChineseCharacterToChuyin"; 143 implementationName = "com.sun.star.i18n.Transliteration.TextToChuyin_zh_TW"; 144 } 145 146 extern "C" { static void SAL_CALL thisModule() {} } 147 148 TextToPronounce_zh::TextToPronounce_zh(const sal_Char* func_name) 149 { 150 #ifdef SAL_DLLPREFIX 151 OUString lib=OUString::createFromAscii(SAL_DLLPREFIX"index_data"SAL_DLLEXTENSION); 152 #else 153 OUString lib=OUString::createFromAscii("index_data"SAL_DLLEXTENSION); 154 #endif 155 hModule = osl_loadModuleRelative( 156 &thisModule, lib.pData, SAL_LOADMODULE_DEFAULT ); 157 idx=NULL; 158 if (hModule) { 159 sal_uInt16** (*function)() = (sal_uInt16** (*)()) osl_getFunctionSymbol(hModule, OUString::createFromAscii(func_name).pData); 160 if (function) 161 idx=function(); 162 } 163 } 164 TextToPronounce_zh::~TextToPronounce_zh() 165 { 166 if (hModule) osl_unloadModule(hModule); 167 } 168 } } } } 169