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 #include <com/sun/star/i18n/CharacterIteratorMode.hpp>
22 #include <breakiterator_ctl.hxx>
24 using namespace ::com::sun::star
;
25 using namespace ::com::sun::star::uno
;
26 using namespace ::com::sun::star::i18n
;
27 using namespace ::com::sun::star::lang
;
34 BreakIterator_CTL::BreakIterator_CTL() :
36 nextCellIndex( nullptr ),
37 previousCellIndex( nullptr ),
40 cBreakIterator
= "com.sun.star.i18n.BreakIterator_CTL";
41 // to improve performance, alloc big enough memory in construct.
42 nextCellIndex
= static_cast<sal_Int32
*>(calloc(cellIndexSize
, sizeof(sal_Int32
)));
43 previousCellIndex
= static_cast<sal_Int32
*>(calloc(cellIndexSize
, sizeof(sal_Int32
)));
49 BreakIterator_CTL::~BreakIterator_CTL()
52 free(previousCellIndex
);
55 sal_Int32 SAL_CALL
BreakIterator_CTL::previousCharacters( const OUString
& Text
,
56 sal_Int32 nStartPos
, const lang::Locale
& rLocale
,
57 sal_Int16 nCharacterIteratorMode
, sal_Int32 nCount
, sal_Int32
& nDone
)
59 if (nCharacterIteratorMode
== CharacterIteratorMode::SKIPCELL
) {
61 if (nStartPos
> 0) { // for others to skip cell.
62 makeIndex(Text
, nStartPos
);
64 if (nextCellIndex
[nStartPos
-1] == 0) // not a CTL character
65 return BreakIterator_Unicode::previousCharacters(Text
, nStartPos
, rLocale
,
66 nCharacterIteratorMode
, nCount
, nDone
);
67 else while (nCount
> 0 && nextCellIndex
[nStartPos
- 1] > 0) {
69 nStartPos
= previousCellIndex
[nStartPos
- 1];
73 } else { // for BS to delete one char.
74 nDone
= (nStartPos
> nCount
) ? nCount
: nStartPos
;
81 sal_Int32 SAL_CALL
BreakIterator_CTL::nextCharacters(const OUString
& Text
,
82 sal_Int32 nStartPos
, const lang::Locale
& rLocale
,
83 sal_Int16 nCharacterIteratorMode
, sal_Int32 nCount
, sal_Int32
& nDone
)
85 sal_Int32 len
= Text
.getLength();
86 if (nCharacterIteratorMode
== CharacterIteratorMode::SKIPCELL
) {
88 if (nStartPos
< len
) {
89 makeIndex(Text
, nStartPos
);
91 if (nextCellIndex
[nStartPos
] == 0) // not a CTL character
92 return BreakIterator_Unicode::nextCharacters(Text
, nStartPos
, rLocale
,
93 nCharacterIteratorMode
, nCount
, nDone
);
94 else while (nCount
> 0 && nextCellIndex
[nStartPos
] > 0) {
96 nStartPos
= nextCellIndex
[nStartPos
];
101 nDone
= (len
- nStartPos
> nCount
) ? nCount
: len
- nStartPos
;
108 // This method should be overwritten by derived language specific class.
109 void SAL_CALL
BreakIterator_CTL::makeIndex(const OUString
& /*text*/, sal_Int32
/*pos*/)
111 throw RuntimeException();
114 // Make sure line is broken on cell boundary if we implement cell iterator.
115 LineBreakResults SAL_CALL
BreakIterator_CTL::getLineBreak(
116 const OUString
& Text
, sal_Int32 nStartPos
,
117 const lang::Locale
& rLocale
, sal_Int32 nMinBreakPos
,
118 const LineBreakHyphenationOptions
& hOptions
,
119 const LineBreakUserOptions
& bOptions
)
121 LineBreakResults lbr
= BreakIterator_Unicode::getLineBreak(Text
, nStartPos
,
122 rLocale
, nMinBreakPos
, hOptions
, bOptions
);
123 if (lbr
.breakIndex
< Text
.getLength()) {
124 makeIndex(Text
, lbr
.breakIndex
);
125 lbr
.breakIndex
= previousCellIndex
[ lbr
.breakIndex
];
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */