LCOV - code coverage report
Current view: top level - libreoffice/sw/inc - breakit.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 21 25 84.0 %
Date: 2012-12-27 Functions: 6 7 85.7 %
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             : #ifndef _BREAKIT_HXX
      21             : #define _BREAKIT_HXX
      22             : 
      23             : #include <boost/noncopyable.hpp>
      24             : #include <com/sun/star/uno/Reference.h>
      25             : #include <com/sun/star/uno/XComponentContext.hpp>
      26             : #include <com/sun/star/i18n/XBreakIterator.hpp>
      27             : #include <com/sun/star/i18n/XScriptTypeDetector.hpp>
      28             : #include <com/sun/star/i18n/ForbiddenCharacters.hpp>
      29             : #include <i18npool/languagetag.hxx>
      30             : #include <swdllapi.h>
      31             : 
      32             : /*************************************************************************
      33             :  *                      class SwBreakIt
      34             :  *************************************************************************/
      35             : 
      36             : 
      37             : class SW_DLLPUBLIC SwBreakIt : private ::boost::noncopyable
      38             : {
      39             :     com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > m_xContext;
      40             :     mutable com::sun::star::uno::Reference< com::sun::star::i18n::XBreakIterator > xBreak;
      41             : 
      42             :     LanguageTag * m_pLanguageTag;   ///< language tag of the current locale
      43             :     com::sun::star::i18n::ForbiddenCharacters * m_pForbidden;
      44             : 
      45             :     LanguageType aForbiddenLang; ///< language of the current forbiddenChar struct
      46             : 
      47             :     void _GetLocale( const LanguageType aLang );
      48             :     void _GetLocale( const LanguageTag& rLanguageTag );
      49             :     void _GetForbidden( const LanguageType  aLang );
      50             : 
      51             :     void createBreakIterator() const;
      52             : 
      53             :     // private (see @ _Create, _Delete).
      54             :     explicit SwBreakIt(
      55             :         const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > & rxContext);
      56             :     ~SwBreakIt();
      57             : 
      58             : public:
      59             :     // private (see @ source/core/bastyp/init.cxx).
      60             :     static void _Create(
      61             :         const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > & rxContext);
      62             :     static void _Delete();
      63             : 
      64             : public:
      65             :     static SwBreakIt * Get();
      66             : 
      67       20699 :     com::sun::star::uno::Reference< com::sun::star::i18n::XBreakIterator > GetBreakIter()
      68             :     {
      69       20699 :         createBreakIterator();
      70       20699 :         return xBreak;
      71             :     }
      72             : 
      73        5386 :     const com::sun::star::lang::Locale& GetLocale( const LanguageType aLang )
      74             :     {
      75        5386 :         if( !m_pLanguageTag || m_pLanguageTag->getLanguageType() != aLang )
      76         296 :             _GetLocale( aLang );
      77        5386 :         return m_pLanguageTag->getLocale();
      78             :     }
      79             : 
      80           0 :     const com::sun::star::lang::Locale& GetLocale( const LanguageTag& rLanguageTag )
      81             :     {
      82             :         // Use LanguageType comparison instead of LanguageTag::operator!=()
      83             :         // because here the LanguageTag is already a known LanguageType value
      84             :         // assigned, so LanguageTag does not need to convert to BCP47 for
      85             :         // comparison.
      86           0 :         if( !m_pLanguageTag || m_pLanguageTag->getLanguageType() != rLanguageTag.getLanguageType() )
      87           0 :             _GetLocale( rLanguageTag );
      88           0 :         return m_pLanguageTag->getLocale();
      89             :     }
      90             : 
      91           9 :     const LanguageTag& GetLanguageTag( const LanguageType aLang )
      92             :     {
      93           9 :         if( !m_pLanguageTag || m_pLanguageTag->getLanguageType() != aLang )
      94           3 :             _GetLocale( aLang );
      95           9 :         return *m_pLanguageTag;
      96             :     }
      97             : 
      98           8 :     const LanguageTag& GetLanguageTag( const LanguageTag& rLanguageTag )
      99             :     {
     100             :         // Use LanguageType comparison instead of LanguageTag::operator!=()
     101             :         // because here the LanguageTag is already a known LanguageType value
     102             :         // assigned, so LanguageTag does not need to convert to BCP47 for
     103             :         // comparison.
     104           8 :         if( !m_pLanguageTag || m_pLanguageTag->getLanguageType() != rLanguageTag.getLanguageType() )
     105           4 :             _GetLocale( rLanguageTag );
     106           8 :         return *m_pLanguageTag;
     107             :     }
     108             : 
     109          78 :     const com::sun::star::i18n::ForbiddenCharacters& GetForbidden( const LanguageType aLang )
     110             :     {
     111          78 :         if( !m_pForbidden || aForbiddenLang != aLang )
     112           9 :             _GetForbidden( aLang );
     113          78 :         return *m_pForbidden;
     114             :     }
     115             : 
     116             :     sal_uInt16 GetRealScriptOfText( const rtl::OUString& rTxt, sal_Int32 nPos ) const;
     117             :     sal_uInt16 GetAllScriptsOfText( const rtl::OUString& rTxt ) const;
     118             : 
     119             :     sal_Int32 getGraphemeCount(const rtl::OUString& rStr,
     120             :         sal_Int32 nStart, sal_Int32 nEnd) const;
     121         692 :     sal_Int32 getGraphemeCount(const rtl::OUString& rStr) const
     122             :     {
     123         692 :         return getGraphemeCount(rStr, 0, rStr.getLength());
     124             :     }
     125             : };
     126             : 
     127             : #define SW_BREAKITER()  SwBreakIt::Get()
     128             : 
     129             : // @@@ backward compatibility @@@
     130             : SW_DLLPUBLIC extern SwBreakIt* pBreakIt;
     131             : 
     132             : #endif
     133             : 
     134             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10