LCOV - code coverage report
Current view: top level - i18npool/source/breakiterator - breakiterator_cjk.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 19 75 25.3 %
Date: 2012-08-25 Functions: 5 17 29.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 13 114 11.4 %

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

Generated by: LCOV version 1.10