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 <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
;
34 sal_Int16 SAL_CALL
TextToPronounce_zh::getType()
36 return TransliterationType::ONE_TO_ONE
| TransliterationType::IGNORE
;
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 reinterpret_cast<sal_Unicode
*>(
47 &idx
[2][idx
[1][address
+ (ch
& 0xFF)]]);
53 TextToPronounce_zh::foldingImpl(const OUString
& inStr
, sal_Int32 startPos
,
54 sal_Int32 nCount
, Sequence
< sal_Int32
> & offset
, bool useOffset
)
57 const sal_Unicode
* chArr
= inStr
.getStr() + startPos
;
60 throw RuntimeException();
62 if (startPos
+ nCount
> inStr
.getLength())
63 nCount
= inStr
.getLength() - startPos
;
66 for (sal_Int32 i
= 0; i
< nCount
; i
++) {
67 OUString
pron(getPronounce(chArr
[i
]));
71 offset
[i
+ 1] = offset
[i
] + pron
.getLength();
73 return sb
.makeStringAndClear();
77 TextToPronounce_zh::transliterateChar2String( sal_Unicode inChar
)
79 return OUString(getPronounce(inChar
));
83 TextToPronounce_zh::transliterateChar2Char( sal_Unicode inChar
)
85 const sal_Unicode
* pron
=getPronounce(inChar
);
86 if (!pron
|| !pron
[0])
89 throw MultipleCharsOutputException();
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
)
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
;
119 nMatch1
= nMatch2
= realCount
;
120 return (nCount1
== nCount2
);
123 #ifdef DISABLE_DYNLOADING
127 sal_uInt16
** get_zh_zhuyin();
128 sal_uInt16
** get_zh_pinyin();
134 TextToPinyin_zh_CN::TextToPinyin_zh_CN() :
135 #ifndef DISABLE_DYNLOADING
136 TextToPronounce_zh("get_zh_pinyin")
138 TextToPronounce_zh(get_zh_pinyin
)
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")
149 TextToPronounce_zh(get_zh_zhuyin
)
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
)
163 OUString
lib(SAL_DLLPREFIX
"index_data" SAL_DLLEXTENSION
);
165 OUString
lib("index_data" SAL_DLLEXTENSION
);
167 hModule
= osl_loadModuleRelative(
168 &thisModule
, lib
.pData
, SAL_LOADMODULE_DEFAULT
);
171 sal_uInt16
** (*function
)() = reinterpret_cast<sal_uInt16
** (*)()>(osl_getFunctionSymbol(hModule
, OUString::createFromAscii(func_name
).pData
));
179 TextToPronounce_zh::TextToPronounce_zh(sal_uInt16
** (*function
)())
186 TextToPronounce_zh::~TextToPronounce_zh()
188 #ifndef DISABLE_DYNLOADING
189 if (hModule
) osl_unloadModule(hModule
);
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */