LCOV - code coverage report
Current view: top level - i18npool/source/breakiterator - breakiterator_cjk.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 46 75 61.3 %
Date: 2015-06-13 12:38:46 Functions: 12 17 70.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             : #include <breakiterator_cjk.hxx>
      21             : #include <localedata.hxx>
      22             : #include <i18nutil/unicode.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             : //      class BreakIterator_CJK
      31             : //      ----------------------------------------------------;
      32             : 
      33         603 : BreakIterator_CJK::BreakIterator_CJK() :
      34             :     dict( NULL ),
      35         603 :     hangingCharacters()
      36             : {
      37         603 :     cBreakIterator = "com.sun.star.i18n.BreakIterator_CJK";
      38         603 : }
      39             : 
      40             : Boundary SAL_CALL
      41           0 : BreakIterator_CJK::previousWord(const OUString& text, sal_Int32 anyPos,
      42             :         const lang::Locale& nLocale, sal_Int16 wordType) throw(RuntimeException, std::exception)
      43             : {
      44           0 :     if (dict) {
      45           0 :         result = dict->previousWord(text, anyPos, wordType);
      46             :         // #109813# for non-CJK, single character word, fallback to ICU breakiterator.
      47           0 :         if (result.endPos - result.startPos != 1 ||
      48           0 :                 getScriptType(text, result.startPos) == ScriptType::ASIAN)
      49           0 :             return result;
      50           0 :         result = BreakIterator_Unicode::getWordBoundary(text, result.startPos, nLocale, wordType, true);
      51           0 :         if (result.endPos < anyPos)
      52           0 :             return result;
      53             :     }
      54           0 :     return BreakIterator_Unicode::previousWord(text, anyPos, nLocale, wordType);
      55             : }
      56             : 
      57             : Boundary SAL_CALL
      58           0 : BreakIterator_CJK::nextWord(const OUString& text, sal_Int32 anyPos,
      59             :         const lang::Locale& nLocale, sal_Int16 wordType) throw(RuntimeException, std::exception)
      60             : {
      61           0 :     if (dict) {
      62           0 :         result = dict->nextWord(text, anyPos, wordType);
      63             :         // #109813# for non-CJK, single character word, fallback to ICU breakiterator.
      64           0 :         if (result.endPos - result.startPos != 1 ||
      65           0 :                 getScriptType(text, result.startPos) == ScriptType::ASIAN)
      66           0 :             return result;
      67           0 :         result = BreakIterator_Unicode::getWordBoundary(text, result.startPos, nLocale, wordType, true);
      68           0 :         if (result.startPos > anyPos)
      69           0 :             return result;
      70             :     }
      71           0 :     return BreakIterator_Unicode::nextWord(text, anyPos, nLocale, wordType);
      72             : }
      73             : 
      74             : Boundary SAL_CALL
      75          51 : BreakIterator_CJK::getWordBoundary( const OUString& text, sal_Int32 anyPos,
      76             :         const lang::Locale& nLocale, sal_Int16 wordType, sal_Bool bDirection )
      77             :         throw(RuntimeException, std::exception)
      78             : {
      79          51 :     if (dict) {
      80          51 :         result = dict->getWordBoundary(text, anyPos, wordType, bDirection);
      81             :         // #109813# for non-CJK, single character word, fallback to ICU breakiterator.
      82          86 :         if (result.endPos - result.startPos != 1 ||
      83          35 :                 getScriptType(text, result.startPos) == ScriptType::ASIAN)
      84          51 :             return result;
      85             :     }
      86           0 :     return BreakIterator_Unicode::getWordBoundary(text, anyPos, nLocale, wordType, bDirection);
      87             : }
      88             : 
      89           4 : LineBreakResults SAL_CALL BreakIterator_CJK::getLineBreak(
      90             :         const OUString& Text, sal_Int32 nStartPos,
      91             :         const lang::Locale& /*rLocale*/, sal_Int32 /*nMinBreakPos*/,
      92             :         const LineBreakHyphenationOptions& /*hOptions*/,
      93             :         const LineBreakUserOptions& bOptions ) throw(RuntimeException, std::exception)
      94             : {
      95           4 :     LineBreakResults lbr;
      96             : 
      97           8 :     if (bOptions.allowPunctuationOutsideMargin &&
      98           4 :             hangingCharacters.indexOf(Text[nStartPos]) != -1 &&
      99           0 :             (Text.iterateCodePoints( &nStartPos, 1), nStartPos == Text.getLength())) {
     100             :         ; // do nothing
     101           4 :     } else if (bOptions.applyForbiddenRules && 0 < nStartPos && nStartPos < Text.getLength()) {
     102          12 :         while (nStartPos > 0 &&
     103           8 :                 (bOptions.forbiddenBeginCharacters.indexOf(Text[nStartPos]) != -1 ||
     104           4 :                  bOptions.forbiddenEndCharacters.indexOf(Text[nStartPos-1]) != -1))
     105           0 :             Text.iterateCodePoints( &nStartPos, -1);
     106             :     }
     107             : 
     108           4 :     lbr.breakIndex = nStartPos;
     109           4 :     lbr.breakType = BreakType::WORDBOUNDARY;
     110           4 :     return lbr;
     111             : }
     112             : 
     113             : #define LOCALE(language, country) lang::Locale(language, country, OUString())
     114             : //      ----------------------------------------------------
     115             : //      class BreakIterator_zh
     116             : //      ----------------------------------------------------;
     117          60 : BreakIterator_zh::BreakIterator_zh()
     118             : {
     119          60 :     dict = new xdictionary("zh");
     120          60 :     hangingCharacters = LocaleDataImpl().getHangingCharacters(LOCALE("zh", "CN"));
     121          60 :     cBreakIterator = "com.sun.star.i18n.BreakIterator_zh";
     122          60 : }
     123             : 
     124         180 : BreakIterator_zh::~BreakIterator_zh()
     125             : {
     126          60 :     delete dict;
     127         120 : }
     128             : 
     129             : //      ----------------------------------------------------
     130             : //      class BreakIterator_zh_TW
     131             : //      ----------------------------------------------------;
     132         541 : BreakIterator_zh_TW::BreakIterator_zh_TW()
     133             : {
     134         541 :     dict = new xdictionary("zh");
     135         541 :     hangingCharacters = LocaleDataImpl().getHangingCharacters(LOCALE("zh", "TW"));
     136         541 :     cBreakIterator = "com.sun.star.i18n.BreakIterator_zh_TW";
     137         541 : }
     138             : 
     139        1623 : BreakIterator_zh_TW::~BreakIterator_zh_TW()
     140             : {
     141         541 :     delete dict;
     142        1082 : }
     143             : 
     144             : //      ----------------------------------------------------
     145             : //      class BreakIterator_ja
     146             : //      ----------------------------------------------------;
     147           2 : BreakIterator_ja::BreakIterator_ja()
     148             : {
     149           2 :     dict = new xdictionary("ja");
     150           2 :     dict->setJapaneseWordBreak();
     151           2 :     hangingCharacters = LocaleDataImpl().getHangingCharacters(LOCALE("ja", "JP"));
     152           2 :     cBreakIterator = "com.sun.star.i18n.BreakIterator_ja";
     153           2 : }
     154             : 
     155           6 : BreakIterator_ja::~BreakIterator_ja()
     156             : {
     157           2 :     delete dict;
     158           4 : }
     159             : 
     160             : //      ----------------------------------------------------
     161             : //      class BreakIterator_ko
     162             : //      ----------------------------------------------------;
     163           0 : BreakIterator_ko::BreakIterator_ko()
     164             : {
     165           0 :     hangingCharacters = LocaleDataImpl().getHangingCharacters(LOCALE("ko", "KR"));
     166           0 :     cBreakIterator = "com.sun.star.i18n.BreakIterator_ko";
     167           0 : }
     168             : 
     169           0 : BreakIterator_ko::~BreakIterator_ko()
     170             : {
     171           0 : }
     172             : 
     173             : } } } }
     174             : 
     175             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11