1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
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};
44 sal_uInt16 address
= idx
[0][ch
>>8];
45 if (address
!= 0xFFFF)
46 return &idx
[2][idx
[1][address
+ (ch
& 0xFF)]];
52 TextToPronounce_zh::folding(const OUString
& inStr
, sal_Int32 startPos
,
53 sal_Int32 nCount
, Sequence
< sal_Int32
> & offset
) throw (RuntimeException
)
56 const sal_Unicode
* chArr
= inStr
.getStr() + startPos
;
59 throw RuntimeException();
61 if (startPos
+ nCount
> inStr
.getLength())
62 nCount
= inStr
.getLength() - startPos
;
65 for (sal_Int32 i
= 0; i
< nCount
; i
++) {
66 OUString
pron(getPronounce(chArr
[i
]));
70 offset
[i
+ 1] = offset
[i
] + pron
.getLength();
72 return sb
.makeStringAndClear();
76 TextToPronounce_zh::transliterateChar2String( sal_Unicode inChar
) throw(RuntimeException
)
78 return OUString(getPronounce(inChar
));
82 TextToPronounce_zh::transliterateChar2Char( sal_Unicode inChar
) throw(RuntimeException
, MultipleCharsOutputException
)
84 const sal_Unicode
* pron
=getPronounce(inChar
);
85 if (!pron
|| !pron
[0])
88 throw MultipleCharsOutputException();
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
)
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
;
120 nMatch1
= nMatch2
= realCount
;
121 return (nCount1
== nCount2
);
124 #ifdef DISABLE_DYNLOADING
128 sal_uInt16
** get_zh_zhuyin();
129 sal_uInt16
** get_zh_pinyin();
135 TextToPinyin_zh_CN::TextToPinyin_zh_CN() :
136 #ifndef DISABLE_DYNLOADING
137 TextToPronounce_zh("get_zh_pinyin")
139 TextToPronounce_zh(get_zh_pinyin
)
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")
150 TextToPronounce_zh(get_zh_zhuyin
)
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
)
164 OUString
lib(SAL_DLLPREFIX
"index_data" SAL_DLLEXTENSION
);
166 OUString
lib("index_data" SAL_DLLEXTENSION
);
168 hModule
= osl_loadModuleRelative(
169 &thisModule
, lib
.pData
, SAL_LOADMODULE_DEFAULT
);
172 sal_uInt16
** (*function
)() = (sal_uInt16
** (*)()) osl_getFunctionSymbol(hModule
, OUString::createFromAscii(func_name
).pData
);
180 TextToPronounce_zh::TextToPronounce_zh(sal_uInt16
** (*function
)())
187 TextToPronounce_zh::~TextToPronounce_zh()
189 #ifndef DISABLE_DYNLOADING
190 if (hModule
) osl_unloadModule(hModule
);
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */