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 .
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};
39 sal_uInt16 address
= idx
[0][ch
>>8];
40 if (address
!= 0xFFFF)
41 return &idx
[2][idx
[1][address
+ (ch
& 0xFF)]];
47 TextToPronounce_zh::folding(const OUString
& inStr
, sal_Int32 startPos
,
48 sal_Int32 nCount
, Sequence
< sal_Int32
> & offset
) throw (RuntimeException
, std::exception
)
51 const sal_Unicode
* chArr
= inStr
.getStr() + startPos
;
54 throw RuntimeException();
56 if (startPos
+ nCount
> inStr
.getLength())
57 nCount
= inStr
.getLength() - startPos
;
60 for (sal_Int32 i
= 0; i
< nCount
; i
++) {
61 OUString
pron(getPronounce(chArr
[i
]));
65 offset
[i
+ 1] = offset
[i
] + pron
.getLength();
67 return sb
.makeStringAndClear();
71 TextToPronounce_zh::transliterateChar2String( sal_Unicode inChar
) throw(RuntimeException
, std::exception
)
73 return OUString(getPronounce(inChar
));
77 TextToPronounce_zh::transliterateChar2Char( sal_Unicode inChar
) throw(RuntimeException
, MultipleCharsOutputException
, std::exception
)
79 const sal_Unicode
* pron
=getPronounce(inChar
);
80 if (!pron
|| !pron
[0])
83 throw MultipleCharsOutputException();
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
)
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
;
115 nMatch1
= nMatch2
= realCount
;
116 return (nCount1
== nCount2
);
119 #ifdef DISABLE_DYNLOADING
123 sal_uInt16
** get_zh_zhuyin();
124 sal_uInt16
** get_zh_pinyin();
130 TextToPinyin_zh_CN::TextToPinyin_zh_CN() :
131 #ifndef DISABLE_DYNLOADING
132 TextToPronounce_zh("get_zh_pinyin")
134 TextToPronounce_zh(get_zh_pinyin
)
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")
145 TextToPronounce_zh(get_zh_zhuyin
)
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
)
159 OUString
lib(SAL_DLLPREFIX
"index_data" SAL_DLLEXTENSION
);
161 OUString
lib("index_data" SAL_DLLEXTENSION
);
163 hModule
= osl_loadModuleRelative(
164 &thisModule
, lib
.pData
, SAL_LOADMODULE_DEFAULT
);
167 sal_uInt16
** (*function
)() = (sal_uInt16
** (*)()) osl_getFunctionSymbol(hModule
, OUString::createFromAscii(func_name
).pData
);
175 TextToPronounce_zh::TextToPronounce_zh(sal_uInt16
** (*function
)())
182 TextToPronounce_zh::~TextToPronounce_zh()
184 #ifndef DISABLE_DYNLOADING
185 if (hModule
) osl_unloadModule(hModule
);
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */