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: indexentrysupplier_asian.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 #include <rtl/ustrbuf.hxx>
35 #include <indexentrysupplier_asian.hxx>
36 #include <data/indexdata_alphanumeric.h>
38 using namespace ::com::sun::star::uno
;
39 using namespace ::com::sun::star::lang
;
40 using namespace ::rtl
;
42 namespace com
{ namespace sun
{ namespace star
{ namespace i18n
{
44 extern "C" { static void SAL_CALL
thisModule() {} }
46 IndexEntrySupplier_asian::IndexEntrySupplier_asian(
47 const Reference
< XMultiServiceFactory
>& rxMSF
) : IndexEntrySupplier_Common(rxMSF
)
49 implementationName
= "com.sun.star.i18n.IndexEntrySupplier_asian";
51 OUString lib
=OUString::createFromAscii(SAL_DLLPREFIX
"index_data"SAL_DLLEXTENSION
);
53 OUString lib
=OUString::createFromAscii("index_data"SAL_DLLEXTENSION
);
55 hModule
= osl_loadModuleRelative(
56 &thisModule
, lib
.pData
, SAL_LOADMODULE_DEFAULT
);
59 IndexEntrySupplier_asian::~IndexEntrySupplier_asian()
61 if (hModule
) osl_unloadModule(hModule
);
65 IndexEntrySupplier_asian::getIndexCharacter( const OUString
& rIndexEntry
,
66 const Locale
& rLocale
, const OUString
& rAlgorithm
) throw (RuntimeException
)
69 sal_uInt32 ch
= rIndexEntry
.iterateCodePoints(&i
, 0);
71 OUString get
=OUString::createFromAscii("get_indexdata_");
72 sal_uInt16
** (*func
)(sal_Int16
*)=NULL
;
73 if (rLocale
.Language
.equalsAscii("zh") && OUString::createFromAscii("TW HK MO").indexOf(rLocale
.Country
) >= 0)
74 func
=(sal_uInt16
** (*)(sal_Int16
*))osl_getFunctionSymbol(hModule
, (get
+rLocale
.Language
+OUString::createFromAscii("_TW_")+rAlgorithm
).pData
);
76 func
=(sal_uInt16
** (*)(sal_Int16
*))osl_getFunctionSymbol(hModule
, (get
+rLocale
.Language
+OUString('_')+rAlgorithm
).pData
);
79 sal_uInt16
** idx
=func(&max_index
);
80 if (((sal_Int16
)(ch
>> 8)) <= max_index
) {
81 sal_uInt16 address
=idx
[0][ch
>> 8];
82 if (address
!= 0xFFFF) {
83 address
=idx
[1][address
+(ch
& 0xFF)];
84 return idx
[2] ? OUString(&idx
[2][address
]) : OUString(address
);
89 // using alphanumeric index for non-define stirng
90 return OUString(&idxStr
[(ch
& 0xFFFFFF00) ? 0 : ch
], 1);
94 IndexEntrySupplier_asian::getIndexKey( const OUString
& rIndexEntry
,
95 const OUString
& rPhoneticEntry
, const Locale
& rLocale
) throw (RuntimeException
)
97 return getIndexCharacter(getEntry(rIndexEntry
, rPhoneticEntry
, rLocale
), rLocale
, aAlgorithm
);
101 IndexEntrySupplier_asian::compareIndexEntry(
102 const OUString
& rIndexEntry1
, const OUString
& rPhoneticEntry1
, const Locale
& rLocale1
,
103 const OUString
& rIndexEntry2
, const OUString
& rPhoneticEntry2
, const Locale
& rLocale2
)
104 throw (RuntimeException
)
106 sal_Int32 result
= collator
->compareString(getEntry(rIndexEntry1
, rPhoneticEntry1
, rLocale1
),
107 getEntry(rIndexEntry2
, rPhoneticEntry2
, rLocale2
));
109 // equivalent of phonetic entries does not mean equivalent of index entries.
110 // we have to continue comparing index entry here.
111 if (result
== 0 && usePhonetic
&& rPhoneticEntry1
.getLength() > 0 &&
112 rLocale1
.Language
== rLocale2
.Language
&& rLocale1
.Country
== rLocale2
.Country
&&
113 rLocale1
.Variant
== rLocale2
.Variant
)
114 result
= collator
->compareString(rIndexEntry1
, rIndexEntry2
);
115 return sal::static_int_cast
< sal_Int16
>(result
); // result in { -1, 0, 1 }
119 IndexEntrySupplier_asian::getPhoneticCandidate( const OUString
& rIndexEntry
,
120 const Locale
& rLocale
) throw (RuntimeException
)
123 sal_uInt16
**(*func
)(sal_Int16
*)=NULL
;
124 const sal_Char
*func_name
=NULL
;
125 if (rLocale
.Language
.equalsAscii("zh"))
126 func_name
=(OUString::createFromAscii("TW HK MO").indexOf(rLocale
.Country
) >= 0) ? "get_zh_zhuyin" : "get_zh_pinyin";
127 else if (rLocale
.Language
.equalsAscii("ko"))
128 func_name
="get_ko_phonetic";
130 func
=(sal_uInt16
**(*)(sal_Int16
*))osl_getFunctionSymbol(hModule
, OUString::createFromAscii(func_name
).pData
);
132 OUStringBuffer candidate
;
134 sal_uInt16
** idx
=func(&max_index
);
135 OUString aIndexEntry
=rIndexEntry
;
136 for (sal_Int32 i
=0,j
=0; i
< rIndexEntry
.getLength(); i
=j
) {
137 sal_uInt32 ch
= rIndexEntry
.iterateCodePoints(&j
, 1);
138 if (((sal_Int16
)(ch
>>8)) <= max_index
) {
139 sal_uInt16 address
= idx
[0][ch
>>8];
140 if (address
!= 0xFFFF) {
141 address
= idx
[1][address
+ (ch
& 0xFF)];
142 if (i
> 0 && rLocale
.Language
.equalsAscii("zh"))
143 candidate
.appendAscii(" ");
145 candidate
.append(&idx
[2][address
]);
147 candidate
.append(address
);
149 candidate
.appendAscii(" ");
152 return candidate
.makeStringAndClear();