LibreOffice Module i18npool (master) 1
transliterationImpl.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
22#include <servicename.hxx>
23
24#include <com/sun/star/i18n/LocaleData2.hpp>
25#include <com/sun/star/i18n/TransliterationType.hpp>
26#include <com/sun/star/i18n/TransliterationModulesExtra.hpp>
27
30#include <o3tl/string_view.hxx>
31#include <rtl/ustring.hxx>
32
33#include <algorithm>
34#include <mutex>
35#include <numeric>
36
37using namespace com::sun::star::uno;
38using namespace com::sun::star::i18n;
39using namespace com::sun::star::lang;
40
41
42namespace i18npool {
43
44#define TmItem1( name ) \
45 {TransliterationModules_##name, TransliterationModulesNew_##name, #name}
46
47#define TmItem2( name ) \
48 {TransliterationModules(0), TransliterationModulesNew_##name, #name}
49
50namespace {
51
52// Ignore Module list
53struct TMList {
54 TransliterationModules tm;
55 TransliterationModulesNew tmn;
56 const char *implName;
57};
58
59}
60
61TMList const TMlist[] = { // Modules ModulesNew
62 TmItem1 (IGNORE_CASE), // 0. (1<<8 256) (7)
63 TmItem1 (IGNORE_WIDTH), // 1. (1<<9 512) (8)
64 TmItem1 (IGNORE_KANA), // 2. (1<<10 1024) (9)
65// No enum define for this trans. application has to use impl name to load it
66// TmItem1 (IGNORE_CASE_SIMPLE), // (1<<11 1024) (66)
67
68 TmItem1 (IgnoreTraditionalKanji_ja_JP), // 3. (1<<12 4096) (10)
69 TmItem1 (IgnoreTraditionalKana_ja_JP), // 4. (1<<13 8192) (11)
70 TmItem1 (IgnoreMinusSign_ja_JP), // 5. (1<<13 16384) (12)
71 TmItem1 (IgnoreIterationMark_ja_JP), // 6. (1<<14 32768) (13)
72 TmItem1 (IgnoreSeparator_ja_JP), // 7. (1<<15 65536) (14)
73 TmItem1 (IgnoreSize_ja_JP), // 15. (1<<23 16777216) (22)
74 TmItem1 (IgnoreMiddleDot_ja_JP), // 17. (1<<25 67108864) (24)
75 TmItem1 (IgnoreSpace_ja_JP), // 18. (1<<26 134217728) (25)
76 TmItem1 (IgnoreZiZu_ja_JP), // 8. (1<<16 131072) (15)
77 TmItem1 (IgnoreBaFa_ja_JP), // 9. (1<<17 262144) (16)
78 TmItem1 (IgnoreTiJi_ja_JP), // 10. (1<<18 524288) (17)
79 TmItem1 (IgnoreHyuByu_ja_JP), // 11. (1<<19 1048576) (18)
80 TmItem1 (IgnoreSeZe_ja_JP), // 12. (1<<20 2097152) (19)
81 TmItem1 (IgnoreIandEfollowedByYa_ja_JP), // 13. (1<<21 4194304) (20)
82 TmItem1 (IgnoreKiKuFollowedBySa_ja_JP), // 14. (1<<22 8388608) (21)
83 TmItem1 (IgnoreProlongedSoundMark_ja_JP), // 16. (1<<24 33554432) (23)
84
85 TmItem1 (UPPERCASE_LOWERCASE), // 19. (1) (1)
86 TmItem1 (LOWERCASE_UPPERCASE), // 20. (2) (2)
87 TmItem1 (HALFWIDTH_FULLWIDTH), // 21. (3) (3)
88 TmItem1 (FULLWIDTH_HALFWIDTH), // 22. (4) (4)
89 TmItem1 (KATAKANA_HIRAGANA), // 23. (5) (5)
90 TmItem1 (HIRAGANA_KATAKANA), // 24. (6) (6)
91
92 TmItem1 (SmallToLarge_ja_JP), // 25. (1<<27 268435456) (26)
93 TmItem1 (LargeToSmall_ja_JP), // 26. (1<<28 536870912) (27)
94 TmItem2 (NumToTextLower_zh_CN), // 27. () (28)
95 TmItem2 (NumToTextUpper_zh_CN), // 28. () (29)
96 TmItem2 (NumToTextLower_zh_TW), // 29. () (30)
97 TmItem2 (NumToTextUpper_zh_TW), // 30. () (31)
98 TmItem2 (NumToTextFormalHangul_ko), // 31. () (32)
99 TmItem2 (NumToTextFormalLower_ko), // 32. () (33)
100 TmItem2 (NumToTextFormalUpper_ko), // 33. () (34)
101 TmItem2 (NumToTextInformalHangul_ko), // 34. () (35)
102 TmItem2 (NumToTextInformalLower_ko), // 35. () (36)
103 TmItem2 (NumToTextInformalUpper_ko), // 36. () (37)
104 TmItem2 (NumToCharLower_zh_CN), // 37. () (38)
105 TmItem2 (NumToCharUpper_zh_CN), // 38. () (39)
106 TmItem2 (NumToCharLower_zh_TW), // 39. () (40)
107 TmItem2 (NumToCharUpper_zh_TW), // 40. () (41)
108 TmItem2 (NumToCharHangul_ko), // 41. () (42)
109 TmItem2 (NumToCharLower_ko), // 42. () (43)
110 TmItem2 (NumToCharUpper_ko), // 43. () (44)
111 TmItem2 (NumToCharFullwidth), // 44. () (45)
112 TmItem2 (NumToCharKanjiShort_ja_JP), // 45. () (46)
113 TmItem2 (TextToNumLower_zh_CN), // 46. () (47)
114 TmItem2 (TextToNumUpper_zh_CN), // 47. () (48)
115 TmItem2 (TextToNumLower_zh_TW), // 48. () (49)
116 TmItem2 (TextToNumUpper_zh_TW), // 49. () (50)
117 TmItem2 (TextToNumFormalHangul_ko), // 50. () (51)
118 TmItem2 (TextToNumFormalLower_ko), // 51. () (52)
119 TmItem2 (TextToNumFormalUpper_ko), // 52. () (53)
120 TmItem2 (TextToNumInformalHangul_ko), // 53. () (54)
121 TmItem2 (TextToNumInformalLower_ko), // 54. () (55)
122 TmItem2 (TextToNumInformalUpper_ko), // 55. () (56)
123
124 TmItem2 (CharToNumLower_zh_CN), // 56. () (59)
125 TmItem2 (CharToNumUpper_zh_CN), // 57. () (60)
126 TmItem2 (CharToNumLower_zh_TW), // 58. () (61)
127 TmItem2 (CharToNumUpper_zh_TW), // 59. () (62)
128 TmItem2 (CharToNumHangul_ko), // 60. () (63)
129 TmItem2 (CharToNumLower_ko), // 61. () (64)
130 TmItem2 (CharToNumUpper_ko), // 62. () (65)
131
132// no enum defined for these trans. application has to use impl name to load them
133// TmItem2 (NumToCharArabic_Indic), // () (67)
134// TmItem2 (NumToCharEstern_Arabic_Indic),// () (68)
135// TmItem2 (NumToCharIndic), // () (69)
136// TmItem2 (NumToCharThai), // () (70)
137 {TransliterationModules(0), TransliterationModulesNew(0), nullptr}
138};
139
140// Constructor/Destructor
142{
143 numCascade = 0;
144 caseignoreOnly = true;
145
146 mxLocaledata.set(LocaleData2::create(xContext));
147}
148
150{
151 mxLocaledata.clear();
152 clear();
153}
154
155
156// Methods
157OUString SAL_CALL
159{
160 if (numCascade == 1 && bodyCascade[0].is())
161 return bodyCascade[0]->getName();
162 if (numCascade < 1)
163 return ( OUString("Not Loaded"));
164 throw RuntimeException();
165}
166
167sal_Int16 SAL_CALL
169{
170 if (numCascade > 1)
171 return (TransliterationType::CASCADE|TransliterationType::IGNORE);
172 if (numCascade > 0 && bodyCascade[0].is())
173 return bodyCascade[0]->getType();
174 throw RuntimeException();
175}
176
177static TransliterationModules operator&(TransliterationModules lhs, TransliterationModules rhs) {
178 return TransliterationModules(sal_Int32(lhs) & sal_Int32(rhs));
179}
180static TransliterationModules operator|(TransliterationModules lhs, TransliterationModules rhs) {
181 return TransliterationModules(sal_Int32(lhs) | sal_Int32(rhs));
182}
183
184void SAL_CALL
185TransliterationImpl::loadModule( TransliterationModules modType, const Locale& rLocale )
186{
187 clear();
188 if (bool(modType & TransliterationModules_IGNORE_MASK) &&
189 bool(modType & TransliterationModules_NON_IGNORE_MASK))
190 {
191 throw RuntimeException();
192 } else if (bool(modType & TransliterationModules_IGNORE_MASK)) {
193#define TransliterationModules_IGNORE_CASE_MASK (TransliterationModules_IGNORE_CASE | \
194 TransliterationModules_IGNORE_WIDTH | \
195 TransliterationModules_IGNORE_KANA)
196 TransliterationModules mask = ((modType & TransliterationModules_IGNORE_CASE_MASK) == modType) ?
197 TransliterationModules_IGNORE_CASE_MASK : TransliterationModules_IGNORE_MASK;
198 for (sal_Int16 i = 0; bool(TMlist[i].tm & mask); i++) {
199 if (bool(modType & TMlist[i].tm))
200 if (loadModuleByName(OUString::createFromAscii(TMlist[i].implName),
201 bodyCascade[numCascade], rLocale))
202 numCascade++;
203 }
204 // additional transliterations from TransliterationModulesExtra (we cannot extend TransliterationModules)
205 if (bool(modType & TransliterationModules(TransliterationModulesExtra::IGNORE_DIACRITICS_CTL)))
206 {
207 if (loadModuleByName(u"ignoreDiacritics_CTL", bodyCascade[numCascade], rLocale))
208 numCascade++;
209 }
210 if (bool(modType & TransliterationModules(TransliterationModulesExtra::IGNORE_KASHIDA_CTL)))
211 if (loadModuleByName(u"ignoreKashida_CTL", bodyCascade[numCascade], rLocale))
212 numCascade++;
213
214 } else if (bool(modType & TransliterationModules_NON_IGNORE_MASK)) {
215 for (sal_Int16 i = 0; bool(TMlist[i].tm); i++) {
216 if (TMlist[i].tm == modType) {
217 if (loadModuleByName(OUString::createFromAscii(TMlist[i].implName), bodyCascade[numCascade], rLocale))
218 numCascade++;
219 break;
220 }
221 }
222 }
223}
224
225void SAL_CALL
227{
228 clear();
229 TransliterationModules mask = TransliterationModules_END_OF_MODULE;
230 sal_Int32 count = modType.getLength();
231 if (count > maxCascade)
232 throw RuntimeException(); // could not handle more than maxCascade
233 for (sal_Int32 i = 0; i < count; i++) {
234 for (sal_Int16 j = 0; bool(TMlist[j].tmn); j++) {
235 if (TMlist[j].tmn == modType[i]) {
236 if (mask == TransliterationModules_END_OF_MODULE)
237 mask = bool(TMlist[i].tm) && bool(TMlist[i].tm & TransliterationModules_IGNORE_MASK) ?
238 TransliterationModules_IGNORE_MASK : TransliterationModules_NON_IGNORE_MASK;
239 else if (mask == TransliterationModules_IGNORE_MASK &&
240 (TMlist[i].tm&TransliterationModules_IGNORE_MASK) == TransliterationModules_END_OF_MODULE)
241 throw RuntimeException(); // could not mess up ignore trans. with non_ignore trans.
242 if (loadModuleByName(OUString::createFromAscii(TMlist[j].implName), bodyCascade[numCascade], rLocale))
243 numCascade++;
244 break;
245 }
246 }
247 }
248}
249
250void SAL_CALL
251TransliterationImpl::loadModuleByImplName(const OUString& implName, const Locale& rLocale)
252{
253 clear();
255 numCascade++;
256}
257
258
259void SAL_CALL
260TransliterationImpl::loadModulesByImplNames(const Sequence< OUString >& implNameList, const Locale& rLocale )
261{
262 if (implNameList.getLength() > maxCascade || implNameList.getLength() <= 0)
263 throw RuntimeException();
264
265 clear();
266 for (const auto& rName : implNameList)
267 if (loadModuleByName(rName, bodyCascade[numCascade], rLocale))
268 numCascade++;
269}
270
271
272Sequence<OUString> SAL_CALL
273TransliterationImpl::getAvailableModules( const Locale& rLocale, sal_Int16 sType )
274{
275 const Sequence<OUString> &translist = mxLocaledata->getTransliterations(rLocale);
276 std::vector<OUString> r;
277 r.reserve(translist.getLength());
279 for (const auto& rTrans : translist)
280 {
281 if (loadModuleByName(rTrans, body, rLocale)) {
282 if (body->getType() & sType)
283 r.push_back(rTrans);
284 body.clear();
285 }
286 }
288}
289
290
291OUString SAL_CALL
292TransliterationImpl::transliterate( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount,
293 Sequence< sal_Int32 >& offset )
294{
295 if (numCascade == 0)
296 return inStr;
297
298 if (numCascade == 1)
299 {
300 if ( startPos == 0 && nCount == inStr.getLength() )
301 return bodyCascade[0]->transliterate( inStr, 0, nCount, offset);
302 else
303 {
304 OUString tmpStr = inStr.copy(startPos, nCount);
305 tmpStr = bodyCascade[0]->transliterate(tmpStr, 0, nCount, offset);
306 if ( startPos )
307 {
308 for (sal_Int32 & j : asNonConstRange(offset))
309 j += startPos;
310 }
311 return tmpStr;
312 }
313 }
314 else
315 {
316 OUString tmpStr = inStr.copy(startPos, nCount);
317
318 auto [begin, end] = asNonConstRange(offset);
319 std::iota(begin, end, startPos);
320
322 Sequence<sal_Int32> to = offset;
323 for (sal_Int32 i = 0; i < numCascade; i++) {
324 tmpStr = bodyCascade[i]->transliterate(tmpStr, 0, nCount, from);
325
326 nCount = tmpStr.getLength();
327
328 assert(from.getLength() == nCount);
329 from.swap(to);
330 for (sal_Int32& ix : asNonConstRange(to))
331 ix = from[ix];
332 }
333 offset = to;
334 return tmpStr;
335 }
336}
337
338
339OUString SAL_CALL
340TransliterationImpl::folding( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount,
341 Sequence< sal_Int32 >& offset )
342{
343 if (numCascade == 0)
344 return inStr;
345
346 if (offset.getLength() != nCount)
347 offset.realloc(nCount);
348 if (numCascade == 1)
349 {
350 if ( startPos == 0 && nCount == inStr.getLength() )
351 return bodyCascade[0]->folding( inStr, 0, nCount, offset);
352 else
353 {
354 OUString tmpStr = inStr.copy(startPos, nCount);
355 tmpStr = bodyCascade[0]->folding(tmpStr, 0, nCount, offset);
356 if ( startPos )
357 {
358 for (sal_Int32 & j : asNonConstRange(offset))
359 j += startPos;
360 }
361 return tmpStr;
362 }
363 }
364 else
365 {
366 OUString tmpStr = inStr.copy(startPos, nCount);
367
368 auto [begin, end] = asNonConstRange(offset);
369 std::iota(begin, end, startPos);
370
372 Sequence<sal_Int32> to = offset;
373
374 for (sal_Int32 i = 0; i < numCascade; i++) {
375 tmpStr = bodyCascade[i]->folding(tmpStr, 0, nCount, from);
376
377 nCount = tmpStr.getLength();
378
379 assert(from.getLength() == nCount);
380 from.swap(to);
381 for (sal_Int32& ix : asNonConstRange(to))
382 ix = from[ix];
383 }
384 offset = to;
385 return tmpStr;
386 }
387}
388
389OUString SAL_CALL
390TransliterationImpl::transliterateString2String( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount )
391{
392 if (numCascade == 0)
393 return inStr;
394 else if (numCascade == 1)
395 return bodyCascade[0]->transliterateString2String( inStr, startPos, nCount);
396 else {
397 OUString tmpStr = bodyCascade[0]->transliterateString2String(inStr, startPos, nCount);
398
399 for (sal_Int32 i = 1; i < numCascade; i++)
400 tmpStr = bodyCascade[i]->transliterateString2String(tmpStr, 0, tmpStr.getLength());
401 return tmpStr;
402 }
403}
404
405OUString SAL_CALL
407{
408 if (numCascade == 0)
409 return OUString(&inChar, 1);
410 else if (numCascade == 1)
411 return bodyCascade[0]->transliterateChar2String( inChar);
412 else {
413 OUString tmpStr = bodyCascade[0]->transliterateChar2String(inChar);
414
415 for (sal_Int32 i = 1; i < numCascade; i++)
416 tmpStr = bodyCascade[i]->transliterateString2String(tmpStr, 0, tmpStr.getLength());
417 return tmpStr;
418 }
419}
420
421sal_Unicode SAL_CALL
423{
424 sal_Unicode tmpChar = inChar;
425 for (sal_Int32 i = 0; i < numCascade; i++)
426 tmpChar = bodyCascade[i]->transliterateChar2Char(tmpChar);
427 return tmpChar;
428}
429
430
431sal_Bool SAL_CALL
433 const OUString& str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32& nMatch1,
434 const OUString& str2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32& nMatch2)
435{
436 // since this is an API function make it user fail safe
437 if ( nCount1 < 0 ) {
438 pos1 += nCount1;
439 nCount1 = -nCount1;
440 }
441 if ( nCount2 < 0 ) {
442 pos2 += nCount2;
443 nCount2 = -nCount2;
444 }
445 if ( !nCount1 || !nCount2 ||
446 pos1 >= str1.getLength() || pos2 >= str2.getLength() ||
447 pos1 < 0 || pos2 < 0 ) {
448 nMatch1 = nMatch2 = 0;
449 // two empty strings return true, else false
450 return !nCount1 && !nCount2 && pos1 == str1.getLength() && pos2 == str2.getLength();
451 }
452 if ( pos1 + nCount1 > str1.getLength() )
453 nCount1 = str1.getLength() - pos1;
454 if ( pos2 + nCount2 > str2.getLength() )
455 nCount2 = str2.getLength() - pos2;
456
457 if (caseignoreOnly && caseignore.is())
458 return caseignore->equals(str1, pos1, nCount1, nMatch1, str2, pos2, nCount2, nMatch2);
459
460 Sequence<sal_Int32> offset1, offset2;
461
462 OUString tmpStr1 = folding(str1, pos1, nCount1, offset1);
463 OUString tmpStr2 = folding(str2, pos2, nCount2, offset2);
464 // Length of offset1 and offset2 may still be 0 if there was no folding
465 // necessary!
466
467 const sal_Unicode *p1 = tmpStr1.getStr();
468 const sal_Unicode *p2 = tmpStr2.getStr();
469 sal_Int32 i, nLen = ::std::min( tmpStr1.getLength(), tmpStr2.getLength());
470 for (i = 0; i < nLen; ++i, ++p1, ++p2 ) {
471 if (*p1 != *p2) {
472 // return number of matched code points so far
473 nMatch1 = (i < offset1.getLength()) ? offset1.getConstArray()[i] : i;
474 nMatch2 = (i < offset2.getLength()) ? offset2.getConstArray()[i] : i;
475 return false;
476 }
477 }
478 // i==nLen
479 if ( tmpStr1.getLength() != tmpStr2.getLength() ) {
480 // return number of matched code points so far
481 nMatch1 = (i <= offset1.getLength()) ? offset1.getConstArray()[i-1] + 1 : i;
482 nMatch2 = (i <= offset2.getLength()) ? offset2.getConstArray()[i-1] + 1 : i;
483 return false;
484 } else {
485 nMatch1 = nCount1;
486 nMatch2 = nCount2;
487 return true;
488 }
489}
490
493 const sal_Int32 length, sal_Int16 _numCascade)
494{
495 if (_numCascade >= numCascade || ! bodyCascade[_numCascade].is())
496 return inStrs;
497
498 sal_Int32 j_tmp = 0;
499 constexpr sal_Int32 nMaxOutput = 2;
500 const sal_Int32 nMaxOutputLength = nMaxOutput*length;
501 std::vector<OUString> ostr;
502 ostr.reserve(nMaxOutputLength);
503 for (sal_Int32 j = 0; j < length; j+=2) {
504 const Sequence< OUString >& temp = bodyCascade[_numCascade]->transliterateRange(inStrs[j], inStrs[j+1]);
505
506 for (const auto& rStr : temp) {
507 if ( j_tmp++ >= nMaxOutputLength ) throw RuntimeException();
508 ostr.push_back(rStr);
509 }
510 }
511
512 return getRange(comphelper::containerToSequence(ostr), j_tmp, ++_numCascade);
513}
514
515
517TransliterationImpl::transliterateRange( const OUString& str1, const OUString& str2 )
518{
519 if (numCascade == 1)
520 return bodyCascade[0]->transliterateRange(str1, str2);
521
522 Sequence< OUString > ostr{ str1, str2 };
523
524 return getRange(ostr, 2, 0);
525}
526
527
528sal_Int32 SAL_CALL
530 const OUString& str1, sal_Int32 off1, sal_Int32 len1,
531 const OUString& str2, sal_Int32 off2, sal_Int32 len2)
532{
533 if (caseignoreOnly && caseignore.is())
534 return caseignore->compareSubstring(str1, off1, len1, str2, off2, len2);
535
537
538 OUString in_str1 = transliterate(str1, off1, len1, offset);
539 OUString in_str2 = transliterate(str2, off2, len2, offset);
540 const sal_Unicode* unistr1 = in_str1.getStr();
541 const sal_Unicode* unistr2 = in_str2.getStr();
542 sal_Int32 strlen1 = in_str1.getLength();
543 sal_Int32 strlen2 = in_str2.getLength();
544
545 while (strlen1 && strlen2) {
546 if (*unistr1 != *unistr2)
547 return *unistr1 > *unistr2 ? 1 : -1;
548
549 unistr1++; unistr2++; strlen1--; strlen2--;
550 }
551 return strlen1 == strlen2 ? 0 : (strlen1 > strlen2 ? 1 : -1);
552}
553
554
555sal_Int32 SAL_CALL
556TransliterationImpl::compareString(const OUString& str1, const OUString& str2 )
557{
558 if (caseignoreOnly && caseignore.is())
559 return caseignore->compareString(str1, str2);
560 else
561 return compareSubstring(str1, 0, str1.getLength(), str2, 0, str2.getLength());
562}
563
564
565void
567{
568 for (sal_Int32 i = 0; i < numCascade; i++)
569 if (bodyCascade[i].is())
570 bodyCascade[i].clear();
571 numCascade = 0;
572 caseignore.clear();
573 caseignoreOnly = true;
574}
575
576namespace
577{
579 struct TransBody
580 {
581 OUString Name;
582 css::uno::Reference< css::i18n::XExtendedTransliteration > Body;
583 };
584}
585
587{
588 assert(!implName.isEmpty());
589 static std::mutex transBodyMutex;
590 std::unique_lock guard(transBodyMutex);
591 static TransBody lastTransBody;
592 if (implName != lastTransBody.Name)
593 {
594 lastTransBody.Body.set(
595 mxContext->getServiceManager()->createInstanceWithContext(implName, mxContext), UNO_QUERY_THROW);
596 lastTransBody.Name = implName;
597 }
598 body = lastTransBody.Body;
599}
600
601bool
603 Reference<XExtendedTransliteration>& body, const Locale& rLocale)
604{
605 OUString cname = OUString::Concat(TRLT_IMPLNAME_PREFIX) + implName;
606 loadBody(cname, body);
607 if (body.is()) {
608 body->loadModule(TransliterationModules(0), rLocale); // toUpper/toLoad need rLocale
609
610 // if the module is ignore case/kana/width, load caseignore for equals/compareString mothed
611 for (sal_Int16 i = 0; i < 3; i++) {
613 if (i == 0) // current module is caseignore
614 body->loadModule(TMlist[0].tm, rLocale); // caseignore need to setup module name
615 if (! caseignore.is()) {
616 OUString bname = TRLT_IMPLNAME_PREFIX +
617 OUString::createFromAscii(TMlist[0].implName);
618 loadBody(bname, caseignore);
619 }
620 if (caseignore.is())
621 caseignore->loadModule(TMlist[i].tm, rLocale);
622 return true;
623 }
624 }
625 caseignoreOnly = false; // has other module than just ignore case/kana/width
626 }
627 return body.is();
628}
629
630OUString SAL_CALL
632{
633 return "com.sun.star.i18n.Transliteration";
634}
635
636sal_Bool SAL_CALL
637TransliterationImpl::supportsService(const OUString& rServiceName)
638{
639 return cppu::supportsService(this, rServiceName);
640}
641
644{
645 return { "com.sun.star.i18n.Transliteration" };
646}
647
648}
649
650extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
652 css::uno::XComponentContext *context,
653 css::uno::Sequence<css::uno::Any> const &)
654{
655 return cppu::acquire(new i18npool::TransliterationImpl(context));
656}
657
658/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OptionalString sType
UBlockCode from
UBlockCode to
css::uno::Reference< css::i18n::XExtendedTransliteration > caseignore
virtual OUString SAL_CALL folding(const OUString &inStr, sal_Int32 startPos, sal_Int32 nCount, css::uno::Sequence< sal_Int32 > &offset) override
virtual void SAL_CALL loadModuleNew(const css::uno::Sequence< css::i18n::TransliterationModulesNew > &modName, const css::lang::Locale &rLocale) override
virtual void SAL_CALL loadModulesByImplNames(const css::uno::Sequence< OUString > &modNamelist, const css::lang::Locale &rLocale) override
virtual sal_Int32 SAL_CALL compareString(const OUString &s1, const OUString &s2) override
virtual OUString SAL_CALL transliterateString2String(const OUString &inStr, sal_Int32 startPos, sal_Int32 nCount) override
virtual css::uno::Sequence< OUString > SAL_CALL transliterateRange(const OUString &str1, const OUString &str2) override
virtual OUString SAL_CALL transliterateChar2String(sal_Unicode inChar) override
virtual sal_Int32 SAL_CALL compareSubstring(const OUString &s1, sal_Int32 off1, sal_Int32 len1, const OUString &s2, sal_Int32 off2, sal_Int32 len2) override
virtual sal_Unicode SAL_CALL transliterateChar2Char(sal_Unicode inChar) override
virtual OUString SAL_CALL getName() override
css::uno::Sequence< OUString > getRange(const css::uno::Sequence< OUString > &inStrs, sal_Int32 length, const sal_Int16 _nCascade)
virtual OUString SAL_CALL transliterate(const OUString &inStr, sal_Int32 startPos, sal_Int32 nCount, css::uno::Sequence< sal_Int32 > &offset) override
virtual void SAL_CALL loadModule(css::i18n::TransliterationModules modName, const css::lang::Locale &rLocale) override
virtual void SAL_CALL loadModuleByImplName(const OUString &implName, const css::lang::Locale &rLocale) override
virtual sal_Bool SAL_CALL equals(const OUString &str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32 &nMatch1, const OUString &str2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32 &nMatch2) override
virtual sal_Int16 SAL_CALL getType() override
TransliterationImpl(const css::uno::Reference< css::uno::XComponentContext > &xContext)
virtual css::uno::Sequence< OUString > SAL_CALL getAvailableModules(const css::lang::Locale &rLocale, sal_Int16 sType) override
void loadBody(OUString const &implName, css::uno::Reference< css::i18n::XExtendedTransliteration > &body)
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual OUString SAL_CALL getImplementationName() override
css::uno::Reference< css::uno::XComponentContext > mxContext
bool loadModuleByName(std::u16string_view implName, css::uno::Reference< css::i18n::XExtendedTransliteration > &body, const css::lang::Locale &rLocale)
css::uno::Reference< css::i18n::XLocaleData5 > mxLocaledata
css::uno::Reference< css::i18n::XExtendedTransliteration > bodyCascade[maxCascade]
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
int nCount
uno::Reference< uno::XComponentContext > mxContext
float u
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
int i
Constant values shared between i18npool and, for example, the number formatter.
static TransliterationModules operator&(TransliterationModules lhs, TransliterationModules rhs)
static TransliterationModules operator|(TransliterationModules lhs, TransliterationModules rhs)
TMList const TMlist[]
bool equalsAscii(std::u16string_view s1, const char *s2)
enumrange< T >::Iterator begin(enumrange< T >)
end
#define TRLT_IMPLNAME_PREFIX
Definition: servicename.hxx:61
TransliterationModulesNew tmn
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_i18n_Transliteration_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
TransliterationModules tm
#define TmItem1(name)
const char * implName
OUString Name
#define TmItem2(name)
#define TransliterationModules_IGNORE_CASE_MASK
#define maxCascade
Body
unsigned char sal_Bool
sal_uInt16 sal_Unicode