bump product version to 4.1.6.2
[LibreOffice.git] / i18npool / source / transliteration / textToPronounce_zh.cxx
blob7d1898e703e08a0bae4b33deabfa85ef1cc4da6b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 // prevent internal compiler error with MSVC6SP3
22 #include <utility>
24 #include <rtl/string.hxx>
25 #include <rtl/ustrbuf.hxx>
26 #define TRANSLITERATION_ALL
27 #include <textToPronounce_zh.hxx>
29 using namespace com::sun::star::uno;
32 namespace com { namespace sun { namespace star { namespace i18n {
34 sal_Int16 SAL_CALL TextToPronounce_zh::getType() throw (RuntimeException)
36 return TransliterationType::ONE_TO_ONE| TransliterationType::IGNORE;
39 const sal_Unicode* SAL_CALL
40 TextToPronounce_zh::getPronounce(const sal_Unicode ch)
42 static const sal_Unicode emptyString[]={0};
43 if (idx) {
44 sal_uInt16 address = idx[0][ch>>8];
45 if (address != 0xFFFF)
46 return &idx[2][idx[1][address + (ch & 0xFF)]];
48 return emptyString;
51 OUString SAL_CALL
52 TextToPronounce_zh::folding(const OUString & inStr, sal_Int32 startPos,
53 sal_Int32 nCount, Sequence< sal_Int32 > & offset) throw (RuntimeException)
55 OUStringBuffer sb;
56 const sal_Unicode * chArr = inStr.getStr() + startPos;
58 if (startPos < 0)
59 throw RuntimeException();
61 if (startPos + nCount > inStr.getLength())
62 nCount = inStr.getLength() - startPos;
64 offset[0] = 0;
65 for (sal_Int32 i = 0; i < nCount; i++) {
66 OUString pron(getPronounce(chArr[i]));
67 sb.append(pron);
69 if (useOffset)
70 offset[i + 1] = offset[i] + pron.getLength();
72 return sb.makeStringAndClear();
75 OUString SAL_CALL
76 TextToPronounce_zh::transliterateChar2String( sal_Unicode inChar) throw(RuntimeException)
78 return OUString(getPronounce(inChar));
81 sal_Unicode SAL_CALL
82 TextToPronounce_zh::transliterateChar2Char( sal_Unicode inChar) throw(RuntimeException, MultipleCharsOutputException)
84 const sal_Unicode* pron=getPronounce(inChar);
85 if (!pron || !pron[0])
86 return 0;
87 if (pron[1])
88 throw MultipleCharsOutputException();
89 return *pron;
92 sal_Bool SAL_CALL
93 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)
97 sal_Int32 realCount;
98 int i; // loop variable
99 const sal_Unicode * s1, * s2;
100 const sal_Unicode *pron1, *pron2;
102 if (nCount1 + pos1 > str1.getLength())
103 nCount1 = str1.getLength() - pos1;
105 if (nCount2 + pos2 > str2.getLength())
106 nCount2 = str2.getLength() - pos2;
108 realCount = ((nCount1 > nCount2) ? nCount2 : nCount1);
110 s1 = str1.getStr() + pos1;
111 s2 = str2.getStr() + pos2;
112 for (i = 0; i < realCount; i++) {
113 pron1=getPronounce(*s1++);
114 pron2=getPronounce(*s2++);
115 if (pron1 != pron2) {
116 nMatch1 = nMatch2 = i;
117 return sal_False;
120 nMatch1 = nMatch2 = realCount;
121 return (nCount1 == nCount2);
124 #ifdef DISABLE_DYNLOADING
126 extern "C" {
128 sal_uInt16** get_zh_zhuyin();
129 sal_uInt16** get_zh_pinyin();
133 #endif
135 TextToPinyin_zh_CN::TextToPinyin_zh_CN() :
136 #ifndef DISABLE_DYNLOADING
137 TextToPronounce_zh("get_zh_pinyin")
138 #else
139 TextToPronounce_zh(get_zh_pinyin)
140 #endif
142 transliterationName = "ChineseCharacterToPinyin";
143 implementationName = "com.sun.star.i18n.Transliteration.TextToPinyin_zh_CN";
146 TextToChuyin_zh_TW::TextToChuyin_zh_TW() :
147 #ifndef DISABLE_DYNLOADING
148 TextToPronounce_zh("get_zh_zhuyin")
149 #else
150 TextToPronounce_zh(get_zh_zhuyin)
151 #endif
153 transliterationName = "ChineseCharacterToChuyin";
154 implementationName = "com.sun.star.i18n.Transliteration.TextToChuyin_zh_TW";
157 #ifndef DISABLE_DYNLOADING
159 extern "C" { static void SAL_CALL thisModule() {} }
161 TextToPronounce_zh::TextToPronounce_zh(const sal_Char* func_name)
163 #ifdef SAL_DLLPREFIX
164 OUString lib(SAL_DLLPREFIX"index_data" SAL_DLLEXTENSION);
165 #else
166 OUString lib("index_data" SAL_DLLEXTENSION);
167 #endif
168 hModule = osl_loadModuleRelative(
169 &thisModule, lib.pData, SAL_LOADMODULE_DEFAULT );
170 idx=NULL;
171 if (hModule) {
172 sal_uInt16** (*function)() = (sal_uInt16** (*)()) osl_getFunctionSymbol(hModule, OUString::createFromAscii(func_name).pData);
173 if (function)
174 idx=function();
178 #else
180 TextToPronounce_zh::TextToPronounce_zh(sal_uInt16 ** (*function)())
182 idx = function();
185 #endif
187 TextToPronounce_zh::~TextToPronounce_zh()
189 #ifndef DISABLE_DYNLOADING
190 if (hModule) osl_unloadModule(hModule);
191 #endif
193 } } } }
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */