LCOV - code coverage report
Current view: top level - i18npool/source/breakiterator - breakiterator_ctl.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 10 47 21.3 %
Date: 2015-06-13 12:38:46 Functions: 2 7 28.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : 
      21             : #include <com/sun/star/i18n/CharacterIteratorMode.hpp>
      22             : #include <breakiterator_ctl.hxx>
      23             : 
      24             : using namespace ::com::sun::star::uno;
      25             : using namespace ::com::sun::star::lang;
      26             : 
      27             : namespace com { namespace sun { namespace star { namespace i18n {
      28             : 
      29             : /**
      30             :  * Constructor.
      31             :  */
      32           1 : BreakIterator_CTL::BreakIterator_CTL() :
      33             :     cachedText(),
      34             :     nextCellIndex( NULL ),
      35             :     previousCellIndex( NULL ),
      36           1 :     cellIndexSize( 512 )
      37             : {
      38           1 :     cBreakIterator = "com.sun.star.i18n.BreakIterator_CTL";
      39             :     // to improve performance, alloc big enough memory in construct.
      40           1 :     nextCellIndex = static_cast<sal_Int32*>(calloc(cellIndexSize, sizeof(sal_Int32)));
      41           1 :     previousCellIndex = static_cast<sal_Int32*>(calloc(cellIndexSize, sizeof(sal_Int32)));
      42           1 : }
      43             : 
      44             : /**
      45             :  * Deconstructor.
      46             :  */
      47           2 : BreakIterator_CTL::~BreakIterator_CTL()
      48             : {
      49           1 :     free(nextCellIndex);
      50           1 :     free(previousCellIndex);
      51           1 : }
      52             : 
      53           0 : 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)
      57             : {
      58           0 :     if (nCharacterIteratorMode == CharacterIteratorMode::SKIPCELL ) {
      59           0 :         nDone = 0;
      60           0 :         if (nStartPos > 0) {    // for others to skip cell.
      61           0 :             makeIndex(Text, nStartPos);
      62             : 
      63           0 :             if (nextCellIndex[nStartPos-1] == 0) // not a CTL character
      64             :                 return BreakIterator_Unicode::previousCharacters(Text, nStartPos, rLocale,
      65           0 :                     nCharacterIteratorMode, nCount, nDone);
      66           0 :             else while (nCount > 0 && nextCellIndex[nStartPos - 1] > 0) {
      67           0 :                 nCount--; nDone++;
      68           0 :                 nStartPos = previousCellIndex[nStartPos - 1];
      69             :             }
      70             :         } else
      71           0 :             nStartPos = 0;
      72             :     } else { // for BS to delete one char.
      73           0 :         nDone = (nStartPos > nCount) ? nCount : nStartPos;
      74           0 :         nStartPos -= nDone;
      75             :     }
      76             : 
      77           0 :     return nStartPos;
      78             : }
      79             : 
      80           0 : 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)
      84             : {
      85           0 :     sal_Int32 len = Text.getLength();
      86           0 :     if (nCharacterIteratorMode == CharacterIteratorMode::SKIPCELL ) {
      87           0 :         nDone = 0;
      88           0 :         if (nStartPos < len) {
      89           0 :             makeIndex(Text, nStartPos);
      90             : 
      91           0 :             if (nextCellIndex[nStartPos] == 0) // not a CTL character
      92             :                 return BreakIterator_Unicode::nextCharacters(Text, nStartPos, rLocale,
      93           0 :                     nCharacterIteratorMode, nCount, nDone);
      94           0 :             else while (nCount > 0 && nextCellIndex[nStartPos] > 0) {
      95           0 :                 nCount--; nDone++;
      96           0 :                 nStartPos = nextCellIndex[nStartPos];
      97             :             }
      98             :         } else
      99           0 :             nStartPos = len;
     100             :     } else {
     101           0 :         nDone = (len - nStartPos > nCount) ? nCount : len - nStartPos;
     102           0 :         nStartPos += nDone;
     103             :     }
     104             : 
     105           0 :     return nStartPos;
     106             : }
     107             : 
     108             : // This method should be overwritten by derived language specific class.
     109           0 : void SAL_CALL BreakIterator_CTL::makeIndex(const OUString& /*text*/, sal_Int32 /*pos*/)
     110             :     throw(RuntimeException)
     111             : {
     112           0 :     throw RuntimeException();
     113             : }
     114             : 
     115             : // Make sure line is broken on cell boundary if we implement cell iterator.
     116           0 : 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)
     121             : {
     122             :     LineBreakResults lbr = BreakIterator_Unicode::getLineBreak(Text, nStartPos,
     123           0 :                     rLocale, nMinBreakPos, hOptions, bOptions );
     124           0 :     if (lbr.breakIndex < Text.getLength()) {
     125           0 :         makeIndex(Text, lbr.breakIndex);
     126           0 :         lbr.breakIndex = previousCellIndex[ lbr.breakIndex ];
     127             :     }
     128           0 :     return lbr;
     129             : }
     130             : 
     131             : } } } }
     132             : 
     133             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11