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 
108 IMPL_CREATEINSTANCE( ignoreKashida_CTL )
109 IMPL_CREATEINSTANCE( NumToCharIndic_ar )
110 IMPL_CREATEINSTANCE( NumToTextCircledNumber )
125 IMPL_UNO_CONSTRUCTOR( CharToNumEastIndic_ar )
126 IMPL_UNO_CONSTRUCTOR( CharToNumIndic_ar )
133 IMPL_UNO_CONSTRUCTOR( NumToCharEastIndic_ar )
134 
135 #if WITH_LOCALE_ALL || WITH_LOCALE_hi
136 IMPL_CREATEINSTANCE( NumToCharIndic_hi )
137 IMPL_UNO_CONSTRUCTOR( CharToNumIndic_hi )
139 #endif
140 
141 #if WITH_LOCALE_ALL || WITH_LOCALE_ja
142 IMPL_CREATEINSTANCE( fullwidthToHalfwidth )
144 IMPL_CREATEINSTANCE( hiraganaToKatakana )
145 IMPL_CREATEINSTANCE( ignoreBaFa_ja_JP )
146 IMPL_CREATEINSTANCE( ignoreHyuByu_ja_JP )
147 IMPL_CREATEINSTANCE( ignoreIandEfollowedByYa_ja_JP )
148 IMPL_CREATEINSTANCE( ignoreIterationMark_ja_JP )
149 IMPL_CREATEINSTANCE( ignoreKiKuFollowedBySa_ja_JP )
150 IMPL_CREATEINSTANCE( ignoreMiddleDot_ja_JP )
151 IMPL_CREATEINSTANCE( ignoreMinusSign_ja_JP )
152 IMPL_CREATEINSTANCE( ignoreProlongedSoundMark_ja_JP )
153 IMPL_CREATEINSTANCE( ignoreSeparator_ja_JP )
154 IMPL_CREATEINSTANCE( ignoreSeZe_ja_JP )
155 IMPL_CREATEINSTANCE( ignoreSize_ja_JP )
156 IMPL_CREATEINSTANCE( ignoreSpace_ja_JP )
157 IMPL_CREATEINSTANCE( ignoreTiJi_ja_JP )
158 IMPL_CREATEINSTANCE( ignoreTraditionalKana_ja_JP )
159 IMPL_CREATEINSTANCE( ignoreTraditionalKanji_ja_JP )
160 IMPL_CREATEINSTANCE( ignoreZiZu_ja_JP )
161 IMPL_CREATEINSTANCE( katakanaToHiragana )
162 IMPL_CREATEINSTANCE( largeToSmall_ja_JP )
163 IMPL_CREATEINSTANCE( NumToCharFullwidth )
164 IMPL_CREATEINSTANCE( NumToCharHalfwidth )
165 IMPL_CREATEINSTANCE( NumToCharKanjiShort_ja_JP )
166 IMPL_CREATEINSTANCE( NumToCharKanjiTraditional_ja_JP )
167 IMPL_CREATEINSTANCE( NumToTextFullwidth_ja_JP )
168 IMPL_CREATEINSTANCE( NumToTextKanjiLongModern_ja_JP )
169 IMPL_CREATEINSTANCE( NumToTextKanjiLongTraditional_ja_JP )
170 IMPL_CREATEINSTANCE( NumToTextKanjiShortModern_ja_JP )
171 IMPL_CREATEINSTANCE( NumToTextKanjiShortTraditional_ja_JP )
172 IMPL_CREATEINSTANCE( smallToLarge_ja_JP )
173 IMPL_CREATEINSTANCE( TextToNumKanjiLongModern_ja_JP )
174 IMPL_CREATEINSTANCE( TextToNumKanjiLongTraditional_ja_JP )
176 IMPL_UNO_CONSTRUCTOR( CharToNumFullwidth )
177 IMPL_UNO_CONSTRUCTOR( CharToNumKanjiShort_ja_JP )
178 IMPL_UNO_CONSTRUCTOR( CharToNumKanjiTraditional_ja_JP )
179 IMPL_UNO_CONSTRUCTOR_CTX( IndexEntrySupplier_ja_phonetic_alphanumeric_first_by_consonant )
180 IMPL_UNO_CONSTRUCTOR_CTX( IndexEntrySupplier_ja_phonetic_alphanumeric_first_by_syllable )
181 IMPL_UNO_CONSTRUCTOR_CTX( IndexEntrySupplier_ja_phonetic_alphanumeric_last_by_consonant )
182 IMPL_UNO_CONSTRUCTOR_CTX( IndexEntrySupplier_ja_phonetic_alphanumeric_last_by_syllable )
183 IMPL_UNO_CONSTRUCTOR( FULLWIDTH_HALFWIDTH_LIKE_ASC )
184 IMPL_UNO_CONSTRUCTOR( FULLWIDTHKATAKANA_HALFWIDTHKATAKANA )
187 IMPL_UNO_CONSTRUCTOR( NumToTextAIUFullWidth_ja_JP )
188 IMPL_UNO_CONSTRUCTOR( NumToTextAIUHalfWidth_ja_JP )
189 IMPL_UNO_CONSTRUCTOR( NumToTextIROHAFullWidth_ja_JP )
190 IMPL_UNO_CONSTRUCTOR( NumToTextIROHAHalfWidth_ja_JP )
191 #endif
192 
193 #if WITH_LOCALE_ALL || WITH_LOCALE_ko
194 IMPL_CREATEINSTANCE( NumToCharHangul_ko )
195 IMPL_CREATEINSTANCE( NumToCharLower_ko )
196 IMPL_CREATEINSTANCE( NumToCharUpper_ko )
197 IMPL_CREATEINSTANCE( NumToTextFullwidth_ko )
198 IMPL_CREATEINSTANCE( TextToNumFormalHangul_ko )
199 IMPL_CREATEINSTANCE( TextToNumFormalLower_ko )
200 IMPL_CREATEINSTANCE( TextToNumFormalUpper_ko )
201 IMPL_CREATEINSTANCE( TextToNumInformalHangul_ko )
202 IMPL_CREATEINSTANCE( TextToNumInformalLower_ko )
203 IMPL_CREATEINSTANCE( TextToNumInformalUpper_ko )
205 IMPL_UNO_CONSTRUCTOR( CharToNumHangul_ko )
206 IMPL_UNO_CONSTRUCTOR( CharToNumLower_ko )
207 IMPL_UNO_CONSTRUCTOR( CharToNumUpper_ko )
209 IMPL_UNO_CONSTRUCTOR( NumToTextFormalHangul_ko )
210 IMPL_UNO_CONSTRUCTOR( NumToTextFormalLower_ko )
211 IMPL_UNO_CONSTRUCTOR( NumToTextFormalUpper_ko )
212 IMPL_UNO_CONSTRUCTOR( NumToTextHangulCircledJamo_ko )
213 IMPL_UNO_CONSTRUCTOR( NumToTextHangulCircledSyllable_ko )
214 IMPL_UNO_CONSTRUCTOR( NumToTextHangulJamo_ko )
215 IMPL_UNO_CONSTRUCTOR( NumToTextHangulSyllable_ko )
216 IMPL_UNO_CONSTRUCTOR( NumToTextInformalHangul_ko )
217 IMPL_UNO_CONSTRUCTOR( NumToTextInformalLower_ko )
218 IMPL_UNO_CONSTRUCTOR( NumToTextInformalUpper_ko )
219 #endif
220 
221 #if WITH_LOCALE_ALL || WITH_LOCALE_th
222 IMPL_CREATEINSTANCE( NumToChar_th )
224 IMPL_UNO_CONSTRUCTOR( CharToNum_th )
226 #endif
227 
228 #if WITH_LOCALE_ALL || WITH_LOCALE_zh
229 IMPL_CREATEINSTANCE( NumToCharLower_zh_CN )
230 IMPL_CREATEINSTANCE( NumToCharLower_zh_TW )
231 IMPL_CREATEINSTANCE( NumToCharUpper_zh_CN )
232 IMPL_CREATEINSTANCE( NumToCharUpper_zh_TW )
233 IMPL_CREATEINSTANCE( NumToTextDate_zh )
234 IMPL_CREATEINSTANCE( NumToTextDiZi_zh )
235 IMPL_CREATEINSTANCE( NumToTextTianGan_zh )
236 IMPL_CREATEINSTANCE( TextToChuyin_zh_TW )
237 IMPL_CREATEINSTANCE( TextToNumLower_zh_CN )
238 IMPL_CREATEINSTANCE( TextToNumLower_zh_TW )
239 IMPL_CREATEINSTANCE( TextToNumUpper_zh_CN )
240 IMPL_CREATEINSTANCE( TextToNumUpper_zh_TW )
241 IMPL_CREATEINSTANCE( TextToPinyin_zh_CN )
244 IMPL_UNO_CONSTRUCTOR( CharToNumLower_zh_CN )
245 IMPL_UNO_CONSTRUCTOR( CharToNumLower_zh_TW )
246 IMPL_UNO_CONSTRUCTOR( CharToNumUpper_zh_CN )
247 IMPL_UNO_CONSTRUCTOR( CharToNumUpper_zh_TW )
249 IMPL_UNO_CONSTRUCTOR( NumToTextFullwidth_zh_CN )
250 IMPL_UNO_CONSTRUCTOR( NumToTextFullwidth_zh_TW )
251 IMPL_UNO_CONSTRUCTOR( NumToTextLower_zh_CN )
252 IMPL_UNO_CONSTRUCTOR( NumToTextLower_zh_TW )
253 IMPL_UNO_CONSTRUCTOR( NumToTextUpper_zh_CN )
254 IMPL_UNO_CONSTRUCTOR( NumToTextUpper_zh_TW )
255 #endif
256 
257 namespace {
258 
259 typedef uno::Reference< uno::XInterface > (*FN_CreateInstance)(
260  const uno::Reference< lang::XMultiServiceFactory >& );
261 
262 struct InstancesArray {
263  const char* pServiceNm;
264  const char* pImplementationNm;
265  FN_CreateInstance pFn;
266 };
267 
268 }
269 
270 const InstancesArray aInstances[] = {
272  TRLT_IMPLNAME_PREFIX "UPPERCASE_LOWERCASE",
273  &Transliteration_u2l_CreateInstance },
275  TRLT_IMPLNAME_PREFIX "LOWERCASE_UPPERCASE",
276  &Transliteration_l2u_CreateInstance },
278  TRLT_IMPLNAME_PREFIX "SENTENCE_CASE",
279  &Transliteration_sentencecase_CreateInstance },
281  TRLT_IMPLNAME_PREFIX "TITLE_CASE",
282  &Transliteration_titlecase_CreateInstance },
284  TRLT_IMPLNAME_PREFIX "TOGGLE_CASE",
285  &Transliteration_togglecase_CreateInstance },
286 
287  IMPL_TRANSLITERATION_ITEM( NumToCharIndic_ar ),
289  IMPL_TRANSLITERATION_ITEM( ignoreKashida_CTL ),
290  IMPL_TRANSLITERATION_ITEM( NumToTextCircledNumber ),
291 
292 #if WITH_LOCALE_ALL || WITH_LOCALE_hi
293  IMPL_TRANSLITERATION_ITEM( NumToCharIndic_hi ),
294 #endif
295 
296 #if WITH_LOCALE_ALL || WITH_LOCALE_ja
298  TRLT_IMPLNAME_PREFIX "HIRAGANA_KATAKANA",
299  &hiraganaToKatakana_CreateInstance },
301  TRLT_IMPLNAME_PREFIX "KATAKANA_HIRAGANA",
302  &katakanaToHiragana_CreateInstance },
304  TRLT_IMPLNAME_PREFIX "FULLWIDTH_HALFWIDTH",
305  &fullwidthToHalfwidth_CreateInstance },
307  TRLT_IMPLNAME_PREFIX "HALFWIDTH_FULLWIDTH",
308  &halfwidthToFullwidth_CreateInstance },
309 
327  IMPL_TRANSLITERATION_ITEM( NumToCharFullwidth ),
328  IMPL_TRANSLITERATION_ITEM( NumToCharHalfwidth ),
329  IMPL_TRANSLITERATION_ITEM( NumToCharKanjiShort_ja_JP ),
330  IMPL_TRANSLITERATION_ITEM( NumToCharKanjiTraditional_ja_JP ),
331  IMPL_TRANSLITERATION_ITEM( NumToTextFullwidth_ja_JP ),
332  IMPL_TRANSLITERATION_ITEM( NumToTextKanjiLongModern_ja_JP ),
333  IMPL_TRANSLITERATION_ITEM( NumToTextKanjiLongTraditional_ja_JP ),
334  IMPL_TRANSLITERATION_ITEM( NumToTextKanjiShortModern_ja_JP ),
335  IMPL_TRANSLITERATION_ITEM( NumToTextKanjiShortTraditional_ja_JP ),
337  IMPL_TRANSLITERATION_ITEM( TextToNumKanjiLongModern_ja_JP ),
338  IMPL_TRANSLITERATION_ITEM( TextToNumKanjiLongTraditional_ja_JP ),
339 #endif
340 
341 #if WITH_LOCALE_ALL || WITH_LOCALE_ko
342  IMPL_TRANSLITERATION_ITEM( NumToCharHangul_ko ),
343  IMPL_TRANSLITERATION_ITEM( NumToCharLower_ko ),
344  IMPL_TRANSLITERATION_ITEM( NumToCharUpper_ko ),
345  IMPL_TRANSLITERATION_ITEM( NumToTextFullwidth_ko ),
346  IMPL_TRANSLITERATION_ITEM( TextToNumFormalHangul_ko ),
347  IMPL_TRANSLITERATION_ITEM( TextToNumFormalLower_ko ),
348  IMPL_TRANSLITERATION_ITEM( TextToNumFormalUpper_ko ),
349  IMPL_TRANSLITERATION_ITEM( TextToNumInformalHangul_ko ),
350  IMPL_TRANSLITERATION_ITEM( TextToNumInformalLower_ko ),
351  IMPL_TRANSLITERATION_ITEM( TextToNumInformalUpper_ko ),
352 #endif
353 
354 #if WITH_LOCALE_ALL || WITH_LOCALE_th
355  IMPL_TRANSLITERATION_ITEM( NumToChar_th ),
356 #endif
357 
358 #if WITH_LOCALE_ALL || WITH_LOCALE_zh
359  IMPL_TRANSLITERATION_ITEM( NumToCharLower_zh_CN ),
360  IMPL_TRANSLITERATION_ITEM( NumToCharLower_zh_TW ),
361  IMPL_TRANSLITERATION_ITEM( NumToCharUpper_zh_CN ),
362  IMPL_TRANSLITERATION_ITEM( NumToCharUpper_zh_TW ),
363  IMPL_TRANSLITERATION_ITEM( NumToTextDate_zh ),
364  IMPL_TRANSLITERATION_ITEM( NumToTextDiZi_zh ),
365  IMPL_TRANSLITERATION_ITEM( NumToTextTianGan_zh ),
366  IMPL_TRANSLITERATION_ITEM( TextToChuyin_zh_TW ),
367  IMPL_TRANSLITERATION_ITEM( TextToNumLower_zh_CN ),
368  IMPL_TRANSLITERATION_ITEM( TextToNumLower_zh_TW ),
369  IMPL_TRANSLITERATION_ITEM( TextToNumUpper_zh_CN ),
370  IMPL_TRANSLITERATION_ITEM( TextToNumUpper_zh_TW ),
371  IMPL_TRANSLITERATION_ITEM( TextToPinyin_zh_CN ),
372 #endif
373 
374  { nullptr, nullptr, nullptr }
375 };
376 
377 
378 extern "C"
379 {
380 
381 SAL_DLLPUBLIC_EXPORT void* i18npool_component_getFactory( const char* sImplementationName, void* _pServiceManager, SAL_UNUSED_PARAMETER void* /*_pRegistryKey*/ )
382 {
383  void* pRet = nullptr;
384 
385  lang::XMultiServiceFactory* pServiceManager =
386  static_cast< lang::XMultiServiceFactory* >( _pServiceManager );
387  uno::Reference< lang::XSingleServiceFactory > xFactory;
388 
389  for( const InstancesArray* pArr = aInstances; pArr->pServiceNm; ++pArr )
390  {
391  if( 0 == rtl_str_compare( sImplementationName, pArr->pImplementationNm ) )
392  {
393  uno::Sequence< OUString > aServiceNames {
394  OUString::createFromAscii( pArr->pServiceNm ) };
395  xFactory = ::cppu::createSingleFactory(
396  pServiceManager,
397  OUString::createFromAscii( pArr->pImplementationNm ),
398  *pArr->pFn, aServiceNames );
399  break;
400  }
401  }
402 
403  if ( xFactory.is() )
404  {
405  xFactory->acquire();
406  pRet = xFactory.get();
407  }
408 
409  return pRet;
410 }
411 
412 } // "C"
413 
414 /* 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:61
#define TRLT_SERVICELNAME_L10N
Definition: servicename.hxx:59
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)