LibreOffice Module i18npool (master) 1
indexentrysupplier_asian.cxx
Go to the documentation of this file.
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#include <sal/config.h>
21
22#include <o3tl/temporary.hxx>
23#include <rtl/ustrbuf.hxx>
24#include <collatorImpl.hxx>
27
28using namespace ::com::sun::star::uno;
29using namespace ::com::sun::star::lang;
30
31namespace i18npool {
32
33#ifndef DISABLE_DYNLOADING
34
35extern "C" { static void thisModule() {} }
36
37#endif
38
40 const Reference < XComponentContext >& rxContext ) : IndexEntrySupplier_Common(rxContext)
41{
42 implementationName = "com.sun.star.i18n.IndexEntrySupplier_asian";
43#ifndef DISABLE_DYNLOADING
44#ifdef SAL_DLLPREFIX
45 OUString lib(SAL_DLLPREFIX"index_data" SAL_DLLEXTENSION);
46#else
47 OUString lib("index_data" SAL_DLLEXTENSION);
48#endif
49 hModule = osl_loadModuleRelative(
50 &thisModule, lib.pData, SAL_LOADMODULE_DEFAULT );
51#endif
52}
53
55{
56#ifndef DISABLE_DYNLOADING
57 if (hModule) osl_unloadModule(hModule);
58#endif
59}
60
61#ifdef DISABLE_DYNLOADING
62
63extern "C" {
64
65sal_uInt16** get_indexdata_ko_dict(sal_Int16*);
66sal_uInt16** get_indexdata_zh_TW_radical(sal_Int16*);
67sal_uInt16** get_indexdata_zh_TW_stroke(sal_Int16*);
68sal_uInt16** get_indexdata_zh_pinyin(sal_Int16*);
69sal_uInt16** get_indexdata_zh_radical(sal_Int16*);
70sal_uInt16** get_indexdata_zh_stroke(sal_Int16*);
71sal_uInt16** get_indexdata_zh_zhuyin(sal_Int16*);
72
73sal_uInt16** get_ko_phonetic(sal_Int16*);
74sal_uInt16** get_zh_pinyin(sal_Int16*);
75sal_uInt16** get_zh_zhuyin(sal_Int16*);
76
77}
78
79#endif
80
81OUString SAL_CALL
83 const Locale& rLocale, const OUString& rAlgorithm )
84{
85 sal_uInt32 ch = rIndexEntry.iterateCodePoints(&o3tl::temporary(sal_Int32(0)), 0);
86
87 sal_uInt16** (*func)(sal_Int16*)=nullptr;
88#ifndef DISABLE_DYNLOADING
89 if (hModule) {
90 OUString get("get_indexdata_");
91 if ( rLocale.Language == "zh" && OUString( "TW HK MO" ).indexOf(rLocale.Country) >= 0 )
92 func=reinterpret_cast<sal_uInt16** (*)(sal_Int16*)>(osl_getFunctionSymbol(hModule, OUString(get+rLocale.Language+"_TW_"+rAlgorithm).pData));
93 if (!func)
94 func=reinterpret_cast<sal_uInt16** (*)(sal_Int16*)>(osl_getFunctionSymbol(hModule, OUString(get+rLocale.Language+"_"+rAlgorithm).pData));
95 }
96#else
97 if ( rLocale.Language == "zh" && OUString( "TW HK MO" ).indexOf(rLocale.Country) >= 0 ) {
98 if ( rAlgorithm == "radical" )
99 func = get_indexdata_zh_TW_radical;
100 else if ( rAlgorithm == "stroke" )
101 func = get_indexdata_zh_TW_stroke;
102 }
103 if (!func) {
104 if ( rLocale.Language == "ko" ) {
105 if ( rAlgorithm == "dict" )
106 func = get_indexdata_ko_dict;
107 } else if ( rLocale.Language == "zh" ) {
108 if ( rAlgorithm == "pinyin" )
109 func = get_indexdata_zh_pinyin;
110 else if ( rAlgorithm == "radical" )
111 func = get_indexdata_zh_radical;
112 else if ( rAlgorithm == "stroke" )
113 func = get_indexdata_zh_stroke;
114 else if ( rAlgorithm == "zhuyin" )
115 func = get_indexdata_zh_zhuyin;
116 }
117 }
118#endif
119 if (func) {
120 sal_Int16 max_index;
121 sal_uInt16** idx=func(&max_index);
122 if (static_cast<sal_Int16>(ch >> 8) <= max_index) {
123 sal_uInt16 address=idx[0][ch >> 8];
124 if (address != 0xFFFF) {
125 address=idx[1][address+(ch & 0xFF)];
126 return idx[2]
127 ? OUString(
128 reinterpret_cast<sal_Unicode *>(&idx[2][address]))
129 : OUString(sal_Unicode(address));
130 }
131 }
132 }
133
134 // using alphanumeric index for non-define string
135 return OUString(&idxStr[(ch & 0xFFFFFF00) ? 0 : ch], 1);
136}
137
138OUString SAL_CALL
139IndexEntrySupplier_asian::getIndexKey( const OUString& rIndexEntry,
140 const OUString& rPhoneticEntry, const Locale& rLocale)
141{
142 return getIndexCharacter(getEntry(rIndexEntry, rPhoneticEntry, rLocale), rLocale, aAlgorithm);
143}
144
145sal_Int16 SAL_CALL
147 const OUString& rIndexEntry1, const OUString& rPhoneticEntry1, const Locale& rLocale1,
148 const OUString& rIndexEntry2, const OUString& rPhoneticEntry2, const Locale& rLocale2 )
149{
150 sal_Int32 result = collator->compareString(getEntry(rIndexEntry1, rPhoneticEntry1, rLocale1),
151 getEntry(rIndexEntry2, rPhoneticEntry2, rLocale2));
152
153 // equivalent of phonetic entries does not mean equivalent of index entries.
154 // we have to continue comparing index entry here.
155 if (result == 0 && usePhonetic && !rPhoneticEntry1.isEmpty() &&
156 rLocale1.Language == rLocale2.Language && rLocale1.Country == rLocale2.Country &&
157 rLocale1.Variant == rLocale2.Variant)
158 result = collator->compareString(rIndexEntry1, rIndexEntry2);
159 return sal::static_int_cast< sal_Int16 >(result); // result in { -1, 0, 1 }
160}
161
162OUString SAL_CALL
164 const Locale& rLocale )
165{
166 sal_uInt16 **(*func)(sal_Int16*)=nullptr;
167#ifndef DISABLE_DYNLOADING
168 if (hModule) {
169 const char *func_name=nullptr;
170 if ( rLocale.Language == "zh" )
171 func_name=(OUString("TW HK MO").indexOf(rLocale.Country) >= 0) ? "get_zh_zhuyin" : "get_zh_pinyin";
172 else if ( rLocale.Language == "ko" )
173 func_name="get_ko_phonetic";
174 if (func_name)
175 func=reinterpret_cast<sal_uInt16 **(*)(sal_Int16*)>(osl_getFunctionSymbol(hModule, OUString::createFromAscii(func_name).pData));
176 }
177#else
178 if ( rLocale.Language == "zh" )
179 func = (OUString("TW HK MO").indexOf(rLocale.Country) >= 0) ? get_zh_zhuyin : get_zh_pinyin;
180 else if ( rLocale.Language == "ko" )
181 func = get_ko_phonetic;
182
183#endif
184 if (func) {
185 OUStringBuffer candidate;
186 sal_Int16 max_index;
187 sal_uInt16** idx=func(&max_index);
188 for (sal_Int32 i=0,j=0; i < rIndexEntry.getLength(); i=j) {
189 sal_uInt32 ch = rIndexEntry.iterateCodePoints(&j);
190 if (static_cast<sal_Int16>(ch>>8) <= max_index) {
191 sal_uInt16 address = idx[0][ch>>8];
192 if (address != 0xFFFF) {
193 address = idx[1][address + (ch & 0xFF)];
194 if ( i > 0 && rLocale.Language == "zh" )
195 candidate.append(" ");
196 if (idx[2])
197 candidate.append(
198 reinterpret_cast<sal_Unicode *>(&idx[2][address]));
199 else
200 candidate.append(sal_Unicode(address));
201 } else
202 candidate.append(" ");
203 }
204 }
205 return candidate.makeStringAndClear();
206 }
207 return OUString();
208}
209
210}
211
212
213/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define SAL_DLLPREFIX
const OUString & getEntry(const OUString &IndexEntry, const OUString &PhoneticEntry, const css::lang::Locale &rLocale) const
OUString SAL_CALL getIndexCharacter(const OUString &rIndexEntry, const css::lang::Locale &rLocale, const OUString &rAlgorithm) override
sal_Int16 SAL_CALL compareIndexEntry(const OUString &rIndexEntry1, const OUString &rPhoneticEntry1, const css::lang::Locale &rLocale1, const OUString &rIndexEntry2, const OUString &rPhoneticEntry2, const css::lang::Locale &rLocale2) override
OUString SAL_CALL getPhoneticCandidate(const OUString &rIndexEntry, const css::lang::Locale &rLocale) override
OUString SAL_CALL getIndexKey(const OUString &rIndexEntry, const OUString &rPhoneticEntry, const css::lang::Locale &rLocale) override
IndexEntrySupplier_asian(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
#define SAL_DLLEXTENSION
const sal_Unicode idxStr[]
const sal_uInt16 idx[]
std::unique_ptr< sal_Int32[]> pData
int i
Constant values shared between i18npool and, for example, the number formatter.
static void thisModule()
Definition: xdictionary.cxx:41
constexpr T & temporary(T &&x)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
sal_uInt16 sal_Unicode
Any result