bump product version to 4.2.0.1
[LibreOffice.git] / i18npool / source / transliteration / transliterationImpl.cxx
blobd700646dcfe2ee5814fd2ffa66bd5191261702ca
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "transliterationImpl.hxx"
22 #include "servicename.hxx"
24 #include <com/sun/star/i18n/LocaleData.hpp>
25 #include <com/sun/star/i18n/TransliterationType.hpp>
26 #include <com/sun/star/i18n/TransliterationModulesExtra.hpp>
27 #include <com/sun/star/lang/XComponent.hpp>
29 #include <comphelper/processfactory.hxx>
30 #include <rtl/instance.hxx>
31 #include <rtl/string.h>
32 #include <rtl/ustring.hxx>
33 #include <rtl/ustrbuf.hxx>
35 #include <algorithm>
37 #if OSL_DEBUG_LEVEL > 1
38 #include <stdio.h>
39 #endif
41 using namespace com::sun::star::uno;
42 using namespace com::sun::star::lang;
45 namespace com { namespace sun { namespace star { namespace i18n {
47 #define ERROR RuntimeException()
49 #define TmItem1( name ) \
50 {TransliterationModules_##name, TransliterationModulesNew_##name, #name}
52 #define TmItem2( name ) \
53 {(TransliterationModules)0, TransliterationModulesNew_##name, #name}
55 // Ignore Module list
56 static struct TMlist {
57 TransliterationModules tm;
58 TransliterationModulesNew tmn;
59 const sal_Char *implName;
60 } TMlist[] = { // Modules ModulesNew
61 TmItem1 (IGNORE_CASE), // 0. (1<<8 256) (7)
62 TmItem1 (IGNORE_WIDTH), // 1. (1<<9 512) (8)
63 TmItem1 (IGNORE_KANA), // 2. (1<<10 1024) (9)
64 // No enum define for this trans. application has to use impl name to load it
65 // TmItem1 (IGNORE_CASE_SIMPLE), // (1<<11 1024) (66)
67 TmItem1 (ignoreTraditionalKanji_ja_JP), // 3. (1<<12 4096) (10)
68 TmItem1 (ignoreTraditionalKana_ja_JP), // 4. (1<<13 8192) (11)
69 TmItem1 (ignoreMinusSign_ja_JP), // 5. (1<<13 16384) (12)
70 TmItem1 (ignoreIterationMark_ja_JP), // 6. (1<<14 32768) (13)
71 TmItem1 (ignoreSeparator_ja_JP), // 7. (1<<15 65536) (14)
72 TmItem1 (ignoreSize_ja_JP), // 15. (1<<23 16777216) (22)
73 TmItem1 (ignoreMiddleDot_ja_JP), // 17. (1<<25 67108864) (24)
74 TmItem1 (ignoreSpace_ja_JP), // 18. (1<<26 134217728) (25)
75 TmItem1 (ignoreZiZu_ja_JP), // 8. (1<<16 131072) (15)
76 TmItem1 (ignoreBaFa_ja_JP), // 9. (1<<17 262144) (16)
77 TmItem1 (ignoreTiJi_ja_JP), // 10. (1<<18 524288) (17)
78 TmItem1 (ignoreHyuByu_ja_JP), // 11. (1<<19 1048576) (18)
79 TmItem1 (ignoreSeZe_ja_JP), // 12. (1<<20 2097152) (19)
80 TmItem1 (ignoreIandEfollowedByYa_ja_JP), // 13. (1<<21 4194304) (20)
81 TmItem1 (ignoreKiKuFollowedBySa_ja_JP), // 14. (1<<22 8388608) (21)
82 TmItem1 (ignoreProlongedSoundMark_ja_JP), // 16. (1<<24 33554432) (23)
84 TmItem1 (UPPERCASE_LOWERCASE), // 19. (1) (1)
85 TmItem1 (LOWERCASE_UPPERCASE), // 20. (2) (2)
86 TmItem1 (HALFWIDTH_FULLWIDTH), // 21. (3) (3)
87 TmItem1 (FULLWIDTH_HALFWIDTH), // 22. (4) (4)
88 TmItem1 (KATAKANA_HIRAGANA), // 23. (5) (5)
89 TmItem1 (HIRAGANA_KATAKANA), // 24. (6) (6)
91 TmItem1 (smallToLarge_ja_JP), // 25. (1<<27 268435456) (26)
92 TmItem1 (largeToSmall_ja_JP), // 26. (1<<28 536870912) (27)
93 TmItem2 (NumToTextLower_zh_CN), // 27. () (28)
94 TmItem2 (NumToTextUpper_zh_CN), // 28. () (29)
95 TmItem2 (NumToTextLower_zh_TW), // 29. () (30)
96 TmItem2 (NumToTextUpper_zh_TW), // 30. () (31)
97 TmItem2 (NumToTextFormalHangul_ko), // 31. () (32)
98 TmItem2 (NumToTextFormalLower_ko), // 32. () (33)
99 TmItem2 (NumToTextFormalUpper_ko), // 33. () (34)
100 TmItem2 (NumToTextInformalHangul_ko), // 34. () (35)
101 TmItem2 (NumToTextInformalLower_ko), // 35. () (36)
102 TmItem2 (NumToTextInformalUpper_ko), // 36. () (37)
103 TmItem2 (NumToCharLower_zh_CN), // 37. () (38)
104 TmItem2 (NumToCharUpper_zh_CN), // 38. () (39)
105 TmItem2 (NumToCharLower_zh_TW), // 39. () (40)
106 TmItem2 (NumToCharUpper_zh_TW), // 40. () (41)
107 TmItem2 (NumToCharHangul_ko), // 41. () (42)
108 TmItem2 (NumToCharLower_ko), // 42. () (43)
109 TmItem2 (NumToCharUpper_ko), // 43. () (44)
110 TmItem2 (NumToCharFullwidth), // 44. () (45)
111 TmItem2 (NumToCharKanjiShort_ja_JP), // 45. () (46)
112 TmItem2 (TextToNumLower_zh_CN), // 46. () (47)
113 TmItem2 (TextToNumUpper_zh_CN), // 47. () (48)
114 TmItem2 (TextToNumLower_zh_TW), // 48. () (49)
115 TmItem2 (TextToNumUpper_zh_TW), // 49. () (50)
116 TmItem2 (TextToNumFormalHangul_ko), // 50. () (51)
117 TmItem2 (TextToNumFormalLower_ko), // 51. () (52)
118 TmItem2 (TextToNumFormalUpper_ko), // 52. () (53)
119 TmItem2 (TextToNumInformalHangul_ko), // 53. () (54)
120 TmItem2 (TextToNumInformalLower_ko), // 54. () (55)
121 TmItem2 (TextToNumInformalUpper_ko), // 55. () (56)
123 TmItem2 (CharToNumLower_zh_CN), // 56. () (59)
124 TmItem2 (CharToNumUpper_zh_CN), // 57. () (60)
125 TmItem2 (CharToNumLower_zh_TW), // 58. () (61)
126 TmItem2 (CharToNumUpper_zh_TW), // 59. () (62)
127 TmItem2 (CharToNumHangul_ko), // 60. () (63)
128 TmItem2 (CharToNumLower_ko), // 61. () (64)
129 TmItem2 (CharToNumUpper_ko), // 62. () (65)
131 // no enum defined for these trans. application has to use impl name to load them
132 // TmItem2 (NumToCharArabic_Indic), // () (67)
133 // TmItem2 (NumToCharEstern_Arabic_Indic),// () (68)
134 // TmItem2 (NumToCharIndic), // () (69)
135 // TmItem2 (NumToCharThai), // () (70)
136 {(TransliterationModules)0, (TransliterationModulesNew)0, NULL}
139 // Constructor/Destructor
140 TransliterationImpl::TransliterationImpl(const Reference <XComponentContext>& xContext) : mxContext(xContext)
142 numCascade = 0;
143 caseignoreOnly = sal_True;
145 mxLocaledata.set(LocaleData::create(xContext));
148 TransliterationImpl::~TransliterationImpl()
150 mxLocaledata.clear();
151 clear();
155 // Methods
156 OUString SAL_CALL
157 TransliterationImpl::getName() throw(RuntimeException)
159 if (numCascade == 1 && bodyCascade[0].is())
160 return bodyCascade[0]->getName();
161 if (numCascade < 1)
162 return ( OUString("Not Loaded"));
163 throw ERROR;
166 sal_Int16 SAL_CALL
167 TransliterationImpl::getType() throw(RuntimeException)
169 if (numCascade > 1)
170 return (TransliterationType::CASCADE|TransliterationType::IGNORE);
171 if (numCascade > 0 && bodyCascade[0].is())
172 return(bodyCascade[0]->getType());
173 throw ERROR;
176 void SAL_CALL
177 TransliterationImpl::loadModule( TransliterationModules modType, const Locale& rLocale )
178 throw(RuntimeException)
180 clear();
181 if (modType&TransliterationModules_IGNORE_MASK && modType&TransliterationModules_NON_IGNORE_MASK) {
182 throw ERROR;
183 } else if (modType&TransliterationModules_IGNORE_MASK) {
184 #define TransliterationModules_IGNORE_CASE_MASK (TransliterationModules_IGNORE_CASE | \
185 TransliterationModules_IGNORE_WIDTH | \
186 TransliterationModules_IGNORE_KANA)
187 sal_Int32 mask = ((modType&TransliterationModules_IGNORE_CASE_MASK) == modType) ?
188 TransliterationModules_IGNORE_CASE_MASK : TransliterationModules_IGNORE_MASK;
189 for (sal_Int16 i = 0; TMlist[i].tm & mask; i++) {
190 if (modType & TMlist[i].tm)
191 if (loadModuleByName(OUString::createFromAscii(TMlist[i].implName),
192 bodyCascade[numCascade], rLocale))
193 numCascade++;
195 // additional transliterations from TranslationModuleExtra (we cannot extend TransliterationModule)
196 if (modType & TransliterationModulesExtra::ignoreDiacritics_CTL)
198 if (loadModuleByName(OUString("ignoreDiacritics_CTL"), bodyCascade[numCascade], rLocale))
199 numCascade++;
201 } else if (modType&TransliterationModules_NON_IGNORE_MASK) {
202 for (sal_Int16 i = 0; TMlist[i].tm; i++) {
203 if (TMlist[i].tm == modType) {
204 if (loadModuleByName(OUString::createFromAscii(TMlist[i].implName), bodyCascade[numCascade], rLocale))
205 numCascade++;
206 break;
212 void SAL_CALL
213 TransliterationImpl::loadModuleNew( const Sequence < TransliterationModulesNew > & modType, const Locale& rLocale )
214 throw(RuntimeException)
216 clear();
217 sal_Int32 mask = 0, count = modType.getLength();
218 if (count > maxCascade)
219 throw ERROR; // could not handle more than maxCascade
220 for (sal_Int16 i = 0; i < count; i++) {
221 for (sal_Int16 j = 0; TMlist[j].tmn; j++) {
222 if (TMlist[j].tmn == modType[i]) {
223 if (mask == 0)
224 mask = TMlist[i].tm && (TMlist[i].tm&TransliterationModules_IGNORE_MASK) ?
225 TransliterationModules_IGNORE_MASK : TransliterationModules_NON_IGNORE_MASK;
226 else if (mask == (sal_Int32) TransliterationModules_IGNORE_MASK &&
227 (TMlist[i].tm&TransliterationModules_IGNORE_MASK) == 0)
228 throw ERROR; // could not mess up ignore trans. with non_ignore trans.
229 if (loadModuleByName(OUString::createFromAscii(TMlist[j].implName), bodyCascade[numCascade], rLocale))
230 numCascade++;
231 break;
237 void SAL_CALL
238 TransliterationImpl::loadModuleByImplName(const OUString& implName, const Locale& rLocale)
239 throw(RuntimeException)
241 clear();
242 if (loadModuleByName(implName, bodyCascade[numCascade], rLocale))
243 numCascade++;
247 void SAL_CALL
248 TransliterationImpl::loadModulesByImplNames(const Sequence< OUString >& implNameList, const Locale& rLocale ) throw(RuntimeException)
250 if (implNameList.getLength() > maxCascade || implNameList.getLength() <= 0)
251 throw ERROR;
253 clear();
254 for (sal_Int32 i = 0; i < implNameList.getLength(); i++)
255 if (loadModuleByName(implNameList[i], bodyCascade[numCascade], rLocale))
256 numCascade++;
260 Sequence<OUString> SAL_CALL
261 TransliterationImpl::getAvailableModules( const Locale& rLocale, sal_Int16 sType ) throw(RuntimeException)
263 const Sequence<OUString> &translist = mxLocaledata->getTransliterations(rLocale);
264 Sequence<OUString> r(translist.getLength());
265 Reference<XExtendedTransliteration> body;
266 sal_Int32 n = 0;
267 for (sal_Int32 i = 0; i < translist.getLength(); i++)
269 if (loadModuleByName(translist[i], body, rLocale)) {
270 if (body->getType() & sType)
271 r[n++] = translist[i];
272 body.clear();
275 r.realloc(n);
276 return (r);
280 OUString SAL_CALL
281 TransliterationImpl::transliterate( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount,
282 Sequence< sal_Int32 >& offset ) throw(RuntimeException)
284 if (numCascade == 0)
285 return inStr;
287 if (offset.getLength() != nCount)
288 offset.realloc(nCount);
289 if (numCascade == 1)
291 if ( startPos == 0 && nCount == inStr.getLength() )
292 return bodyCascade[0]->transliterate( inStr, 0, nCount, offset);
293 else
295 OUString tmpStr = inStr.copy(startPos, nCount);
296 tmpStr = bodyCascade[0]->transliterate(tmpStr, 0, nCount, offset);
297 if ( startPos )
299 sal_Int32 * pArr = offset.getArray();
300 nCount = offset.getLength();
301 for (sal_Int32 j = 0; j < nCount; j++)
302 pArr[j] += startPos;
304 return tmpStr;
307 else
309 OUString tmpStr = inStr.copy(startPos, nCount);
310 sal_Int32 * pArr = offset.getArray();
311 for (sal_Int32 j = 0; j < nCount; j++)
312 pArr[j] = startPos + j;
314 sal_Int16 from = 0, to = 1, tmp;
315 Sequence<sal_Int32> off[2];
317 off[to] = offset;
318 off[from].realloc(nCount);
319 for (sal_Int32 i = 0; i < numCascade; i++) {
320 tmpStr = bodyCascade[i]->transliterate(tmpStr, 0, nCount, off[from]);
322 nCount = tmpStr.getLength();
324 tmp = from; from = to; to = tmp;
325 for (sal_Int32 j = 0; j < nCount; j++)
326 off[to][j] = off[from][off[to][j]];
328 offset = off[to];
329 return tmpStr;
335 OUString SAL_CALL
336 TransliterationImpl::folding( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount,
337 Sequence< sal_Int32 >& offset ) throw(RuntimeException)
339 if (numCascade == 0)
340 return inStr;
342 if (offset.getLength() != nCount)
343 offset.realloc(nCount);
344 if (numCascade == 1)
346 if ( startPos == 0 && nCount == inStr.getLength() )
347 return bodyCascade[0]->folding( inStr, 0, nCount, offset);
348 else
350 OUString tmpStr = inStr.copy(startPos, nCount);
351 tmpStr = bodyCascade[0]->folding(tmpStr, 0, nCount, offset);
352 if ( startPos )
354 sal_Int32 * pArr = offset.getArray();
355 nCount = offset.getLength();
356 for (sal_Int32 j = 0; j < nCount; j++)
357 pArr[j] += startPos;
359 return tmpStr;
362 else
364 OUString tmpStr = inStr.copy(startPos, nCount);
365 sal_Int32 * pArr = offset.getArray();
366 for (sal_Int32 j = 0; j < nCount; j++)
367 pArr[j] = startPos + j;
369 sal_Int16 from = 0, to = 1, tmp;
370 Sequence<sal_Int32> off[2];
372 off[to] = offset;
373 for (sal_Int32 i = 0; i < numCascade; i++) {
374 tmpStr = bodyCascade[i]->folding(tmpStr, 0, nCount, off[from]);
376 nCount = tmpStr.getLength();
378 tmp = from; from = to; to = tmp;
379 for (sal_Int32 j = 0; j < nCount; j++)
380 off[to][j] = off[from][off[to][j]];
382 offset = off[to];
383 return tmpStr;
387 OUString SAL_CALL
388 TransliterationImpl::transliterateString2String( const OUString& inStr, sal_Int32 startPos, sal_Int32 nCount ) throw(RuntimeException)
390 if (numCascade == 0)
391 return inStr;
392 else if (numCascade == 1)
393 return bodyCascade[0]->transliterateString2String( inStr, startPos, nCount);
394 else {
395 OUString tmpStr = bodyCascade[0]->transliterateString2String(inStr, startPos, nCount);
397 for (sal_Int32 i = 1; i < numCascade; i++)
398 tmpStr = bodyCascade[i]->transliterateString2String(tmpStr, 0, tmpStr.getLength());
399 return tmpStr;
403 OUString SAL_CALL
404 TransliterationImpl::transliterateChar2String( sal_Unicode inChar ) throw(RuntimeException)
406 if (numCascade == 0)
407 return OUString(&inChar, 1);
408 else if (numCascade == 1)
409 return bodyCascade[0]->transliterateChar2String( inChar);
410 else {
411 OUString tmpStr = bodyCascade[0]->transliterateChar2String(inChar);
413 for (sal_Int32 i = 1; i < numCascade; i++)
414 tmpStr = bodyCascade[i]->transliterateString2String(tmpStr, 0, tmpStr.getLength());
415 return tmpStr;
419 sal_Unicode SAL_CALL
420 TransliterationImpl::transliterateChar2Char( sal_Unicode inChar ) throw(MultipleCharsOutputException, RuntimeException)
422 sal_Unicode tmpChar = inChar;
423 for (sal_Int32 i = 0; i < numCascade; i++)
424 tmpChar = bodyCascade[i]->transliterateChar2Char(tmpChar);
425 return tmpChar;
429 sal_Bool SAL_CALL
430 TransliterationImpl::equals(
431 const OUString& str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32& nMatch1,
432 const OUString& str2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32& nMatch2)
433 throw(RuntimeException)
435 // since this is an API function make it user fail safe
436 if ( nCount1 < 0 ) {
437 pos1 += nCount1;
438 nCount1 = -nCount1;
440 if ( nCount2 < 0 ) {
441 pos2 += nCount2;
442 nCount2 = -nCount2;
444 if ( !nCount1 || !nCount2 ||
445 pos1 >= str1.getLength() || pos2 >= str2.getLength() ||
446 pos1 < 0 || pos2 < 0 ) {
447 nMatch1 = nMatch2 = 0;
448 // two empty strings return true, else false
449 return !nCount1 && !nCount2 && pos1 == str1.getLength() && pos2 == str2.getLength();
451 if ( pos1 + nCount1 > str1.getLength() )
452 nCount1 = str1.getLength() - pos1;
453 if ( pos2 + nCount2 > str2.getLength() )
454 nCount2 = str2.getLength() - pos2;
456 if (caseignoreOnly && caseignore.is())
457 return caseignore->equals(str1, pos1, nCount1, nMatch1, str2, pos2, nCount2, nMatch2);
459 Sequence<sal_Int32> offset1, offset2;
461 OUString tmpStr1 = folding(str1, pos1, nCount1, offset1);
462 OUString tmpStr2 = folding(str2, pos2, nCount2, offset2);
463 // Length of offset1 and offset2 may still be 0 if there was no folding
464 // necessary!
466 const sal_Unicode *p1 = tmpStr1.getStr();
467 const sal_Unicode *p2 = tmpStr2.getStr();
468 sal_Int32 i, nLen = ::std::min( tmpStr1.getLength(), tmpStr2.getLength());
469 for (i = 0; i < nLen; ++i, ++p1, ++p2 ) {
470 if (*p1 != *p2) {
471 // return number of matched code points so far
472 nMatch1 = (i < offset1.getLength()) ? offset1[i] : i;
473 nMatch2 = (i < offset2.getLength()) ? offset2[i] : i;
474 return sal_False;
477 // i==nLen
478 if ( tmpStr1.getLength() != tmpStr2.getLength() ) {
479 // return number of matched code points so far
480 nMatch1 = (i <= offset1.getLength()) ? offset1[i-1] + 1 : i;
481 nMatch2 = (i <= offset2.getLength()) ? offset2[i-1] + 1 : i;
482 return sal_False;
483 } else {
484 nMatch1 = nCount1;
485 nMatch2 = nCount2;
486 return sal_True;
490 #define MaxOutput 2
492 Sequence< OUString > SAL_CALL
493 TransliterationImpl::getRange(const Sequence< OUString > &inStrs,
494 const sal_Int32 length, sal_Int16 _numCascade) throw(RuntimeException)
496 if (_numCascade >= numCascade || ! bodyCascade[_numCascade].is())
497 return inStrs;
499 sal_Int32 j_tmp = 0;
500 Sequence< OUString > ostr(MaxOutput*length);
501 for (sal_Int32 j = 0; j < length; j+=2) {
502 const Sequence< OUString >& temp = bodyCascade[_numCascade]->transliterateRange(inStrs[j], inStrs[j+1]);
504 for ( sal_Int32 k = 0; k < temp.getLength(); k++) {
505 if ( j_tmp >= MaxOutput*length ) throw ERROR;
506 ostr[j_tmp++] = temp[k];
509 ostr.realloc(j_tmp);
511 return this->getRange(ostr, j_tmp, ++_numCascade);
515 Sequence< OUString > SAL_CALL
516 TransliterationImpl::transliterateRange( const OUString& str1, const OUString& str2 )
517 throw(RuntimeException)
519 if (numCascade == 1)
520 return bodyCascade[0]->transliterateRange(str1, str2);
522 Sequence< OUString > ostr(2);
523 ostr[0] = str1;
524 ostr[1] = str2;
526 return this->getRange(ostr, 2, 0);
530 sal_Int32 SAL_CALL
531 TransliterationImpl::compareSubstring(
532 const OUString& str1, sal_Int32 off1, sal_Int32 len1,
533 const OUString& str2, sal_Int32 off2, sal_Int32 len2)
534 throw(RuntimeException)
536 if (caseignoreOnly && caseignore.is())
537 return caseignore->compareSubstring(str1, off1, len1, str2, off2, len2);
539 Sequence <sal_Int32> offset;
541 OUString in_str1 = this->transliterate(str1, off1, len1, offset);
542 OUString in_str2 = this->transliterate(str2, off2, len2, offset);
543 const sal_Unicode* unistr1 = in_str1.getStr();
544 const sal_Unicode* unistr2 = in_str2.getStr();
545 sal_Int32 strlen1 = in_str1.getLength();
546 sal_Int32 strlen2 = in_str2.getLength();
548 while (strlen1 && strlen2) {
549 if (*unistr1 != *unistr2)
550 return *unistr1 > *unistr2 ? 1 : -1;
552 unistr1++; unistr2++; strlen1--; strlen2--;
554 return strlen1 == strlen2 ? 0 : (strlen1 > strlen2 ? 1 : -1);
558 sal_Int32 SAL_CALL
559 TransliterationImpl::compareString(const OUString& str1, const OUString& str2 ) throw (RuntimeException)
561 if (caseignoreOnly && caseignore.is())
562 return caseignore->compareString(str1, str2);
563 else
564 return this->compareSubstring(str1, 0, str1.getLength(), str2, 0, str2.getLength());
568 void
569 TransliterationImpl::clear()
571 for (sal_Int32 i = 0; i < numCascade; i++)
572 if (bodyCascade[i].is())
573 bodyCascade[i].clear();
574 numCascade = 0;
575 caseignore.clear();
576 caseignoreOnly = sal_True;
579 namespace
581 /** structure to cache the last transliteration body used. */
582 struct TransBody
584 OUString Name;
585 ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XExtendedTransliteration > Body;
587 class theTransBodyMutex : public rtl::Static<osl::Mutex, theTransBodyMutex> {};
590 void TransliterationImpl::loadBody( OUString &implName, Reference<XExtendedTransliteration>& body )
591 throw (RuntimeException)
593 assert(!implName.isEmpty());
594 ::osl::MutexGuard guard(theTransBodyMutex::get());
595 static TransBody lastTransBody;
596 if (implName != lastTransBody.Name)
598 lastTransBody.Body.set(
599 mxContext->getServiceManager()->createInstanceWithContext(implName, mxContext), UNO_QUERY_THROW);
600 lastTransBody.Name = implName;
602 body = lastTransBody.Body;
605 sal_Bool SAL_CALL
606 TransliterationImpl::loadModuleByName( const OUString& implName,
607 Reference<XExtendedTransliteration>& body, const Locale& rLocale) throw(RuntimeException)
609 OUString cname = OUString(TRLT_IMPLNAME_PREFIX) + implName;
610 loadBody(cname, body);
611 if (body.is()) {
612 body->loadModule((TransliterationModules)0, rLocale); // toUpper/toLoad need rLocale
614 // if the module is ignore case/kana/width, load caseignore for equals/compareString mothed
615 for (sal_Int16 i = 0; i < 3; i++) {
616 if (implName.equalsAscii(TMlist[i].implName)) {
617 if (i == 0) // current module is caseignore
618 body->loadModule(TMlist[0].tm, rLocale); // caseingore need to setup module name
619 if (! caseignore.is()) {
620 OUString bname = OUString(TRLT_IMPLNAME_PREFIX) +
621 OUString::createFromAscii(TMlist[0].implName);
622 loadBody(bname, caseignore);
624 if (caseignore.is())
625 caseignore->loadModule(TMlist[i].tm, rLocale);
626 return sal_True;
629 caseignoreOnly = sal_False; // has other module than just ignore case/kana/width
631 return body.is();
634 const sal_Char cTrans[] = "com.sun.star.i18n.Transliteration";
636 OUString SAL_CALL
637 TransliterationImpl::getImplementationName() throw( RuntimeException )
639 return OUString::createFromAscii(cTrans);
643 sal_Bool SAL_CALL
644 TransliterationImpl::supportsService(const OUString& rServiceName) throw( RuntimeException )
646 return rServiceName.equalsAscii(cTrans);
649 Sequence< OUString > SAL_CALL
650 TransliterationImpl::getSupportedServiceNames(void) throw( RuntimeException )
652 Sequence< OUString > aRet(1);
653 aRet[0] = OUString::createFromAscii(cTrans);
654 return aRet;
657 } } } }
659 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */