1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
19 #include <config_locales.h>
21 #include <breakiteratorImpl.hxx>
22 #include <cppuhelper/supportsservice.hxx>
23 #include <unicode/uchar.h>
24 #include <i18nutil/unicode.hxx>
25 #include <rtl/ustrbuf.hxx>
27 using namespace ::com::sun::star
;
28 using namespace ::com::sun::star::uno
;
29 using namespace ::com::sun::star::i18n
;
30 using namespace ::com::sun::star::lang
;
34 BreakIteratorImpl::BreakIteratorImpl( const Reference
< XComponentContext
>& rxContext
) : m_xContext( rxContext
)
38 BreakIteratorImpl::BreakIteratorImpl()
42 BreakIteratorImpl::~BreakIteratorImpl()
46 #define LBI getLocaleSpecificBreakIterator(rLocale)
48 sal_Int32 SAL_CALL
BreakIteratorImpl::nextCharacters( const OUString
& Text
, sal_Int32 nStartPos
,
49 const Locale
&rLocale
, sal_Int16 nCharacterIteratorMode
, sal_Int32 nCount
, sal_Int32
& nDone
)
51 if (nCount
< 0) throw RuntimeException();
53 return LBI
->nextCharacters( Text
, nStartPos
, rLocale
, nCharacterIteratorMode
, nCount
, nDone
);
56 sal_Int32 SAL_CALL
BreakIteratorImpl::previousCharacters( const OUString
& Text
, sal_Int32 nStartPos
,
57 const Locale
& rLocale
, sal_Int16 nCharacterIteratorMode
, sal_Int32 nCount
, sal_Int32
& nDone
)
59 if (nCount
< 0) throw RuntimeException();
61 return LBI
->previousCharacters( Text
, nStartPos
, rLocale
, nCharacterIteratorMode
, nCount
, nDone
);
64 #define isZWSP(c) (ch == 0x200B)
66 static sal_Int32
skipSpace(const OUString
& Text
, sal_Int32 nPos
, sal_Int32 len
, sal_Int16 rWordType
, bool bDirection
)
71 case WordType::ANYWORD_IGNOREWHITESPACES
:
73 while (nPos
< len
&& (u_isWhitespace(ch
= Text
.iterateCodePoints(&pos
)) || isZWSP(ch
))) nPos
=pos
;
75 while (nPos
> 0 && (u_isWhitespace(ch
= Text
.iterateCodePoints(&pos
, -1)) || isZWSP(ch
))) nPos
=pos
;
77 case WordType::DICTIONARY_WORD
:
79 while (nPos
< len
&& (u_isWhitespace(ch
= Text
.iterateCodePoints(&pos
)) || isZWSP(ch
) ||
80 ! (ch
== 0x002E || u_isalnum(ch
)))) nPos
=pos
;
82 while (nPos
> 0 && (u_isWhitespace(ch
= Text
.iterateCodePoints(&pos
, -1)) || isZWSP(ch
) ||
83 ! (ch
== 0x002E || u_isalnum(ch
)))) nPos
=pos
;
85 case WordType::WORD_COUNT
:
87 while (nPos
< len
&& (u_isUWhiteSpace(ch
= Text
.iterateCodePoints(&pos
)) || isZWSP(ch
))) nPos
=pos
;
89 while (nPos
> 0 && (u_isUWhiteSpace(ch
= Text
.iterateCodePoints(&pos
, -1)) || isZWSP(ch
))) nPos
=pos
;
95 Boundary SAL_CALL
BreakIteratorImpl::nextWord( const OUString
& Text
, sal_Int32 nStartPos
,
96 const Locale
& rLocale
, sal_Int16 rWordType
)
98 sal_Int32 len
= Text
.getLength();
99 if( nStartPos
< 0 || len
== 0 )
100 result
.endPos
= result
.startPos
= 0;
101 else if (nStartPos
>= len
)
102 result
.endPos
= result
.startPos
= len
;
104 result
= LBI
->nextWord(Text
, nStartPos
, rLocale
, rWordType
);
106 nStartPos
= skipSpace(Text
, result
.startPos
, len
, rWordType
, true);
108 if ( nStartPos
!= result
.startPos
) {
109 if( nStartPos
>= len
)
110 result
.startPos
= result
.endPos
= len
;
112 result
= LBI
->getWordBoundary(Text
, nStartPos
, rLocale
, rWordType
, true);
113 // i88041: avoid startPos goes back to nStartPos when switching between Latin and CJK scripts
114 if (result
.startPos
< nStartPos
) result
.startPos
= nStartPos
;
121 static inline bool isCJK( const Locale
& rLocale
) {
122 return rLocale
.Language
== "zh" || rLocale
.Language
== "ja" || rLocale
.Language
== "ko";
125 Boundary SAL_CALL
BreakIteratorImpl::previousWord( const OUString
& Text
, sal_Int32 nStartPos
,
126 const Locale
& rLocale
, sal_Int16 rWordType
)
128 sal_Int32 len
= Text
.getLength();
129 if( nStartPos
<= 0 || len
== 0 ) {
130 result
.endPos
= result
.startPos
= 0;
132 } else if (nStartPos
> len
) {
133 result
.endPos
= result
.startPos
= len
;
137 sal_Int32 nPos
= skipSpace(Text
, nStartPos
, len
, rWordType
, false);
139 // if some spaces are skipped, and the script type is Asian with no CJK rLocale, we have to return
140 // (nStartPos, -1) for caller to send correct rLocale for loading correct dictionary.
141 result
.startPos
= nPos
;
142 if (nPos
!= nStartPos
&& nPos
> 0 && !isCJK(rLocale
) && getScriptClass(Text
.iterateCodePoints(&nPos
, -1)) == ScriptType::ASIAN
) {
147 return LBI
->previousWord(Text
, result
.startPos
, rLocale
, rWordType
);
151 Boundary SAL_CALL
BreakIteratorImpl::getWordBoundary( const OUString
& Text
, sal_Int32 nPos
, const Locale
& rLocale
,
152 sal_Int16 rWordType
, sal_Bool bDirection
)
154 sal_Int32 len
= Text
.getLength();
155 if( nPos
< 0 || len
== 0 )
156 result
.endPos
= result
.startPos
= 0;
158 result
.endPos
= result
.startPos
= len
;
160 sal_Int32 next
, prev
;
161 next
= skipSpace(Text
, nPos
, len
, rWordType
, true);
162 prev
= skipSpace(Text
, nPos
, len
, rWordType
, false);
163 if (prev
== 0 && next
== len
) {
164 result
.endPos
= result
.startPos
= nPos
;
165 } else if (prev
== 0 && ! bDirection
) {
166 result
.endPos
= result
.startPos
= 0;
167 } else if (next
== len
&& bDirection
) {
168 result
.endPos
= result
.startPos
= len
;
171 if (next
== nPos
&& next
!= len
)
173 else if (prev
== nPos
&& prev
!= 0)
176 nPos
= bDirection
? next
: prev
;
178 result
= LBI
->getWordBoundary(Text
, nPos
, rLocale
, rWordType
, bDirection
);
184 sal_Bool SAL_CALL
BreakIteratorImpl::isBeginWord( const OUString
& Text
, sal_Int32 nPos
,
185 const Locale
& rLocale
, sal_Int16 rWordType
)
187 sal_Int32 len
= Text
.getLength();
189 if (nPos
< 0 || nPos
>= len
) return false;
191 sal_Int32 tmp
= skipSpace(Text
, nPos
, len
, rWordType
, true);
193 if (tmp
!= nPos
) return false;
195 result
= getWordBoundary(Text
, nPos
, rLocale
, rWordType
, true);
197 return result
.startPos
== nPos
;
200 sal_Bool SAL_CALL
BreakIteratorImpl::isEndWord( const OUString
& Text
, sal_Int32 nPos
,
201 const Locale
& rLocale
, sal_Int16 rWordType
)
203 sal_Int32 len
= Text
.getLength();
205 if (nPos
<= 0 || nPos
> len
) return false;
207 sal_Int32 tmp
= skipSpace(Text
, nPos
, len
, rWordType
, false);
209 if (tmp
!= nPos
) return false;
211 result
= getWordBoundary(Text
, nPos
, rLocale
, rWordType
, false);
213 return result
.endPos
== nPos
;
216 sal_Int32 SAL_CALL
BreakIteratorImpl::beginOfSentence( const OUString
& Text
, sal_Int32 nStartPos
,
217 const Locale
&rLocale
)
219 if (nStartPos
< 0 || nStartPos
> Text
.getLength())
221 if (Text
.isEmpty()) return 0;
222 return LBI
->beginOfSentence(Text
, nStartPos
, rLocale
);
225 sal_Int32 SAL_CALL
BreakIteratorImpl::endOfSentence( const OUString
& Text
, sal_Int32 nStartPos
,
226 const Locale
&rLocale
)
228 if (nStartPos
< 0 || nStartPos
> Text
.getLength())
230 if (Text
.isEmpty()) return 0;
231 return LBI
->endOfSentence(Text
, nStartPos
, rLocale
);
234 LineBreakResults SAL_CALL
BreakIteratorImpl::getLineBreak( const OUString
& Text
, sal_Int32 nStartPos
,
235 const Locale
& rLocale
, sal_Int32 nMinBreakPos
, const LineBreakHyphenationOptions
& hOptions
,
236 const LineBreakUserOptions
& bOptions
)
238 return LBI
->getLineBreak(Text
, nStartPos
, rLocale
, nMinBreakPos
, hOptions
, bOptions
);
241 sal_Int16 SAL_CALL
BreakIteratorImpl::getScriptType( const OUString
& Text
, sal_Int32 nPos
)
243 return (nPos
< 0 || nPos
>= Text
.getLength()) ? ScriptType::WEAK
:
244 getScriptClass(Text
.iterateCodePoints(&nPos
, 0));
248 /** Increments/decrements position first, then obtains character.
249 @return current position, may be -1 or text length if string was consumed.
251 static sal_Int32
iterateCodePoints(const OUString
& Text
, sal_Int32
&nStartPos
, sal_Int32 inc
, sal_uInt32
& ch
) {
252 sal_Int32 nLen
= Text
.getLength();
253 if (nStartPos
+ inc
< 0 || nStartPos
+ inc
>= nLen
) {
255 nStartPos
= nStartPos
+ inc
< 0 ? -1 : nLen
;
257 ch
= Text
.iterateCodePoints(&nStartPos
, inc
);
259 // erAck: 2009-06-30T21:52+0200 This logic looks somewhat
260 // suspicious as if it cures a symptom.. anyway, had to add
261 // nStartPos < Text.getLength() to silence the (correct) assertion
262 // in rtl_uString_iterateCodePoints() if Text was one character
263 // (codepoint) only, made up of a surrogate pair.
264 //if (inc > 0 && nStartPos < Text.getLength())
265 // ch = Text.iterateCodePoints(&nStartPos, 0);
266 // With surrogates, nStartPos may actually point behind string
267 // now, even if inc is only +1
269 ch
= (nStartPos
< nLen
? Text
.iterateCodePoints(&nStartPos
, 0) : 0);
275 sal_Int32 SAL_CALL
BreakIteratorImpl::beginOfScript( const OUString
& Text
,
276 sal_Int32 nStartPos
, sal_Int16 ScriptType
)
278 if (nStartPos
< 0 || nStartPos
>= Text
.getLength())
281 if(ScriptType
!= getScriptClass(Text
.iterateCodePoints(&nStartPos
, 0)))
284 if (nStartPos
== 0) return 0;
286 while (iterateCodePoints(Text
, nStartPos
, -1, ch
) >= 0 && ScriptType
== getScriptClass(ch
)) {
287 if (nStartPos
== 0) return 0;
290 return iterateCodePoints(Text
, nStartPos
, 1, ch
);
293 sal_Int32 SAL_CALL
BreakIteratorImpl::endOfScript( const OUString
& Text
,
294 sal_Int32 nStartPos
, sal_Int16 ScriptType
)
296 if (nStartPos
< 0 || nStartPos
>= Text
.getLength())
299 if(ScriptType
!= getScriptClass(Text
.iterateCodePoints(&nStartPos
, 0)))
302 sal_Int32 strLen
= Text
.getLength();
304 while(iterateCodePoints(Text
, nStartPos
, 1, ch
) < strLen
) {
305 sal_Int16 currentCharScriptType
= getScriptClass(ch
);
306 if(ScriptType
!= currentCharScriptType
&& currentCharScriptType
!= ScriptType::WEAK
)
312 sal_Int32 SAL_CALL
BreakIteratorImpl::previousScript( const OUString
& Text
,
313 sal_Int32 nStartPos
, sal_Int16 ScriptType
)
317 if (nStartPos
> Text
.getLength())
318 nStartPos
= Text
.getLength();
320 sal_Int16 numberOfChange
= (ScriptType
== getScriptClass(Text
.iterateCodePoints(&nStartPos
, 0))) ? 3 : 2;
323 while (numberOfChange
> 0 && iterateCodePoints(Text
, nStartPos
, -1, ch
) >= 0) {
324 if (((numberOfChange
% 2) == 0) != (ScriptType
!= getScriptClass(ch
)))
326 else if (nStartPos
== 0) {
330 return numberOfChange
== 0 ? iterateCodePoints(Text
, nStartPos
, 1, ch
) : -1;
333 sal_Int32 SAL_CALL
BreakIteratorImpl::nextScript( const OUString
& Text
, sal_Int32 nStartPos
,
334 sal_Int16 ScriptType
)
339 sal_Int32 strLen
= Text
.getLength();
340 if (nStartPos
>= strLen
)
343 sal_Int16 numberOfChange
= (ScriptType
== getScriptClass(Text
.iterateCodePoints(&nStartPos
, 0))) ? 2 : 1;
346 while (numberOfChange
> 0 && iterateCodePoints(Text
, nStartPos
, 1, ch
) < strLen
) {
347 sal_Int16 currentCharScriptType
= getScriptClass(ch
);
348 if ((numberOfChange
== 1) ? (ScriptType
== currentCharScriptType
) :
349 (ScriptType
!= currentCharScriptType
&& currentCharScriptType
!= ScriptType::WEAK
))
352 return numberOfChange
== 0 ? nStartPos
: -1;
355 sal_Int32 SAL_CALL
BreakIteratorImpl::beginOfCharBlock( const OUString
& Text
, sal_Int32 nStartPos
,
356 const Locale
& /*rLocale*/, sal_Int16 CharType
)
358 if (CharType
== CharType::ANY_CHAR
) return 0;
359 if (nStartPos
< 0 || nStartPos
>= Text
.getLength()) return -1;
360 if (CharType
!= static_cast<sal_Int16
>(u_charType( Text
.iterateCodePoints(&nStartPos
, 0)))) return -1;
362 sal_Int32 nPos
=nStartPos
;
363 while(nStartPos
> 0 && CharType
== static_cast<sal_Int16
>(u_charType(Text
.iterateCodePoints(&nPos
, -1)))) { nStartPos
=nPos
; }
364 return nStartPos
; // begin of char block is inclusive
367 sal_Int32 SAL_CALL
BreakIteratorImpl::endOfCharBlock( const OUString
& Text
, sal_Int32 nStartPos
,
368 const Locale
& /*rLocale*/, sal_Int16 CharType
)
370 sal_Int32 strLen
= Text
.getLength();
372 if (CharType
== CharType::ANY_CHAR
) return strLen
; // end of char block is exclusive
373 if (nStartPos
< 0 || nStartPos
>= strLen
) return -1;
374 if (CharType
!= static_cast<sal_Int16
>(u_charType(Text
.iterateCodePoints(&nStartPos
, 0)))) return -1;
377 while(iterateCodePoints(Text
, nStartPos
, 1, ch
) < strLen
&& CharType
== static_cast<sal_Int16
>(u_charType(ch
))) {}
378 return nStartPos
; // end of char block is exclusive
381 sal_Int32 SAL_CALL
BreakIteratorImpl::nextCharBlock( const OUString
& Text
, sal_Int32 nStartPos
,
382 const Locale
& /*rLocale*/, sal_Int16 CharType
)
384 if (CharType
== CharType::ANY_CHAR
) return -1;
385 if (nStartPos
< 0 || nStartPos
>= Text
.getLength()) return -1;
387 sal_Int16 numberOfChange
= (CharType
== static_cast<sal_Int16
>(u_charType(Text
.iterateCodePoints(&nStartPos
, 0)))) ? 2 : 1;
388 sal_Int32 strLen
= Text
.getLength();
391 while (numberOfChange
> 0 && iterateCodePoints(Text
, nStartPos
, 1, ch
) < strLen
) {
392 if ((CharType
!= static_cast<sal_Int16
>(u_charType(ch
))) != (numberOfChange
== 1))
395 return numberOfChange
== 0 ? nStartPos
: -1;
398 sal_Int32 SAL_CALL
BreakIteratorImpl::previousCharBlock( const OUString
& Text
, sal_Int32 nStartPos
,
399 const Locale
& /*rLocale*/, sal_Int16 CharType
)
401 if(CharType
== CharType::ANY_CHAR
) return -1;
402 if (nStartPos
< 0 || nStartPos
>= Text
.getLength()) return -1;
404 sal_Int16 numberOfChange
= (CharType
== static_cast<sal_Int16
>(u_charType(Text
.iterateCodePoints(&nStartPos
, 0)))) ? 3 : 2;
407 while (numberOfChange
> 0 && iterateCodePoints(Text
, nStartPos
, -1, ch
) >= 0) {
408 if (((numberOfChange
% 2) == 0) != (CharType
!= static_cast<sal_Int16
>(u_charType(ch
))))
410 if (nStartPos
== 0 && numberOfChange
> 0) {
412 if (numberOfChange
== 0) return nStartPos
;
415 return numberOfChange
== 0 ? iterateCodePoints(Text
, nStartPos
, 1, ch
) : -1;
419 sal_Int16 SAL_CALL
BreakIteratorImpl::getWordType( const OUString
& /*Text*/,
420 sal_Int32
/*nPos*/, const Locale
& /*rLocale*/ )
427 sal_Int16
getScriptClassByUAX24Script(sal_uInt32 currentChar
)
429 int32_t script
= u_getIntPropertyValue(currentChar
, UCHAR_SCRIPT
);
430 return unicode::getScriptClassFromUScriptCode(static_cast<UScriptCode
>(script
));
440 static const UBlock2Script scriptList
[] =
442 {UBLOCK_NO_BLOCK
, UBLOCK_NO_BLOCK
, ScriptType::WEAK
},
443 {UBLOCK_BASIC_LATIN
, UBLOCK_SPACING_MODIFIER_LETTERS
, ScriptType::LATIN
},
444 {UBLOCK_GREEK
, UBLOCK_ARMENIAN
, ScriptType::LATIN
},
445 {UBLOCK_HEBREW
, UBLOCK_MYANMAR
, ScriptType::COMPLEX
},
446 {UBLOCK_GEORGIAN
, UBLOCK_GEORGIAN
, ScriptType::LATIN
},
447 {UBLOCK_HANGUL_JAMO
, UBLOCK_HANGUL_JAMO
, ScriptType::ASIAN
},
448 {UBLOCK_ETHIOPIC
, UBLOCK_ETHIOPIC
, ScriptType::COMPLEX
},
449 {UBLOCK_CHEROKEE
, UBLOCK_RUNIC
, ScriptType::LATIN
},
450 {UBLOCK_KHMER
, UBLOCK_MONGOLIAN
, ScriptType::COMPLEX
},
451 {UBLOCK_LATIN_EXTENDED_ADDITIONAL
, UBLOCK_GREEK_EXTENDED
, ScriptType::LATIN
},
452 {UBLOCK_NUMBER_FORMS
, UBLOCK_NUMBER_FORMS
, ScriptType::WEAK
},
453 {UBLOCK_CJK_RADICALS_SUPPLEMENT
, UBLOCK_HANGUL_SYLLABLES
, ScriptType::ASIAN
},
454 {UBLOCK_CJK_COMPATIBILITY_IDEOGRAPHS
, UBLOCK_CJK_COMPATIBILITY_IDEOGRAPHS
, ScriptType::ASIAN
},
455 {UBLOCK_ARABIC_PRESENTATION_FORMS_A
, UBLOCK_ARABIC_PRESENTATION_FORMS_A
, ScriptType::COMPLEX
},
456 {UBLOCK_CJK_COMPATIBILITY_FORMS
, UBLOCK_CJK_COMPATIBILITY_FORMS
, ScriptType::ASIAN
},
457 {UBLOCK_ARABIC_PRESENTATION_FORMS_B
, UBLOCK_ARABIC_PRESENTATION_FORMS_B
, ScriptType::COMPLEX
},
458 {UBLOCK_HALFWIDTH_AND_FULLWIDTH_FORMS
, UBLOCK_HALFWIDTH_AND_FULLWIDTH_FORMS
, ScriptType::ASIAN
},
459 {UBLOCK_CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B
, UBLOCK_CJK_COMPATIBILITY_IDEOGRAPHS_SUPPLEMENT
, ScriptType::ASIAN
},
460 {UBLOCK_CJK_STROKES
, UBLOCK_CJK_STROKES
, ScriptType::ASIAN
},
461 {UBLOCK_LATIN_EXTENDED_C
, UBLOCK_LATIN_EXTENDED_D
, ScriptType::LATIN
}
464 #define scriptListCount SAL_N_ELEMENTS(scriptList)
466 //always sets rScriptType
468 //returns true for characters historically explicitly assigned to
471 //returns false for characters that historically implicitly assigned to
473 bool getCompatibilityScriptClassByBlock(sal_uInt32 currentChar
, sal_Int16
&rScriptType
)
476 //handle specific characters always as weak:
477 // 0x01 - this breaks a word
478 // 0x02 - this can be inside a word
479 // 0x20 & 0xA0 - Bug 102975, declare western space and non-break space as WEAK char.
480 if( 0x01 == currentChar
|| 0x02 == currentChar
|| 0x20 == currentChar
|| 0xA0 == currentChar
)
481 rScriptType
= ScriptType::WEAK
;
482 // Few Spacing Modifier Letters that can be Bopomofo tonal marks.
483 else if ( 0x2CA == currentChar
|| 0x2CB == currentChar
|| 0x2C7 == currentChar
|| 0x2D9 == currentChar
)
484 rScriptType
= ScriptType::WEAK
;
485 // workaround for Coptic
486 else if ( 0x2C80 <= currentChar
&& 0x2CE3 >= currentChar
)
487 rScriptType
= ScriptType::LATIN
;
490 UBlockCode block
=ublock_getCode(currentChar
);
492 while (i
< scriptListCount
)
494 if (block
<= scriptList
[i
].to
)
498 if (i
< scriptListCount
&& block
>= scriptList
[i
].from
)
499 rScriptType
= scriptList
[i
].script
;
502 rScriptType
= ScriptType::WEAK
;
510 sal_Int16
BreakIteratorImpl::getScriptClass(sal_uInt32 currentChar
)
512 static sal_uInt32 lastChar
= 0;
513 static sal_Int16 nRet
= ScriptType::WEAK
;
515 if (currentChar
!= lastChar
)
517 lastChar
= currentChar
;
519 if (!getCompatibilityScriptClassByBlock(currentChar
, nRet
))
520 nRet
= getScriptClassByUAX24Script(currentChar
);
526 bool BreakIteratorImpl::createLocaleSpecificBreakIterator(const OUString
& aLocaleName
)
528 // to share service between same Language but different Country code, like zh_CN and zh_TW
529 for (lookupTableItem
& listItem
: lookupTable
) {
530 if (aLocaleName
== listItem
.aLocale
.Language
) {
536 #if !WITH_LOCALE_ALL && !WITH_LOCALE_ja
537 if (aLocaleName
== "ja")
540 #if !WITH_LOCALE_ALL && !WITH_LOCALE_zh
541 if (aLocaleName
== "zh" || aLocaleName
== "zh_TW")
544 #if !WITH_LOCALE_ALL && !WITH_LOCALE_ko
545 if (aLocaleName
== "ko")
548 #if !WITH_LOCALE_ALL && !WITH_LOCALE_th
549 if (aLocaleName
== "th")
553 Reference
< uno::XInterface
> xI
= m_xContext
->getServiceManager()->createInstanceWithContext(
554 "com.sun.star.i18n.BreakIterator_" + aLocaleName
, m_xContext
);
557 xBI
.set(xI
, UNO_QUERY
);
559 lookupTable
.emplace_back(Locale(aLocaleName
, aLocaleName
, aLocaleName
), xBI
);
566 Reference
< XBreakIterator
>
567 BreakIteratorImpl::getLocaleSpecificBreakIterator(const Locale
& rLocale
)
569 if (xBI
.is() && rLocale
== aLocale
)
571 else if (m_xContext
.is()) {
574 for (lookupTableItem
& listItem
: lookupTable
) {
575 if (rLocale
== listItem
.aLocale
)
576 return xBI
= listItem
.xBI
;
579 sal_Unicode under
= '_';
581 sal_Int32 l
= rLocale
.Language
.getLength();
582 sal_Int32 c
= rLocale
.Country
.getLength();
583 sal_Int32 v
= rLocale
.Variant
.getLength();
584 OUStringBuffer
aBuf(l
+c
+v
+3);
586 if ((l
> 0 && c
> 0 && v
> 0 &&
587 // load service with name <base>_<lang>_<country>_<variant>
588 createLocaleSpecificBreakIterator(aBuf
.append(rLocale
.Language
).append(under
).append(
589 rLocale
.Country
).append(under
).append(rLocale
.Variant
).makeStringAndClear())) ||
591 // load service with name <base>_<lang>_<country>
592 createLocaleSpecificBreakIterator(aBuf
.append(rLocale
.Language
).append(under
).append(
593 rLocale
.Country
).makeStringAndClear())) ||
594 (l
> 0 && c
> 0 && rLocale
.Language
== "zh" &&
595 (rLocale
.Country
== "HK" ||
596 rLocale
.Country
== "MO" ) &&
597 // if the country code is HK or MO, one more step to try TW.
598 createLocaleSpecificBreakIterator(aBuf
.append(rLocale
.Language
).append(under
).append(
599 "TW").makeStringAndClear())) ||
601 // load service with name <base>_<lang>
602 createLocaleSpecificBreakIterator(rLocale
.Language
)) ||
603 // load default service with name <base>_Unicode
604 createLocaleSpecificBreakIterator("Unicode")) {
605 lookupTable
.emplace_back( aLocale
, xBI
);
609 throw RuntimeException();
613 BreakIteratorImpl::getImplementationName()
615 return OUString("com.sun.star.i18n.BreakIterator");
619 BreakIteratorImpl::supportsService(const OUString
& rServiceName
)
621 return cppu::supportsService(this, rServiceName
);
624 Sequence
< OUString
> SAL_CALL
625 BreakIteratorImpl::getSupportedServiceNames()
627 Sequence
< OUString
> aRet
{ "com.sun.star.i18n.BreakIterator" };
633 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
634 com_sun_star_i18n_BreakIterator_get_implementation(
635 css::uno::XComponentContext
*context
,
636 css::uno::Sequence
<css::uno::Any
> const &)
638 return cppu::acquire(new i18npool::BreakIteratorImpl(context
));
641 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */