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