bump product version to 6.3.0.0.beta1
[LibreOffice.git] / i18npool / source / transliteration / textToPronounce_zh.cxx
blob9e84ed90320d0d523d1f2233a76377b2474e5492
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 <sal/config.h>
22 #include <com/sun/star/i18n/MultipleCharsOutputException.hpp>
23 #include <com/sun/star/i18n/TransliterationType.hpp>
24 #include <rtl/ustring.hxx>
25 #include <rtl/ustrbuf.hxx>
27 #include <textToPronounce_zh.hxx>
29 using namespace com::sun::star::i18n;
30 using namespace com::sun::star::uno;
32 namespace i18npool {
34 sal_Int16 SAL_CALL TextToPronounce_zh::getType()
36 return TransliterationType::ONE_TO_ONE| TransliterationType::IGNORE;
39 const sal_Unicode*
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 reinterpret_cast<sal_Unicode *>(
47 &idx[2][idx[1][address + (ch & 0xFF)]]);
49 return emptyString;
52 OUString
53 TextToPronounce_zh::foldingImpl(const OUString & inStr, sal_Int32 startPos,
54 sal_Int32 nCount, Sequence< sal_Int32 > & offset, bool useOffset)
56 OUStringBuffer sb;
57 const sal_Unicode * chArr = inStr.getStr() + startPos;
59 if (startPos < 0)
60 throw RuntimeException();
62 if (startPos + nCount > inStr.getLength())
63 nCount = inStr.getLength() - startPos;
65 offset[0] = 0;
66 for (sal_Int32 i = 0; i < nCount; i++) {
67 OUString pron(getPronounce(chArr[i]));
68 sb.append(pron);
70 if (useOffset)
71 offset[i + 1] = offset[i] + pron.getLength();
73 return sb.makeStringAndClear();
76 OUString SAL_CALL
77 TextToPronounce_zh::transliterateChar2String( sal_Unicode inChar)
79 return OUString(getPronounce(inChar));
82 sal_Unicode SAL_CALL
83 TextToPronounce_zh::transliterateChar2Char( sal_Unicode inChar)
85 const sal_Unicode* pron=getPronounce(inChar);
86 if (!pron || !pron[0])
87 return 0;
88 if (pron[1])
89 throw MultipleCharsOutputException();
90 return *pron;
93 sal_Bool SAL_CALL
94 TextToPronounce_zh::equals( const OUString & str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32 & nMatch1,
95 const OUString & str2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32 & nMatch2)
97 sal_Int32 realCount;
98 int i; // loop variable
99 const sal_Unicode * s1, * s2;
101 if (nCount1 + pos1 > str1.getLength())
102 nCount1 = str1.getLength() - pos1;
104 if (nCount2 + pos2 > str2.getLength())
105 nCount2 = str2.getLength() - pos2;
107 realCount = std::min(nCount1, nCount2);
109 s1 = str1.getStr() + pos1;
110 s2 = str2.getStr() + pos2;
111 for (i = 0; i < realCount; i++) {
112 const sal_Unicode *pron1 = getPronounce(*s1++);
113 const sal_Unicode *pron2 = getPronounce(*s2++);
114 if (pron1 != pron2) {
115 nMatch1 = nMatch2 = i;
116 return false;
119 nMatch1 = nMatch2 = realCount;
120 return (nCount1 == nCount2);
123 #ifdef DISABLE_DYNLOADING
125 extern "C" {
127 sal_uInt16** get_zh_zhuyin();
128 sal_uInt16** get_zh_pinyin();
132 #endif
134 TextToPinyin_zh_CN::TextToPinyin_zh_CN() :
135 #ifndef DISABLE_DYNLOADING
136 TextToPronounce_zh("get_zh_pinyin")
137 #else
138 TextToPronounce_zh(get_zh_pinyin)
139 #endif
141 transliterationName = "ChineseCharacterToPinyin";
142 implementationName = "com.sun.star.i18n.Transliteration.TextToPinyin_zh_CN";
145 TextToChuyin_zh_TW::TextToChuyin_zh_TW() :
146 #ifndef DISABLE_DYNLOADING
147 TextToPronounce_zh("get_zh_zhuyin")
148 #else
149 TextToPronounce_zh(get_zh_zhuyin)
150 #endif
152 transliterationName = "ChineseCharacterToChuyin";
153 implementationName = "com.sun.star.i18n.Transliteration.TextToChuyin_zh_TW";
156 #ifndef DISABLE_DYNLOADING
158 extern "C" { static void thisModule() {} }
160 TextToPronounce_zh::TextToPronounce_zh(const sal_Char* func_name)
162 #ifdef SAL_DLLPREFIX
163 OUString lib(SAL_DLLPREFIX"index_data" SAL_DLLEXTENSION);
164 #else
165 OUString lib("index_data" SAL_DLLEXTENSION);
166 #endif
167 hModule = osl_loadModuleRelative(
168 &thisModule, lib.pData, SAL_LOADMODULE_DEFAULT );
169 idx=nullptr;
170 if (hModule) {
171 sal_uInt16** (*function)() = reinterpret_cast<sal_uInt16** (*)()>(osl_getFunctionSymbol(hModule, OUString::createFromAscii(func_name).pData));
172 if (function)
173 idx=function();
177 #else
179 TextToPronounce_zh::TextToPronounce_zh(sal_uInt16 ** (*function)())
181 idx = function();
184 #endif
186 TextToPronounce_zh::~TextToPronounce_zh()
188 #ifndef DISABLE_DYNLOADING
189 if (hModule) osl_unloadModule(hModule);
190 #endif
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */