Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <rtl/ustring.hxx>
21 : #include <rtl/ustrbuf.hxx>
22 :
23 : #include <textToPronounce_zh.hxx>
24 :
25 : using namespace com::sun::star::uno;
26 :
27 : namespace com { namespace sun { namespace star { namespace i18n {
28 :
29 0 : sal_Int16 SAL_CALL TextToPronounce_zh::getType() throw (RuntimeException, std::exception)
30 : {
31 0 : return TransliterationType::ONE_TO_ONE| TransliterationType::IGNORE;
32 : }
33 :
34 : const sal_Unicode* SAL_CALL
35 0 : TextToPronounce_zh::getPronounce(const sal_Unicode ch)
36 : {
37 : static const sal_Unicode emptyString[]={0};
38 0 : if (idx) {
39 0 : sal_uInt16 address = idx[0][ch>>8];
40 0 : if (address != 0xFFFF)
41 0 : return &idx[2][idx[1][address + (ch & 0xFF)]];
42 : }
43 0 : return emptyString;
44 : }
45 :
46 : OUString SAL_CALL
47 0 : TextToPronounce_zh::folding(const OUString & inStr, sal_Int32 startPos,
48 : sal_Int32 nCount, Sequence< sal_Int32 > & offset) throw (RuntimeException, std::exception)
49 : {
50 0 : OUStringBuffer sb;
51 0 : const sal_Unicode * chArr = inStr.getStr() + startPos;
52 :
53 0 : if (startPos < 0)
54 0 : throw RuntimeException();
55 :
56 0 : if (startPos + nCount > inStr.getLength())
57 0 : nCount = inStr.getLength() - startPos;
58 :
59 0 : offset[0] = 0;
60 0 : for (sal_Int32 i = 0; i < nCount; i++) {
61 0 : OUString pron(getPronounce(chArr[i]));
62 0 : sb.append(pron);
63 :
64 0 : if (useOffset)
65 0 : offset[i + 1] = offset[i] + pron.getLength();
66 0 : }
67 0 : return sb.makeStringAndClear();
68 : }
69 :
70 : OUString SAL_CALL
71 0 : TextToPronounce_zh::transliterateChar2String( sal_Unicode inChar) throw(RuntimeException, std::exception)
72 : {
73 0 : return OUString(getPronounce(inChar));
74 : }
75 :
76 : sal_Unicode SAL_CALL
77 0 : TextToPronounce_zh::transliterateChar2Char( sal_Unicode inChar) throw(RuntimeException, MultipleCharsOutputException, std::exception)
78 : {
79 0 : const sal_Unicode* pron=getPronounce(inChar);
80 0 : if (!pron || !pron[0])
81 0 : return 0;
82 0 : if (pron[1])
83 0 : throw MultipleCharsOutputException();
84 0 : return *pron;
85 : }
86 :
87 : sal_Bool SAL_CALL
88 0 : 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)
91 : {
92 : sal_Int32 realCount;
93 : int i; // loop variable
94 : const sal_Unicode * s1, * s2;
95 : const sal_Unicode *pron1, *pron2;
96 :
97 0 : if (nCount1 + pos1 > str1.getLength())
98 0 : nCount1 = str1.getLength() - pos1;
99 :
100 0 : if (nCount2 + pos2 > str2.getLength())
101 0 : nCount2 = str2.getLength() - pos2;
102 :
103 0 : realCount = ((nCount1 > nCount2) ? nCount2 : nCount1);
104 :
105 0 : s1 = str1.getStr() + pos1;
106 0 : s2 = str2.getStr() + pos2;
107 0 : for (i = 0; i < realCount; i++) {
108 0 : pron1=getPronounce(*s1++);
109 0 : pron2=getPronounce(*s2++);
110 0 : if (pron1 != pron2) {
111 0 : nMatch1 = nMatch2 = i;
112 0 : return sal_False;
113 : }
114 : }
115 0 : nMatch1 = nMatch2 = realCount;
116 0 : return (nCount1 == nCount2);
117 : }
118 :
119 : #ifdef DISABLE_DYNLOADING
120 :
121 : extern "C" {
122 :
123 : sal_uInt16** get_zh_zhuyin();
124 : sal_uInt16** get_zh_pinyin();
125 :
126 : }
127 :
128 : #endif
129 :
130 0 : TextToPinyin_zh_CN::TextToPinyin_zh_CN() :
131 : #ifndef DISABLE_DYNLOADING
132 0 : TextToPronounce_zh("get_zh_pinyin")
133 : #else
134 : TextToPronounce_zh(get_zh_pinyin)
135 : #endif
136 : {
137 0 : transliterationName = "ChineseCharacterToPinyin";
138 0 : implementationName = "com.sun.star.i18n.Transliteration.TextToPinyin_zh_CN";
139 0 : }
140 :
141 0 : TextToChuyin_zh_TW::TextToChuyin_zh_TW() :
142 : #ifndef DISABLE_DYNLOADING
143 0 : TextToPronounce_zh("get_zh_zhuyin")
144 : #else
145 : TextToPronounce_zh(get_zh_zhuyin)
146 : #endif
147 : {
148 0 : transliterationName = "ChineseCharacterToChuyin";
149 0 : implementationName = "com.sun.star.i18n.Transliteration.TextToChuyin_zh_TW";
150 0 : }
151 :
152 : #ifndef DISABLE_DYNLOADING
153 :
154 0 : extern "C" { static void SAL_CALL thisModule() {} }
155 :
156 0 : TextToPronounce_zh::TextToPronounce_zh(const sal_Char* func_name)
157 : {
158 : #ifdef SAL_DLLPREFIX
159 0 : OUString lib(SAL_DLLPREFIX"index_data" SAL_DLLEXTENSION);
160 : #else
161 : OUString lib("index_data" SAL_DLLEXTENSION);
162 : #endif
163 : hModule = osl_loadModuleRelative(
164 0 : &thisModule, lib.pData, SAL_LOADMODULE_DEFAULT );
165 0 : idx=NULL;
166 0 : if (hModule) {
167 0 : sal_uInt16** (*function)() = (sal_uInt16** (*)()) osl_getFunctionSymbol(hModule, OUString::createFromAscii(func_name).pData);
168 0 : if (function)
169 0 : idx=function();
170 0 : }
171 0 : }
172 :
173 : #else
174 :
175 : TextToPronounce_zh::TextToPronounce_zh(sal_uInt16 ** (*function)())
176 : {
177 : idx = function();
178 : }
179 :
180 : #endif
181 :
182 0 : TextToPronounce_zh::~TextToPronounce_zh()
183 : {
184 : #ifndef DISABLE_DYNLOADING
185 0 : if (hModule) osl_unloadModule(hModule);
186 : #endif
187 0 : }
188 : } } } }
189 :
190 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|