update emoji autocorrect entries from po-files
[LibreOffice.git] / i18npool / source / breakiterator / breakiterator_ctl.cxx
blob8a4593238dd84752257f04a366f088c2f59edb9d
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;
27 namespace com { namespace sun { namespace star { namespace i18n {
29 /**
30 * Constructor.
32 BreakIterator_CTL::BreakIterator_CTL() :
33 cachedText(),
34 nextCellIndex( NULL ),
35 previousCellIndex( NULL ),
36 cellIndexSize( 512 )
38 cBreakIterator = "com.sun.star.i18n.BreakIterator_CTL";
39 // to improve performance, alloc big enough memory in construct.
40 nextCellIndex = static_cast<sal_Int32*>(calloc(cellIndexSize, sizeof(sal_Int32)));
41 previousCellIndex = static_cast<sal_Int32*>(calloc(cellIndexSize, sizeof(sal_Int32)));
44 /**
45 * Deconstructor.
47 BreakIterator_CTL::~BreakIterator_CTL()
49 free(nextCellIndex);
50 free(previousCellIndex);
53 sal_Int32 SAL_CALL BreakIterator_CTL::previousCharacters( const OUString& Text,
54 sal_Int32 nStartPos, const lang::Locale& rLocale,
55 sal_Int16 nCharacterIteratorMode, sal_Int32 nCount, sal_Int32& nDone )
56 throw(RuntimeException, std::exception)
58 if (nCharacterIteratorMode == CharacterIteratorMode::SKIPCELL ) {
59 nDone = 0;
60 if (nStartPos > 0) { // for others to skip cell.
61 makeIndex(Text, nStartPos);
63 if (nextCellIndex[nStartPos-1] == 0) // not a CTL character
64 return BreakIterator_Unicode::previousCharacters(Text, nStartPos, rLocale,
65 nCharacterIteratorMode, nCount, nDone);
66 else while (nCount > 0 && nextCellIndex[nStartPos - 1] > 0) {
67 nCount--; nDone++;
68 nStartPos = previousCellIndex[nStartPos - 1];
70 } else
71 nStartPos = 0;
72 } else { // for BS to delete one char.
73 nDone = (nStartPos > nCount) ? nCount : nStartPos;
74 nStartPos -= nDone;
77 return nStartPos;
80 sal_Int32 SAL_CALL BreakIterator_CTL::nextCharacters(const OUString& Text,
81 sal_Int32 nStartPos, const lang::Locale& rLocale,
82 sal_Int16 nCharacterIteratorMode, sal_Int32 nCount, sal_Int32& nDone)
83 throw(RuntimeException, std::exception)
85 sal_Int32 len = Text.getLength();
86 if (nCharacterIteratorMode == CharacterIteratorMode::SKIPCELL ) {
87 nDone = 0;
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) {
95 nCount--; nDone++;
96 nStartPos = nextCellIndex[nStartPos];
98 } else
99 nStartPos = len;
100 } else {
101 nDone = (len - nStartPos > nCount) ? nCount : len - nStartPos;
102 nStartPos += nDone;
105 return 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*/)
110 throw(RuntimeException)
112 throw RuntimeException();
115 // Make sure line is broken on cell boundary if we implement cell iterator.
116 LineBreakResults SAL_CALL BreakIterator_CTL::getLineBreak(
117 const OUString& Text, sal_Int32 nStartPos,
118 const lang::Locale& rLocale, sal_Int32 nMinBreakPos,
119 const LineBreakHyphenationOptions& hOptions,
120 const LineBreakUserOptions& bOptions ) throw(RuntimeException, std::exception)
122 LineBreakResults lbr = BreakIterator_Unicode::getLineBreak(Text, nStartPos,
123 rLocale, nMinBreakPos, hOptions, bOptions );
124 if (lbr.breakIndex < Text.getLength()) {
125 makeIndex(Text, lbr.breakIndex);
126 lbr.breakIndex = previousCellIndex[ lbr.breakIndex ];
128 return lbr;
131 } } } }
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */