Bump version to 4.3-4
[LibreOffice.git] / i18npool / source / breakiterator / breakiterator_ctl.cxx
blobc2058904fc5c41dd17910c1edf335d7369751772
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 <com/sun/star/i18n/CharacterIteratorMode.hpp>
22 #include <breakiterator_ctl.hxx>
24 using namespace ::com::sun::star::uno;
25 using namespace ::com::sun::star::lang;
26 using namespace ::rtl;
28 namespace com { namespace sun { namespace star { namespace i18n {
30 /**
31 * Constructor.
33 BreakIterator_CTL::BreakIterator_CTL() :
34 cachedText(),
35 nextCellIndex( NULL ),
36 previousCellIndex( NULL ),
37 cellIndexSize( 512 )
39 cBreakIterator = "com.sun.star.i18n.BreakIterator_CTL";
40 // to improve performance, alloc big enough memory in construct.
41 nextCellIndex = (sal_Int32*) calloc(cellIndexSize, sizeof(sal_Int32));
42 previousCellIndex = (sal_Int32*) calloc(cellIndexSize, sizeof(sal_Int32));
45 /**
46 * Deconstructor.
48 BreakIterator_CTL::~BreakIterator_CTL()
50 free(nextCellIndex);
51 free(previousCellIndex);
54 sal_Int32 SAL_CALL BreakIterator_CTL::previousCharacters( const OUString& Text,
55 sal_Int32 nStartPos, const lang::Locale& rLocale,
56 sal_Int16 nCharacterIteratorMode, sal_Int32 nCount, sal_Int32& nDone )
57 throw(RuntimeException, std::exception)
59 if (nCharacterIteratorMode == CharacterIteratorMode::SKIPCELL ) {
60 nDone = 0;
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) {
68 nCount--; nDone++;
69 nStartPos = previousCellIndex[nStartPos - 1];
71 } else
72 nStartPos = 0;
73 } else { // for BS to delete one char.
74 nDone = (nStartPos > nCount) ? nCount : nStartPos;
75 nStartPos -= nDone;
78 return 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)
84 throw(RuntimeException, std::exception)
86 sal_Int32 len = Text.getLength();
87 if (nCharacterIteratorMode == CharacterIteratorMode::SKIPCELL ) {
88 nDone = 0;
89 if (nStartPos < len) {
90 makeIndex(Text, nStartPos);
92 if (nextCellIndex[nStartPos] == 0) // not a CTL character
93 return BreakIterator_Unicode::nextCharacters(Text, nStartPos, rLocale,
94 nCharacterIteratorMode, nCount, nDone);
95 else while (nCount > 0 && nextCellIndex[nStartPos] > 0) {
96 nCount--; nDone++;
97 nStartPos = nextCellIndex[nStartPos];
99 } else
100 nStartPos = len;
101 } else {
102 nDone = (len - nStartPos > nCount) ? nCount : len - nStartPos;
103 nStartPos += nDone;
106 return nStartPos;
109 // This method should be overwritten by derived language specific class.
110 void SAL_CALL BreakIterator_CTL::makeIndex(const OUString& /*text*/, sal_Int32 /*pos*/)
111 throw(RuntimeException)
113 throw RuntimeException();
116 // Make sure line is broken on cell boundary if we implement cell iterator.
117 LineBreakResults SAL_CALL BreakIterator_CTL::getLineBreak(
118 const OUString& Text, sal_Int32 nStartPos,
119 const lang::Locale& rLocale, sal_Int32 nMinBreakPos,
120 const LineBreakHyphenationOptions& hOptions,
121 const LineBreakUserOptions& bOptions ) throw(RuntimeException, std::exception)
123 LineBreakResults lbr = BreakIterator_Unicode::getLineBreak(Text, nStartPos,
124 rLocale, nMinBreakPos, hOptions, bOptions );
125 if (lbr.breakIndex < Text.getLength()) {
126 makeIndex(Text, lbr.breakIndex);
127 lbr.breakIndex = previousCellIndex[ lbr.breakIndex ];
129 return lbr;
132 } } } }
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */