LibreOffice Module i18npool (master)  1
registerservices.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 <config_locales.h>
21 
22 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
23 
25 #include <cppuhelper/factory.hxx>
26 #include <cppuhelper/weak.hxx>
27 
28 #include <servicename.hxx>
29 
30 #include <transliteration_body.hxx>
32 #include <textToPronounce_zh.hxx>
33 #include <numtotext_cjk.hxx>
34 #include <numtochar.hxx>
35 #include <texttonum.hxx>
36 #include <chartonum.hxx>
37 
38 #include <calendarImpl.hxx>
39 #include <calendar_gregorian.hxx>
40 #include <calendar_hijri.hxx>
41 #include <calendar_jewish.hxx>
42 
43 #include <breakiterator_cjk.hxx>
44 #include <breakiterator_th.hxx>
45 
46 #include <indexentrysupplier.hxx>
50 
51 #include <chaptercollator.hxx>
52 #include <collator_unicode.hxx>
53 
56 
57 #include <textconversion.hxx>
58 
59 using namespace ::com::sun::star;
60 using namespace ::com::sun::star::i18n;
61 using namespace i18npool;
62 
63 #define IMPL_CREATEINSTANCE( ImplName ) \
64  static uno::Reference< uno::XInterface > \
65  ImplName##_CreateInstance( \
66  SAL_UNUSED_PARAMETER const uno::Reference< \
67  lang::XMultiServiceFactory >& ) \
68 { \
69  return uno::Reference < \
70  uno::XInterface >( static_cast<cppu::OWeakObject*>( \
71  new ImplName) ); \
72 }
73 
74 #define IMPL_TRANSLITERATION_ITEM( implName ) \
75  { TRLT_SERVICELNAME_L10N, \
76  TRLT_IMPLNAME_PREFIX #implName, \
77  &implName##_CreateInstance }
78 
79 #define IMPL_UNO_CONSTRUCTOR( ImplName ) \
80 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * \
81 i18npool_##ImplName##_get_implementation( \
82  css::uno::XComponentContext *, \
83  css::uno::Sequence<css::uno::Any> const &) \
84 { \
85  return cppu::acquire(new ImplName()); \
86 }
87 
88 #define IMPL_UNO_CONSTRUCTOR_CTX( ImplName ) \
89 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * \
90 i18npool_##ImplName##_get_implementation( \
91  css::uno::XComponentContext * context, \
92  css::uno::Sequence<css::uno::Any> const &) \
93 { \
94  return cppu::acquire(new ImplName(context)); \
95 }
96 
97 
98 // At least for iOS it doesn't hurt if we have lots of functions here
99 // generated by these lovely macros that get compiled, but then no
100 // references to them thanks to the WITH_LOCALE ifdefs for the
101 // aInstances table below. The -dead_strip linker option will take
102 // care of not linking these functions in. Presumably the same holds
103 // for Android, too, as we use -ffunction-sections and
104 // -Wl,--gc_sections. It's mainly for iOS and Android that the
105 // --with-locales option is intended anyway.
106 
109 #if WITH_LOCALE_ALL || WITH_LOCALE_ja
110 IMPL_UNO_CONSTRUCTOR_CTX( IndexEntrySupplier_ja_phonetic_alphanumeric_first_by_syllable )
111 IMPL_UNO_CONSTRUCTOR_CTX( IndexEntrySupplier_ja_phonetic_alphanumeric_first_by_consonant )
112 IMPL_UNO_CONSTRUCTOR_CTX( IndexEntrySupplier_ja_phonetic_alphanumeric_last_by_syllable )
113 IMPL_UNO_CONSTRUCTOR_CTX( IndexEntrySupplier_ja_phonetic_alphanumeric_last_by_consonant )
114 #endif
126 #if WITH_LOCALE_ALL || WITH_LOCALE_ja
128 #endif
129 #if WITH_LOCALE_ALL || WITH_LOCALE_zh
132 #endif
133 #if WITH_LOCALE_ALL || WITH_LOCALE_ko
135 #endif
136 #if WITH_LOCALE_ALL || WITH_LOCALE_th
138 #endif
141 
142 #if WITH_LOCALE_ALL || WITH_LOCALE_th
144 #endif
145 #if WITH_LOCALE_ALL || WITH_LOCALE_hi
147 #endif
148 #if WITH_LOCALE_ALL || WITH_LOCALE_ko
150 #endif
151 #if WITH_LOCALE_ALL || WITH_LOCALE_zh
153 #endif
154 
160 IMPL_CREATEINSTANCE( hiraganaToKatakana )
161 IMPL_CREATEINSTANCE( katakanaToHiragana )
162 IMPL_CREATEINSTANCE( fullwidthToHalfwidth )
164 
165 IMPL_CREATEINSTANCE( smallToLarge_ja_JP)
166 IMPL_CREATEINSTANCE( largeToSmall_ja_JP)
167 IMPL_CREATEINSTANCE( ignoreTraditionalKanji_ja_JP)
168 IMPL_CREATEINSTANCE( ignoreTraditionalKana_ja_JP)
169 IMPL_CREATEINSTANCE( ignoreMinusSign_ja_JP)
170 IMPL_CREATEINSTANCE( ignoreIterationMark_ja_JP)
171 IMPL_CREATEINSTANCE( ignoreSeparator_ja_JP)
172 IMPL_CREATEINSTANCE( ignoreZiZu_ja_JP)
173 IMPL_CREATEINSTANCE( ignoreBaFa_ja_JP)
174 IMPL_CREATEINSTANCE( ignoreTiJi_ja_JP)
175 IMPL_CREATEINSTANCE( ignoreHyuByu_ja_JP)
176 IMPL_CREATEINSTANCE( ignoreSeZe_ja_JP)
177 IMPL_CREATEINSTANCE( ignoreIandEfollowedByYa_ja_JP)
178 IMPL_CREATEINSTANCE( ignoreKiKuFollowedBySa_ja_JP)
179 IMPL_CREATEINSTANCE( ignoreSize_ja_JP)
180 IMPL_CREATEINSTANCE( ignoreProlongedSoundMark_ja_JP)
181 IMPL_CREATEINSTANCE( ignoreMiddleDot_ja_JP)
182 IMPL_CREATEINSTANCE( ignoreSpace_ja_JP)
184 IMPL_CREATEINSTANCE( ignoreKashida_CTL)
185 
186 IMPL_CREATEINSTANCE( TextToChuyin_zh_TW )
187 IMPL_CREATEINSTANCE( TextToPinyin_zh_CN )
188 
189 IMPL_CREATEINSTANCE( NumToCharLower_zh_CN )
190 IMPL_CREATEINSTANCE( NumToCharUpper_zh_CN )
191 IMPL_CREATEINSTANCE( NumToCharLower_zh_TW )
192 IMPL_CREATEINSTANCE( NumToCharUpper_zh_TW )
193 IMPL_CREATEINSTANCE( NumToCharHalfwidth )
194 IMPL_CREATEINSTANCE( NumToCharFullwidth )
195 IMPL_CREATEINSTANCE( NumToCharKanjiShort_ja_JP )
196 IMPL_CREATEINSTANCE( NumToCharKanjiTraditional_ja_JP )
197 IMPL_CREATEINSTANCE( NumToCharHangul_ko )
198 IMPL_CREATEINSTANCE( NumToCharLower_ko )
199 IMPL_CREATEINSTANCE( NumToCharUpper_ko )
200 IMPL_CREATEINSTANCE( NumToCharIndic_ar )
201 IMPL_UNO_CONSTRUCTOR( NumToCharEastIndic_ar )
202 IMPL_CREATEINSTANCE( NumToCharIndic_hi )
203 IMPL_CREATEINSTANCE( NumToChar_th )
204 
205 #if WITH_LOCALE_ALL || WITH_LOCALE_zh
206 IMPL_UNO_CONSTRUCTOR (CharToNumUpper_zh_CN)
207 IMPL_UNO_CONSTRUCTOR (CharToNumLower_zh_CN)
208 IMPL_UNO_CONSTRUCTOR (CharToNumUpper_zh_TW)
209 IMPL_UNO_CONSTRUCTOR (CharToNumLower_zh_TW)
210 #endif
211 #if WITH_LOCALE_ALL || WITH_LOCALE_ja
212 IMPL_UNO_CONSTRUCTOR( CharToNumFullwidth )
213 IMPL_UNO_CONSTRUCTOR( CharToNumKanjiShort_ja_JP )
214 IMPL_UNO_CONSTRUCTOR( CharToNumKanjiTraditional_ja_JP )
215 #endif
216 #if WITH_LOCALE_ALL || WITH_LOCALE_ko
217 IMPL_UNO_CONSTRUCTOR( CharToNumHangul_ko )
218 IMPL_UNO_CONSTRUCTOR( CharToNumLower_ko )
219 IMPL_UNO_CONSTRUCTOR( CharToNumUpper_ko )
220 #endif
221 IMPL_UNO_CONSTRUCTOR( CharToNumIndic_ar )
222 IMPL_UNO_CONSTRUCTOR( CharToNumEastIndic_ar )
223 #if WITH_LOCALE_ALL || WITH_LOCALE_hi
224 IMPL_UNO_CONSTRUCTOR( CharToNumIndic_hi )
225 #endif
226 #if WITH_LOCALE_ALL || WITH_LOCALE_th
227 IMPL_UNO_CONSTRUCTOR( CharToNum_th )
228 #endif
229 
230 #if WITH_LOCALE_ALL || WITH_LOCALE_zh
231 IMPL_UNO_CONSTRUCTOR( NumToTextLower_zh_CN )
232 IMPL_UNO_CONSTRUCTOR( NumToTextUpper_zh_CN )
233 IMPL_UNO_CONSTRUCTOR( NumToTextLower_zh_TW )
234 IMPL_UNO_CONSTRUCTOR( NumToTextUpper_zh_TW )
235 IMPL_UNO_CONSTRUCTOR( NumToTextFullwidth_zh_CN )
236 IMPL_UNO_CONSTRUCTOR( NumToTextFullwidth_zh_TW )
237 #endif
238 IMPL_CREATEINSTANCE( NumToTextFullwidth_ja_JP )
239 IMPL_CREATEINSTANCE( NumToTextFullwidth_ko )
240 IMPL_CREATEINSTANCE( NumToTextKanjiLongModern_ja_JP )
241 IMPL_CREATEINSTANCE( NumToTextKanjiLongTraditional_ja_JP )
242 IMPL_CREATEINSTANCE( NumToTextKanjiShortModern_ja_JP )
243 IMPL_CREATEINSTANCE( NumToTextKanjiShortTraditional_ja_JP )
244 #if WITH_LOCALE_ALL || WITH_LOCALE_ko
245 IMPL_UNO_CONSTRUCTOR (NumToTextInformalHangul_ko)
246 IMPL_UNO_CONSTRUCTOR (NumToTextInformalLower_ko)
247 IMPL_UNO_CONSTRUCTOR (NumToTextInformalUpper_ko)
248 IMPL_UNO_CONSTRUCTOR (NumToTextFormalHangul_ko)
249 IMPL_UNO_CONSTRUCTOR (NumToTextFormalLower_ko)
250 IMPL_UNO_CONSTRUCTOR (NumToTextFormalUpper_ko)
251 #endif
252 
253 IMPL_CREATEINSTANCE( TextToNumLower_zh_CN )
254 IMPL_CREATEINSTANCE( TextToNumUpper_zh_CN )
255 IMPL_CREATEINSTANCE( TextToNumLower_zh_TW )
256 IMPL_CREATEINSTANCE( TextToNumUpper_zh_TW )
257 IMPL_CREATEINSTANCE( TextToNumKanjiLongModern_ja_JP )
258 IMPL_CREATEINSTANCE( TextToNumKanjiLongTraditional_ja_JP )
259 IMPL_CREATEINSTANCE( TextToNumFormalHangul_ko )
260 IMPL_CREATEINSTANCE( TextToNumFormalLower_ko )
261 IMPL_CREATEINSTANCE( TextToNumFormalUpper_ko )
262 IMPL_CREATEINSTANCE( TextToNumInformalHangul_ko )
263 IMPL_CREATEINSTANCE( TextToNumInformalUpper_ko )
264 IMPL_CREATEINSTANCE( TextToNumInformalLower_ko )
265 
266 IMPL_CREATEINSTANCE( NumToTextDate_zh )
267 #if WITH_LOCALE_ALL || WITH_LOCALE_ja
268 IMPL_UNO_CONSTRUCTOR (NumToTextAIUFullWidth_ja_JP)
269 IMPL_UNO_CONSTRUCTOR (NumToTextAIUHalfWidth_ja_JP)
270 IMPL_UNO_CONSTRUCTOR (NumToTextIROHAFullWidth_ja_JP)
271 IMPL_UNO_CONSTRUCTOR (NumToTextIROHAHalfWidth_ja_JP)
272 #endif
273 IMPL_CREATEINSTANCE( NumToTextCircledNumber )
274 #if WITH_LOCALE_ALL || WITH_LOCALE_ko
275 IMPL_UNO_CONSTRUCTOR (NumToTextHangulJamo_ko)
276 IMPL_UNO_CONSTRUCTOR (NumToTextHangulSyllable_ko)
277 IMPL_UNO_CONSTRUCTOR (NumToTextHangulCircledJamo_ko)
278 IMPL_UNO_CONSTRUCTOR (NumToTextHangulCircledSyllable_ko)
279 #endif
280 IMPL_CREATEINSTANCE( NumToTextTianGan_zh )
281 IMPL_CREATEINSTANCE( NumToTextDiZi_zh )
282 
283 #if WITH_LOCALE_ALL || WITH_LOCALE_ja
284 IMPL_UNO_CONSTRUCTOR (FULLWIDTHKATAKANA_HALFWIDTHKATAKANA)
286 IMPL_UNO_CONSTRUCTOR (FULLWIDTH_HALFWIDTH_LIKE_ASC)
288 #endif
289 
290 namespace {
291 
292 typedef uno::Reference< uno::XInterface > (*FN_CreateInstance)(
293  const uno::Reference< lang::XMultiServiceFactory >& );
294 
295 struct InstancesArray {
296  const char* pServiceNm;
297  const char* pImplementationNm;
298  FN_CreateInstance pFn;
299 };
300 
301 }
302 
303 const InstancesArray aInstances[] = {
305  TRLT_IMPLNAME_PREFIX "UPPERCASE_LOWERCASE",
306  &Transliteration_u2l_CreateInstance },
308  TRLT_IMPLNAME_PREFIX "LOWERCASE_UPPERCASE",
309  &Transliteration_l2u_CreateInstance },
311  TRLT_IMPLNAME_PREFIX "SENTENCE_CASE",
312  &Transliteration_sentencecase_CreateInstance },
314  TRLT_IMPLNAME_PREFIX "TITLE_CASE",
315  &Transliteration_titlecase_CreateInstance },
317  TRLT_IMPLNAME_PREFIX "TOGGLE_CASE",
318  &Transliteration_togglecase_CreateInstance },
319 #if WITH_LOCALE_ALL || WITH_LOCALE_ja
321  TRLT_IMPLNAME_PREFIX "HIRAGANA_KATAKANA",
322  &hiraganaToKatakana_CreateInstance },
324  TRLT_IMPLNAME_PREFIX "KATAKANA_HIRAGANA",
325  &katakanaToHiragana_CreateInstance },
327  TRLT_IMPLNAME_PREFIX "FULLWIDTH_HALFWIDTH",
328  &fullwidthToHalfwidth_CreateInstance },
330  TRLT_IMPLNAME_PREFIX "HALFWIDTH_FULLWIDTH",
331  &halfwidthToFullwidth_CreateInstance },
332 #endif
333 #if WITH_LOCALE_ALL || WITH_LOCALE_ja
352 #endif
353 #if WITH_LOCALE_ALL || WITH_LOCALE_zh
354  IMPL_TRANSLITERATION_ITEM (TextToPinyin_zh_CN),
355  IMPL_TRANSLITERATION_ITEM (TextToChuyin_zh_TW),
356 #endif
358  IMPL_TRANSLITERATION_ITEM (ignoreKashida_CTL),
359 
360 #if WITH_LOCALE_ALL || WITH_LOCALE_zh
361  IMPL_TRANSLITERATION_ITEM (NumToCharUpper_zh_CN),
362  IMPL_TRANSLITERATION_ITEM (NumToCharLower_zh_CN),
363  IMPL_TRANSLITERATION_ITEM (NumToCharUpper_zh_TW),
364  IMPL_TRANSLITERATION_ITEM (NumToCharLower_zh_TW),
365 #endif
366 #if WITH_LOCALE_ALL || WITH_LOCALE_ja
367  IMPL_TRANSLITERATION_ITEM (NumToCharHalfwidth),
368  IMPL_TRANSLITERATION_ITEM (NumToCharFullwidth),
369  IMPL_TRANSLITERATION_ITEM (NumToCharKanjiShort_ja_JP),
370  IMPL_TRANSLITERATION_ITEM (NumToCharKanjiTraditional_ja_JP),
371 #endif
372 #if WITH_LOCALE_ALL || WITH_LOCALE_ko
373  IMPL_TRANSLITERATION_ITEM (NumToCharLower_ko),
374  IMPL_TRANSLITERATION_ITEM (NumToCharUpper_ko),
375  IMPL_TRANSLITERATION_ITEM (NumToCharHangul_ko),
376 #endif
377  IMPL_TRANSLITERATION_ITEM (NumToCharIndic_ar),
378 #if WITH_LOCALE_ALL || WITH_LOCALE_hi
379  IMPL_TRANSLITERATION_ITEM (NumToCharIndic_hi),
380 #endif
381 #if WITH_LOCALE_ALL || WITH_LOCALE_th
382  IMPL_TRANSLITERATION_ITEM (NumToChar_th),
383 #endif
384 
385 #if WITH_LOCALE_ALL || WITH_LOCALE_ja
386  IMPL_TRANSLITERATION_ITEM (NumToTextFullwidth_ja_JP),
387 #endif
388 #if WITH_LOCALE_ALL || WITH_LOCALE_ko
389  IMPL_TRANSLITERATION_ITEM (NumToTextFullwidth_ko),
390 #endif
391 #if WITH_LOCALE_ALL || WITH_LOCALE_ja
392  IMPL_TRANSLITERATION_ITEM (NumToTextKanjiLongModern_ja_JP),
393  IMPL_TRANSLITERATION_ITEM (NumToTextKanjiLongTraditional_ja_JP),
394  IMPL_TRANSLITERATION_ITEM (NumToTextKanjiShortModern_ja_JP),
395  IMPL_TRANSLITERATION_ITEM (NumToTextKanjiShortTraditional_ja_JP),
396 #endif
397 
398 #if WITH_LOCALE_ALL || WITH_LOCALE_zh
399  IMPL_TRANSLITERATION_ITEM (TextToNumUpper_zh_CN),
400  IMPL_TRANSLITERATION_ITEM (TextToNumLower_zh_CN),
401  IMPL_TRANSLITERATION_ITEM (TextToNumUpper_zh_TW),
402  IMPL_TRANSLITERATION_ITEM (TextToNumLower_zh_TW),
403 #endif
404 #if WITH_LOCALE_ALL || WITH_LOCALE_ja
405  IMPL_TRANSLITERATION_ITEM (TextToNumKanjiLongModern_ja_JP),
406  IMPL_TRANSLITERATION_ITEM (TextToNumKanjiLongTraditional_ja_JP),
407 #endif
408 #if WITH_LOCALE_ALL || WITH_LOCALE_ko
409  IMPL_TRANSLITERATION_ITEM (TextToNumInformalHangul_ko),
410  IMPL_TRANSLITERATION_ITEM (TextToNumInformalLower_ko),
411  IMPL_TRANSLITERATION_ITEM (TextToNumInformalUpper_ko),
412  IMPL_TRANSLITERATION_ITEM (TextToNumFormalHangul_ko),
413  IMPL_TRANSLITERATION_ITEM (TextToNumFormalLower_ko),
414  IMPL_TRANSLITERATION_ITEM (TextToNumFormalUpper_ko),
415 #endif
416 
417 #if WITH_LOCALE_ALL || WITH_LOCALE_zh
418  IMPL_TRANSLITERATION_ITEM (NumToTextDate_zh),
419 #endif
420  IMPL_TRANSLITERATION_ITEM (NumToTextCircledNumber),
421 #if WITH_LOCALE_ALL || WITH_LOCALE_zh
422  IMPL_TRANSLITERATION_ITEM (NumToTextTianGan_zh),
423  IMPL_TRANSLITERATION_ITEM (NumToTextDiZi_zh),
424 #endif
425 
426 // add here new services !!
427  { nullptr, nullptr, nullptr }
428 };
429 
430 
431 extern "C"
432 {
433 
434 SAL_DLLPUBLIC_EXPORT void* i18npool_component_getFactory( const char* sImplementationName, void* _pServiceManager, SAL_UNUSED_PARAMETER void* /*_pRegistryKey*/ )
435 {
436  void* pRet = nullptr;
437 
438  lang::XMultiServiceFactory* pServiceManager =
439  static_cast< lang::XMultiServiceFactory* >( _pServiceManager );
440  uno::Reference< lang::XSingleServiceFactory > xFactory;
441 
442  for( const InstancesArray* pArr = aInstances; pArr->pServiceNm; ++pArr )
443  {
444  if( 0 == rtl_str_compare( sImplementationName, pArr->pImplementationNm ) )
445  {
446  uno::Sequence< OUString > aServiceNames {
447  OUString::createFromAscii( pArr->pServiceNm ) };
448  xFactory = ::cppu::createSingleFactory(
449  pServiceManager,
450  OUString::createFromAscii( pArr->pImplementationNm ),
451  *pArr->pFn, aServiceNames );
452  break;
453  }
454  }
455 
456  if ( xFactory.is() )
457  {
458  xFactory->acquire();
459  pRet = xFactory.get();
460  }
461 
462  return pRet;
463 }
464 
465 } // "C"
466 
467 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const InstancesArray aInstances[]
#define IMPL_UNO_CONSTRUCTOR(ImplName)
Sequence< OUString > aServiceNames
#define IMPL_TRANSLITERATION_ITEM(implName)
#define IMPL_UNO_CONSTRUCTOR_CTX(ImplName)
#define TRLT_IMPLNAME_PREFIX
Definition: servicename.hxx:62
#define TRLT_SERVICELNAME_L10N
Definition: servicename.hxx:60
Constant values shared between i18npool and, for example, the number formatter.
SAL_DLLPUBLIC_EXPORT void * i18npool_component_getFactory(const char *sImplementationName, void *_pServiceManager, SAL_UNUSED_PARAMETER void *)
Reference< XSingleServiceFactory > xFactory
#define IMPL_CREATEINSTANCE(ImplName)