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 .
21 #define BREAKITERATOR_ALL
22 #include <breakiterator_cjk.hxx>
23 #include <localedata.hxx>
24 #include <i18nutil/unicode.hxx>
26 using namespace ::com::sun::star::uno
;
27 using namespace ::com::sun::star::lang
;
28 using namespace ::rtl
;
30 namespace com
{ namespace sun
{ namespace star
{ namespace i18n
{
32 // ----------------------------------------------------
33 // class BreakIterator_CJK
34 // ----------------------------------------------------;
36 BreakIterator_CJK::BreakIterator_CJK() :
40 cBreakIterator
= "com.sun.star.i18n.BreakIterator_CJK";
44 BreakIterator_CJK::previousWord(const OUString
& text
, sal_Int32 anyPos
,
45 const lang::Locale
& nLocale
, sal_Int16 wordType
) throw(RuntimeException
)
48 result
= dict
->previousWord(text
, anyPos
, wordType
);
49 // #109813# for non-CJK, single character word, fallback to ICU breakiterator.
50 if (result
.endPos
- result
.startPos
!= 1 ||
51 getScriptType(text
, result
.startPos
) == ScriptType::ASIAN
)
53 result
= BreakIterator_Unicode::getWordBoundary(text
, result
.startPos
, nLocale
, wordType
, true);
54 if (result
.endPos
< anyPos
)
57 return BreakIterator_Unicode::previousWord(text
, anyPos
, nLocale
, wordType
);
61 BreakIterator_CJK::nextWord(const OUString
& text
, sal_Int32 anyPos
,
62 const lang::Locale
& nLocale
, sal_Int16 wordType
) throw(RuntimeException
)
65 result
= dict
->nextWord(text
, anyPos
, wordType
);
66 // #109813# for non-CJK, single character word, fallback to ICU breakiterator.
67 if (result
.endPos
- result
.startPos
!= 1 ||
68 getScriptType(text
, result
.startPos
) == ScriptType::ASIAN
)
70 result
= BreakIterator_Unicode::getWordBoundary(text
, result
.startPos
, nLocale
, wordType
, true);
71 if (result
.startPos
> anyPos
)
74 return BreakIterator_Unicode::nextWord(text
, anyPos
, nLocale
, wordType
);
78 BreakIterator_CJK::getWordBoundary( const OUString
& text
, sal_Int32 anyPos
,
79 const lang::Locale
& nLocale
, sal_Int16 wordType
, sal_Bool bDirection
)
80 throw(RuntimeException
)
83 result
= dict
->getWordBoundary(text
, anyPos
, wordType
, bDirection
);
84 // #109813# for non-CJK, single character word, fallback to ICU breakiterator.
85 if (result
.endPos
- result
.startPos
!= 1 ||
86 getScriptType(text
, result
.startPos
) == ScriptType::ASIAN
)
89 return BreakIterator_Unicode::getWordBoundary(text
, anyPos
, nLocale
, wordType
, bDirection
);
92 LineBreakResults SAL_CALL
BreakIterator_CJK::getLineBreak(
93 const OUString
& Text
, sal_Int32 nStartPos
,
94 const lang::Locale
& /*rLocale*/, sal_Int32
/*nMinBreakPos*/,
95 const LineBreakHyphenationOptions
& /*hOptions*/,
96 const LineBreakUserOptions
& bOptions
) throw(RuntimeException
)
100 if (bOptions
.allowPunctuationOutsideMargin
&&
101 hangingCharacters
.indexOf(Text
[nStartPos
]) != -1 &&
102 (Text
.iterateCodePoints( &nStartPos
, 1), nStartPos
== Text
.getLength())) {
104 } else if (bOptions
.applyForbiddenRules
&& 0 < nStartPos
&& nStartPos
< Text
.getLength()) {
105 while (nStartPos
> 0 &&
106 (bOptions
.forbiddenBeginCharacters
.indexOf(Text
[nStartPos
]) != -1 ||
107 bOptions
.forbiddenEndCharacters
.indexOf(Text
[nStartPos
-1]) != -1))
108 Text
.iterateCodePoints( &nStartPos
, -1);
111 lbr
.breakIndex
= nStartPos
;
112 lbr
.breakType
= BreakType::WORDBOUNDARY
;
116 #define LOCALE(language, country) lang::Locale(OUString::createFromAscii(language), OUString::createFromAscii(country), OUString())
117 // ----------------------------------------------------
118 // class BreakIterator_zh
119 // ----------------------------------------------------;
120 BreakIterator_zh::BreakIterator_zh()
122 dict
= new xdictionary("zh");
123 hangingCharacters
= LocaleData().getHangingCharacters(LOCALE("zh", "CN"));
124 cBreakIterator
= "com.sun.star.i18n.BreakIterator_zh";
127 BreakIterator_zh::~BreakIterator_zh()
132 // ----------------------------------------------------
133 // class BreakIterator_zh_TW
134 // ----------------------------------------------------;
135 BreakIterator_zh_TW::BreakIterator_zh_TW()
137 dict
= new xdictionary("zh");
138 hangingCharacters
= LocaleData().getHangingCharacters(LOCALE("zh", "TW"));
139 cBreakIterator
= "com.sun.star.i18n.BreakIterator_zh_TW";
142 BreakIterator_zh_TW::~BreakIterator_zh_TW()
147 // ----------------------------------------------------
148 // class BreakIterator_ja
149 // ----------------------------------------------------;
150 BreakIterator_ja::BreakIterator_ja()
152 dict
= new xdictionary("ja");
153 dict
->setJapaneseWordBreak();
154 hangingCharacters
= LocaleData().getHangingCharacters(LOCALE("ja", "JP"));
155 cBreakIterator
= "com.sun.star.i18n.BreakIterator_ja";
158 BreakIterator_ja::~BreakIterator_ja()
163 // ----------------------------------------------------
164 // class BreakIterator_ko
165 // ----------------------------------------------------;
166 BreakIterator_ko::BreakIterator_ko()
168 hangingCharacters
= LocaleData().getHangingCharacters(LOCALE("ko", "KR"));
169 cBreakIterator
= "com.sun.star.i18n.BreakIterator_ko";
172 BreakIterator_ko::~BreakIterator_ko()
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */