Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : :
21 : : #include <rtl/ustrbuf.hxx>
22 : : #include <indexentrysupplier_asian.hxx>
23 : : #include <data/indexdata_alphanumeric.h>
24 : :
25 : : using namespace ::com::sun::star::uno;
26 : : using namespace ::com::sun::star::lang;
27 : : using namespace ::rtl;
28 : :
29 : : namespace com { namespace sun { namespace star { namespace i18n {
30 : :
31 : : #ifndef DISABLE_DYNLOADING
32 : :
33 : 0 : extern "C" { static void SAL_CALL thisModule() {} }
34 : :
35 : : #endif
36 : :
37 : 0 : IndexEntrySupplier_asian::IndexEntrySupplier_asian(
38 : 0 : const Reference < XMultiServiceFactory >& rxMSF ) : IndexEntrySupplier_Common(rxMSF)
39 : : {
40 : 0 : implementationName = "com.sun.star.i18n.IndexEntrySupplier_asian";
41 : : #ifndef DISABLE_DYNLOADING
42 : : #ifdef SAL_DLLPREFIX
43 : 0 : OUString lib(SAL_DLLPREFIX"index_data" SAL_DLLEXTENSION);
44 : : #else
45 : : OUString lib("index_data" SAL_DLLEXTENSION);
46 : : #endif
47 : : hModule = osl_loadModuleRelative(
48 [ # # ]: 0 : &thisModule, lib.pData, SAL_LOADMODULE_DEFAULT );
49 : : #endif
50 : 0 : }
51 : :
52 : 0 : IndexEntrySupplier_asian::~IndexEntrySupplier_asian()
53 : : {
54 : : #ifndef DISABLE_DYNLOADING
55 [ # # ][ # # ]: 0 : if (hModule) osl_unloadModule(hModule);
56 : : #endif
57 [ # # ]: 0 : }
58 : :
59 : : #ifdef DISABLE_DYNLOADING
60 : :
61 : : extern "C" {
62 : :
63 : : sal_uInt16** get_indexdata_ko_dict(sal_Int16*);
64 : : sal_uInt16** get_indexdata_zh_TW_radical(sal_Int16*);
65 : : sal_uInt16** get_indexdata_zh_TW_stroke(sal_Int16*);
66 : : sal_uInt16** get_indexdata_zh_pinyin(sal_Int16*);
67 : : sal_uInt16** get_indexdata_zh_radical(sal_Int16*);
68 : : sal_uInt16** get_indexdata_zh_stroke(sal_Int16*);
69 : : sal_uInt16** get_indexdata_zh_zhuyin(sal_Int16*);
70 : :
71 : : sal_uInt16** get_ko_phonetic(sal_Int16*);
72 : : sal_uInt16** get_zh_pinyin(sal_Int16*);
73 : : sal_uInt16** get_zh_zhuyin(sal_Int16*);
74 : :
75 : : }
76 : :
77 : : #endif
78 : :
79 : : OUString SAL_CALL
80 : 0 : IndexEntrySupplier_asian::getIndexCharacter( const OUString& rIndexEntry,
81 : : const Locale& rLocale, const OUString& rAlgorithm ) throw (RuntimeException)
82 : : {
83 : 0 : sal_Int32 i=0;
84 [ # # ]: 0 : sal_uInt32 ch = rIndexEntry.iterateCodePoints(&i, 0);
85 : :
86 : 0 : sal_uInt16** (*func)(sal_Int16*)=NULL;
87 : : #ifndef DISABLE_DYNLOADING
88 [ # # ]: 0 : if (hModule) {
89 : 0 : OUString get("get_indexdata_");
90 [ # # ][ # # ]: 0 : if ( rLocale.Language == "zh" && OUString( "TW HK MO" ).indexOf(rLocale.Country) >= 0 )
[ # # ][ # # ]
[ # # ]
91 [ # # ]: 0 : func=(sal_uInt16** (*)(sal_Int16*))osl_getFunctionSymbol(hModule, (get+rLocale.Language+OUString("_TW_")+rAlgorithm).pData);
92 [ # # ]: 0 : if (!func)
93 [ # # ]: 0 : func=(sal_uInt16** (*)(sal_Int16*))osl_getFunctionSymbol(hModule, (get+rLocale.Language+OUString('_')+rAlgorithm).pData);
94 : : }
95 : : #else
96 : : if ( rLocale.Language == "zh" && OUString( "TW HK MO" ).indexOf(rLocale.Country) >= 0 ) {
97 : : if ( rAlgorithm == "radical" )
98 : : func = get_indexdata_zh_TW_radical;
99 : : else if ( rAlgorithm == "stroke" )
100 : : func = get_indexdata_zh_TW_stroke;
101 : : }
102 : : if (!func) {
103 : : if ( rLocale.Language == "ko" ) {
104 : : if ( rAlgorithm == "dict" )
105 : : func = get_indexdata_ko_dict;
106 : : } else if ( rLocale.Language == "zh" ) {
107 : : if ( rAlgorithm == "pinyin" )
108 : : func = get_indexdata_zh_pinyin;
109 : : else if ( rAlgorithm == "radical" )
110 : : func = get_indexdata_zh_radical;
111 : : else if ( rAlgorithm == "stroke" )
112 : : func = get_indexdata_zh_stroke;
113 : : else if ( rAlgorithm == "zhuyin" )
114 : : func = get_indexdata_zh_zhuyin;
115 : : }
116 : : }
117 : : #endif
118 [ # # ]: 0 : if (func) {
119 : : sal_Int16 max_index;
120 [ # # ]: 0 : sal_uInt16** idx=func(&max_index);
121 [ # # ]: 0 : if (((sal_Int16)(ch >> 8)) <= max_index) {
122 : 0 : sal_uInt16 address=idx[0][ch >> 8];
123 [ # # ]: 0 : if (address != 0xFFFF) {
124 : 0 : address=idx[1][address+(ch & 0xFF)];
125 [ # # ]: 0 : return idx[2] ? OUString(&idx[2][address]) : OUString(address);
126 : : }
127 : : }
128 : : }
129 : :
130 : : // using alphanumeric index for non-define stirng
131 [ # # ]: 0 : return OUString(&idxStr[(ch & 0xFFFFFF00) ? 0 : ch], 1);
132 : : }
133 : :
134 : : OUString SAL_CALL
135 : 0 : IndexEntrySupplier_asian::getIndexKey( const OUString& rIndexEntry,
136 : : const OUString& rPhoneticEntry, const Locale& rLocale) throw (RuntimeException)
137 : : {
138 : 0 : return getIndexCharacter(getEntry(rIndexEntry, rPhoneticEntry, rLocale), rLocale, aAlgorithm);
139 : : }
140 : :
141 : : sal_Int16 SAL_CALL
142 : 0 : IndexEntrySupplier_asian::compareIndexEntry(
143 : : const OUString& rIndexEntry1, const OUString& rPhoneticEntry1, const Locale& rLocale1,
144 : : const OUString& rIndexEntry2, const OUString& rPhoneticEntry2, const Locale& rLocale2 )
145 : : throw (RuntimeException)
146 : : {
147 : 0 : sal_Int32 result = collator->compareString(getEntry(rIndexEntry1, rPhoneticEntry1, rLocale1),
148 : 0 : getEntry(rIndexEntry2, rPhoneticEntry2, rLocale2));
149 : :
150 : : // equivalent of phonetic entries does not mean equivalent of index entries.
151 : : // we have to continue comparing index entry here.
152 [ # # ][ # # : 0 : if (result == 0 && usePhonetic && !rPhoneticEntry1.isEmpty() &&
# # # # #
# ][ # # ]
[ # # ]
153 : 0 : rLocale1.Language == rLocale2.Language && rLocale1.Country == rLocale2.Country &&
154 : 0 : rLocale1.Variant == rLocale2.Variant)
155 : 0 : result = collator->compareString(rIndexEntry1, rIndexEntry2);
156 : 0 : return sal::static_int_cast< sal_Int16 >(result); // result in { -1, 0, 1 }
157 : : }
158 : :
159 : : OUString SAL_CALL
160 : 0 : IndexEntrySupplier_asian::getPhoneticCandidate( const OUString& rIndexEntry,
161 : : const Locale& rLocale ) throw (RuntimeException)
162 : : {
163 : 0 : sal_uInt16 **(*func)(sal_Int16*)=NULL;
164 : : #ifndef DISABLE_DYNLOADING
165 [ # # ]: 0 : if (hModule) {
166 : 0 : const sal_Char *func_name=NULL;
167 [ # # ]: 0 : if ( rLocale.Language == "zh" )
168 [ # # ]: 0 : func_name=(OUString("TW HK MO").indexOf(rLocale.Country) >= 0) ? "get_zh_zhuyin" : "get_zh_pinyin";
169 [ # # ]: 0 : else if ( rLocale.Language == "ko" )
170 : 0 : func_name="get_ko_phonetic";
171 [ # # ]: 0 : if (func_name)
172 [ # # ]: 0 : func=(sal_uInt16 **(*)(sal_Int16*))osl_getFunctionSymbol(hModule, OUString::createFromAscii(func_name).pData);
173 : : }
174 : : #else
175 : : if ( rLocale.Language == "zh" )
176 : : func = (OUString("TW HK MO").indexOf(rLocale.Country) >= 0) ? get_zh_zhuyin : get_zh_pinyin;
177 : : else if ( rLocale.Language == "ko" )
178 : : func = get_ko_phonetic;
179 : :
180 : : #endif
181 [ # # ]: 0 : if (func) {
182 : 0 : OUStringBuffer candidate;
183 : : sal_Int16 max_index;
184 [ # # ]: 0 : sal_uInt16** idx=func(&max_index);
185 [ # # ]: 0 : for (sal_Int32 i=0,j=0; i < rIndexEntry.getLength(); i=j) {
186 [ # # ]: 0 : sal_uInt32 ch = rIndexEntry.iterateCodePoints(&j, 1);
187 [ # # ]: 0 : if (((sal_Int16)(ch>>8)) <= max_index) {
188 : 0 : sal_uInt16 address = idx[0][ch>>8];
189 [ # # ]: 0 : if (address != 0xFFFF) {
190 : 0 : address = idx[1][address + (ch & 0xFF)];
191 [ # # ][ # # ]: 0 : if ( i > 0 && rLocale.Language == "zh" )
[ # # ]
192 [ # # ]: 0 : candidate.appendAscii(" ");
193 [ # # ]: 0 : if (idx[2])
194 [ # # ]: 0 : candidate.append(&idx[2][address]);
195 : : else
196 [ # # ]: 0 : candidate.append(address);
197 : : } else
198 [ # # ]: 0 : candidate.appendAscii(" ");
199 : : }
200 : : }
201 [ # # ]: 0 : return candidate.makeStringAndClear();
202 : : }
203 : 0 : return OUString();
204 : : }
205 : : } } } }
206 : :
207 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|