Bump version to 4.3-4
[LibreOffice.git] / i18npool / source / transliteration / textToPronounce_zh.cxx
blobcc2b8ee90da560bdbe2b03b9f561a5e5ea1ebf84
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 .
20 #include <rtl/ustring.hxx>
21 #include <rtl/ustrbuf.hxx>
23 #include <textToPronounce_zh.hxx>
25 using namespace com::sun::star::uno;
27 namespace com { namespace sun { namespace star { namespace i18n {
29 sal_Int16 SAL_CALL TextToPronounce_zh::getType() throw (RuntimeException, std::exception)
31 return TransliterationType::ONE_TO_ONE| TransliterationType::IGNORE;
34 const sal_Unicode* SAL_CALL
35 TextToPronounce_zh::getPronounce(const sal_Unicode ch)
37 static const sal_Unicode emptyString[]={0};
38 if (idx) {
39 sal_uInt16 address = idx[0][ch>>8];
40 if (address != 0xFFFF)
41 return &idx[2][idx[1][address + (ch & 0xFF)]];
43 return emptyString;
46 OUString SAL_CALL
47 TextToPronounce_zh::folding(const OUString & inStr, sal_Int32 startPos,
48 sal_Int32 nCount, Sequence< sal_Int32 > & offset) throw (RuntimeException, std::exception)
50 OUStringBuffer sb;
51 const sal_Unicode * chArr = inStr.getStr() + startPos;
53 if (startPos < 0)
54 throw RuntimeException();
56 if (startPos + nCount > inStr.getLength())
57 nCount = inStr.getLength() - startPos;
59 offset[0] = 0;
60 for (sal_Int32 i = 0; i < nCount; i++) {
61 OUString pron(getPronounce(chArr[i]));
62 sb.append(pron);
64 if (useOffset)
65 offset[i + 1] = offset[i] + pron.getLength();
67 return sb.makeStringAndClear();
70 OUString SAL_CALL
71 TextToPronounce_zh::transliterateChar2String( sal_Unicode inChar) throw(RuntimeException, std::exception)
73 return OUString(getPronounce(inChar));
76 sal_Unicode SAL_CALL
77 TextToPronounce_zh::transliterateChar2Char( sal_Unicode inChar) throw(RuntimeException, MultipleCharsOutputException, std::exception)
79 const sal_Unicode* pron=getPronounce(inChar);
80 if (!pron || !pron[0])
81 return 0;
82 if (pron[1])
83 throw MultipleCharsOutputException();
84 return *pron;
87 sal_Bool SAL_CALL
88 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)
92 sal_Int32 realCount;
93 int i; // loop variable
94 const sal_Unicode * s1, * s2;
95 const sal_Unicode *pron1, *pron2;
97 if (nCount1 + pos1 > str1.getLength())
98 nCount1 = str1.getLength() - pos1;
100 if (nCount2 + pos2 > str2.getLength())
101 nCount2 = str2.getLength() - pos2;
103 realCount = ((nCount1 > nCount2) ? nCount2 : nCount1);
105 s1 = str1.getStr() + pos1;
106 s2 = str2.getStr() + pos2;
107 for (i = 0; i < realCount; i++) {
108 pron1=getPronounce(*s1++);
109 pron2=getPronounce(*s2++);
110 if (pron1 != pron2) {
111 nMatch1 = nMatch2 = i;
112 return sal_False;
115 nMatch1 = nMatch2 = realCount;
116 return (nCount1 == nCount2);
119 #ifdef DISABLE_DYNLOADING
121 extern "C" {
123 sal_uInt16** get_zh_zhuyin();
124 sal_uInt16** get_zh_pinyin();
128 #endif
130 TextToPinyin_zh_CN::TextToPinyin_zh_CN() :
131 #ifndef DISABLE_DYNLOADING
132 TextToPronounce_zh("get_zh_pinyin")
133 #else
134 TextToPronounce_zh(get_zh_pinyin)
135 #endif
137 transliterationName = "ChineseCharacterToPinyin";
138 implementationName = "com.sun.star.i18n.Transliteration.TextToPinyin_zh_CN";
141 TextToChuyin_zh_TW::TextToChuyin_zh_TW() :
142 #ifndef DISABLE_DYNLOADING
143 TextToPronounce_zh("get_zh_zhuyin")
144 #else
145 TextToPronounce_zh(get_zh_zhuyin)
146 #endif
148 transliterationName = "ChineseCharacterToChuyin";
149 implementationName = "com.sun.star.i18n.Transliteration.TextToChuyin_zh_TW";
152 #ifndef DISABLE_DYNLOADING
154 extern "C" { static void SAL_CALL thisModule() {} }
156 TextToPronounce_zh::TextToPronounce_zh(const sal_Char* func_name)
158 #ifdef SAL_DLLPREFIX
159 OUString lib(SAL_DLLPREFIX"index_data" SAL_DLLEXTENSION);
160 #else
161 OUString lib("index_data" SAL_DLLEXTENSION);
162 #endif
163 hModule = osl_loadModuleRelative(
164 &thisModule, lib.pData, SAL_LOADMODULE_DEFAULT );
165 idx=NULL;
166 if (hModule) {
167 sal_uInt16** (*function)() = (sal_uInt16** (*)()) osl_getFunctionSymbol(hModule, OUString::createFromAscii(func_name).pData);
168 if (function)
169 idx=function();
173 #else
175 TextToPronounce_zh::TextToPronounce_zh(sal_uInt16 ** (*function)())
177 idx = function();
180 #endif
182 TextToPronounce_zh::~TextToPronounce_zh()
184 #ifndef DISABLE_DYNLOADING
185 if (hModule) osl_unloadModule(hModule);
186 #endif
188 } } } }
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */