1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: breakiterator_ctl.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_i18npool.hxx"
34 #include <com/sun/star/i18n/CharacterIteratorMode.hpp>
35 #include <breakiterator_ctl.hxx>
37 #include <string.h> // for memset
39 using namespace ::com::sun::star::uno
;
40 using namespace ::com::sun::star::lang
;
41 using namespace ::rtl
;
43 namespace com
{ namespace sun
{ namespace star
{ namespace i18n
{
48 BreakIterator_CTL::BreakIterator_CTL() :
50 nextCellIndex( NULL
),
51 previousCellIndex( NULL
),
54 cBreakIterator
= "com.sun.star.i18n.BreakIterator_CTL";
55 // to improve performance, alloc big enough memory in construct.
56 nextCellIndex
= (sal_Int32
*) calloc(cellIndexSize
, sizeof(sal_Int32
));
57 previousCellIndex
= (sal_Int32
*) calloc(cellIndexSize
, sizeof(sal_Int32
));
58 memset(nextCellIndex
, 0, cellIndexSize
* sizeof(sal_Int32
));
64 BreakIterator_CTL::~BreakIterator_CTL()
67 free(previousCellIndex
);
70 sal_Int32 SAL_CALL
BreakIterator_CTL::previousCharacters( const OUString
& Text
,
71 sal_Int32 nStartPos
, const lang::Locale
& rLocale
,
72 sal_Int16 nCharacterIteratorMode
, sal_Int32 nCount
, sal_Int32
& nDone
)
73 throw(RuntimeException
)
75 if (nCharacterIteratorMode
== CharacterIteratorMode::SKIPCELL
) {
77 if (nStartPos
> 0) { // for others to skip cell.
78 makeIndex(Text
, nStartPos
);
80 if (nextCellIndex
[nStartPos
-1] == 0) // not a CTL character
81 return BreakIterator_Unicode::previousCharacters(Text
, nStartPos
, rLocale
,
82 nCharacterIteratorMode
, nCount
, nDone
);
83 else while (nCount
> 0 && nextCellIndex
[nStartPos
- 1] > 0) {
85 nStartPos
= previousCellIndex
[nStartPos
- 1];
89 } else { // for BS to delete one char.
90 nDone
= (nStartPos
> nCount
) ? nCount
: nStartPos
;
97 sal_Int32 SAL_CALL
BreakIterator_CTL::nextCharacters(const OUString
& Text
,
98 sal_Int32 nStartPos
, const lang::Locale
& rLocale
,
99 sal_Int16 nCharacterIteratorMode
, sal_Int32 nCount
, sal_Int32
& nDone
)
100 throw(RuntimeException
)
102 sal_Int32 len
= Text
.getLength();
103 if (nCharacterIteratorMode
== CharacterIteratorMode::SKIPCELL
) {
105 if (nStartPos
< len
) {
106 makeIndex(Text
, nStartPos
);
108 if (nextCellIndex
[nStartPos
] == 0) // not a CTL character
109 return BreakIterator_Unicode::nextCharacters(Text
, nStartPos
, rLocale
,
110 nCharacterIteratorMode
, nCount
, nDone
);
111 else while (nCount
> 0 && nextCellIndex
[nStartPos
] > 0) {
113 nStartPos
= nextCellIndex
[nStartPos
];
118 nDone
= (len
- nStartPos
> nCount
) ? nCount
: len
- nStartPos
;
125 // This method should be overwritten by derived language specific class.
126 void SAL_CALL
BreakIterator_CTL::makeIndex(const OUString
& /*text*/, sal_Int32
/*pos*/)
127 throw(RuntimeException
)
129 throw RuntimeException();
132 // Make sure line is broken on cell boundary if we implement cell iterator.
133 LineBreakResults SAL_CALL
BreakIterator_CTL::getLineBreak(
134 const OUString
& Text
, sal_Int32 nStartPos
,
135 const lang::Locale
& rLocale
, sal_Int32 nMinBreakPos
,
136 const LineBreakHyphenationOptions
& hOptions
,
137 const LineBreakUserOptions
& bOptions
) throw(RuntimeException
)
139 LineBreakResults lbr
= BreakIterator_Unicode::getLineBreak(Text
, nStartPos
,
140 rLocale
, nMinBreakPos
, hOptions
, bOptions
);
141 if (lbr
.breakIndex
< Text
.getLength()) {
142 makeIndex(Text
, lbr
.breakIndex
);
143 lbr
.breakIndex
= previousCellIndex
[ lbr
.breakIndex
];