1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: textToPronounce_zh.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_i18npool.hxx"
34 // prevent internal compiler error with MSVC6SP3
37 #include <rtl/string.hxx>
38 #include <rtl/ustrbuf.hxx>
39 #define TRANSLITERATION_ALL
40 #include <textToPronounce_zh.hxx>
42 using namespace com::sun::star::uno
;
45 namespace com
{ namespace sun
{ namespace star
{ namespace i18n
{
47 sal_Int16 SAL_CALL
TextToPronounce_zh::getType() throw (RuntimeException
)
49 return TransliterationType::ONE_TO_ONE
| TransliterationType::IGNORE
;
52 const sal_Unicode
* SAL_CALL
53 TextToPronounce_zh::getPronounce(const sal_Unicode ch
)
55 static const sal_Unicode emptyString
[]={0};
57 sal_uInt16 address
= idx
[0][ch
>>8];
58 if (address
!= 0xFFFF)
59 return &idx
[2][idx
[1][address
+ (ch
& 0xFF)]];
65 TextToPronounce_zh::folding(const OUString
& inStr
, sal_Int32 startPos
,
66 sal_Int32 nCount
, Sequence
< sal_Int32
> & offset
) throw (RuntimeException
)
69 const sal_Unicode
* chArr
= inStr
.getStr() + startPos
;
72 throw RuntimeException();
74 if (startPos
+ nCount
> inStr
.getLength())
75 nCount
= inStr
.getLength() - startPos
;
78 for (sal_Int32 i
= 0; i
< nCount
; i
++) {
79 OUString
pron(getPronounce(chArr
[i
]));
83 offset
[i
+ 1] = offset
[i
] + pron
.getLength();
85 return sb
.makeStringAndClear();
89 TextToPronounce_zh::transliterateChar2String( sal_Unicode inChar
) throw(RuntimeException
)
91 return OUString(getPronounce(inChar
));
95 TextToPronounce_zh::transliterateChar2Char( sal_Unicode inChar
) throw(RuntimeException
, MultipleCharsOutputException
)
97 const sal_Unicode
* pron
=getPronounce(inChar
);
98 if (!pron
|| !pron
[0])
101 throw MultipleCharsOutputException();
106 TextToPronounce_zh::equals( const OUString
& str1
, sal_Int32 pos1
, sal_Int32 nCount1
, sal_Int32
& nMatch1
,
107 const OUString
& str2
, sal_Int32 pos2
, sal_Int32 nCount2
, sal_Int32
& nMatch2
)
108 throw (RuntimeException
)
111 int i
; // loop variable
112 const sal_Unicode
* s1
, * s2
;
113 const sal_Unicode
*pron1
, *pron2
;
115 if (nCount1
+ pos1
> str1
.getLength())
116 nCount1
= str1
.getLength() - pos1
;
118 if (nCount2
+ pos2
> str2
.getLength())
119 nCount2
= str2
.getLength() - pos2
;
121 realCount
= ((nCount1
> nCount2
) ? nCount2
: nCount1
);
123 s1
= str1
.getStr() + pos1
;
124 s2
= str2
.getStr() + pos2
;
125 for (i
= 0; i
< realCount
; i
++) {
126 pron1
=getPronounce(*s1
++);
127 pron2
=getPronounce(*s2
++);
128 if (pron1
!= pron2
) {
129 nMatch1
= nMatch2
= i
;
133 nMatch1
= nMatch2
= realCount
;
134 return (nCount1
== nCount2
);
137 TextToPinyin_zh_CN::TextToPinyin_zh_CN() : TextToPronounce_zh("get_zh_pinyin")
139 transliterationName
= "ChineseCharacterToPinyin";
140 implementationName
= "com.sun.star.i18n.Transliteration.TextToPinyin_zh_CN";
143 TextToChuyin_zh_TW::TextToChuyin_zh_TW() : TextToPronounce_zh("get_zh_zhuyin")
145 transliterationName
= "ChineseCharacterToChuyin";
146 implementationName
= "com.sun.star.i18n.Transliteration.TextToChuyin_zh_TW";
149 extern "C" { static void SAL_CALL
thisModule() {} }
151 TextToPronounce_zh::TextToPronounce_zh(const sal_Char
* func_name
)
154 OUString lib
=OUString::createFromAscii(SAL_DLLPREFIX
"index_data"SAL_DLLEXTENSION
);
156 OUString lib
=OUString::createFromAscii("index_data"SAL_DLLEXTENSION
);
158 hModule
= osl_loadModuleRelative(
159 &thisModule
, lib
.pData
, SAL_LOADMODULE_DEFAULT
);
162 sal_uInt16
** (*function
)() = (sal_uInt16
** (*)()) osl_getFunctionSymbol(hModule
, OUString::createFromAscii(func_name
).pData
);
167 TextToPronounce_zh::~TextToPronounce_zh()
169 if (hModule
) osl_unloadModule(hModule
);