LCOV - code coverage report
Current view: top level - include/unotools - charclass.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 15 22 68.2 %
Date: 2014-04-11 Functions: 5 7 71.4 %
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 <unotools/unotoolsdllapi.h>
      21             : 
      22             : #ifndef INCLUDED_UNOTOOLS_CHARCLASS_HXX
      23             : #define INCLUDED_UNOTOOLS_CHARCLASS_HXX
      24             : 
      25             : #include <boost/noncopyable.hpp>
      26             : #include <i18nlangtag/languagetag.hxx>
      27             : #include <com/sun/star/i18n/KCharacterType.hpp>
      28             : #include <com/sun/star/i18n/KParseTokens.hpp>
      29             : #include <com/sun/star/i18n/KParseType.hpp>
      30             : #include <com/sun/star/i18n/ParseResult.hpp>
      31             : #include <com/sun/star/i18n/XCharacterClassification.hpp>
      32             : #include <osl/mutex.hxx>
      33             : #include <rtl/character.hxx>
      34             : 
      35             : namespace com { namespace sun { namespace star {
      36             :     namespace uno {
      37             :         class XComponentContext;
      38             :     }
      39             : }}}
      40             : 
      41             : const sal_Int32 nCharClassAlphaType =
      42             :     ::com::sun::star::i18n::KCharacterType::UPPER |
      43             :     ::com::sun::star::i18n::KCharacterType::LOWER |
      44             :     ::com::sun::star::i18n::KCharacterType::TITLE_CASE;
      45             : 
      46             : const sal_Int32 nCharClassAlphaTypeMask =
      47             :     nCharClassAlphaType |
      48             :     ::com::sun::star::i18n::KCharacterType::PRINTABLE |
      49             :     ::com::sun::star::i18n::KCharacterType::BASE_FORM;
      50             : 
      51             : const sal_Int32 nCharClassLetterType =
      52             :     nCharClassAlphaType |
      53             :     ::com::sun::star::i18n::KCharacterType::LETTER;
      54             : 
      55             : const sal_Int32 nCharClassLetterTypeMask =
      56             :     nCharClassAlphaTypeMask |
      57             :     ::com::sun::star::i18n::KCharacterType::LETTER;
      58             : 
      59             : const sal_Int32 nCharClassNumericType =
      60             :     ::com::sun::star::i18n::KCharacterType::DIGIT;
      61             : 
      62             : const sal_Int32 nCharClassNumericTypeMask =
      63             :     nCharClassNumericType |
      64             :     ::com::sun::star::i18n::KCharacterType::PRINTABLE |
      65             :     ::com::sun::star::i18n::KCharacterType::BASE_FORM;
      66             : 
      67             : class UNOTOOLS_DLLPUBLIC CharClass : private boost::noncopyable
      68             : {
      69             :     LanguageTag                 maLanguageTag;
      70             :     ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XCharacterClassification >    xCC;
      71             :     mutable ::osl::Mutex        aMutex;
      72             : 
      73             : public:
      74             :     /// Preferred ctor with service manager specified
      75             :     CharClass(
      76             :         const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > & rxContext,
      77             :         const LanguageTag& rLanguageTag );
      78             : 
      79             :     /// Depricated ctor, tries to get a process service manager or to load the
      80             :     /// library directly.
      81             :     CharClass( const LanguageTag& rLanguageTag );
      82             : 
      83             :     ~CharClass();
      84             : 
      85             :     /// set a new Locale
      86             :     void setLanguageTag( const LanguageTag& rLanguageTag );
      87             : 
      88             :     /// get current Locale
      89             :     const LanguageTag& getLanguageTag() const;
      90             : 
      91             :     /// isdigit() on ascii values
      92             :     SAL_DEPRECATED("Use rtl::isAsciiDigit instead")
      93             :     static inline bool isAsciiDigit( sal_Unicode c )
      94             :     {
      95             :         return rtl::isAsciiDigit( c );
      96             :     }
      97             : 
      98             :     /// isalpha() on ascii values
      99             :     SAL_DEPRECATED("Use rtl::isAsciiAlpha instead")
     100             :     static inline bool isAsciiAlpha( sal_Unicode c )
     101             :     {
     102             :         return rtl::isAsciiAlpha( c );
     103             :     }
     104             : 
     105             :     /// isalnum() on ascii values
     106             :     SAL_DEPRECATED("Use rtl::isAsciiAlphanumeric instead")
     107             :     static inline bool isAsciiAlphaNumeric( sal_Unicode c )
     108             :     {
     109             :         return rtl::isAsciiAlphanumeric( c );
     110             :     }
     111             : 
     112             :     /// isdigit() on ascii values of entire string
     113             :     static bool isAsciiNumeric( const OUString& rStr );
     114             : 
     115             :     /// isalpha() on ascii values of entire string
     116             :     static bool isAsciiAlpha( const OUString& rStr );
     117             : 
     118             :     /// isalnum() on ascii values of entire string
     119             :     static bool isAsciiAlphaNumeric( const OUString& rStr );
     120             : 
     121             :     /// whether type is pure alpha or not, e.g. return of getStringType
     122             :     static inline bool isAlphaType( sal_Int32 nType )
     123             :     {
     124             :         return ((nType & nCharClassAlphaType) != 0) &&
     125             :             ((nType & ~(nCharClassAlphaTypeMask)) == 0);
     126             :     }
     127             : 
     128             :     /// whether type is pure numeric or not, e.g. return of getStringType
     129          40 :     static inline bool isNumericType( sal_Int32 nType )
     130             :     {
     131          40 :         return ((nType & nCharClassNumericType) != 0) &&
     132          40 :             ((nType & ~(nCharClassNumericTypeMask)) == 0);
     133             :     }
     134             : 
     135             :     /// whether type is pure alphanumeric or not, e.g. return of getStringType
     136           0 :     static inline bool isAlphaNumericType( sal_Int32 nType )
     137             :     {
     138           0 :         return ((nType & (nCharClassAlphaType |
     139           0 :             nCharClassNumericType)) != 0) &&
     140           0 :             ((nType & ~(nCharClassAlphaTypeMask |
     141           0 :             nCharClassNumericTypeMask)) == 0);
     142             :     }
     143             : 
     144             :     /// whether type is pure letter or not, e.g. return of getStringType
     145          14 :     static inline bool isLetterType( sal_Int32 nType )
     146             :     {
     147          28 :         return ((nType & nCharClassLetterType) != 0) &&
     148          28 :             ((nType & ~(nCharClassLetterTypeMask)) == 0);
     149             :     }
     150             : 
     151             :     /// whether type is pure letternumeric or not, e.g. return of getStringType
     152       11017 :     static inline bool isLetterNumericType( sal_Int32 nType )
     153             :     {
     154       11017 :         return ((nType & (nCharClassLetterType |
     155       20570 :             nCharClassNumericType)) != 0) &&
     156        9553 :             ((nType & ~(nCharClassLetterTypeMask |
     157       11017 :             nCharClassNumericTypeMask)) == 0);
     158             :     }
     159             : 
     160             :     // Wrapper implementations of class CharacterClassification
     161             : 
     162             :     OUString uppercase( const OUString& rStr, sal_Int32 nPos, sal_Int32 nCount ) const;
     163             :     OUString lowercase( const OUString& rStr, sal_Int32 nPos, sal_Int32 nCount ) const;
     164             :     OUString titlecase( const OUString& rStr, sal_Int32 nPos, sal_Int32 nCount ) const;
     165             : 
     166      473187 :     OUString uppercase( const OUString& _rStr ) const
     167             :     {
     168      473187 :         return uppercase(_rStr, 0, _rStr.getLength());
     169             :     }
     170       30823 :     OUString lowercase( const OUString& _rStr ) const
     171             :     {
     172       30823 :         return lowercase(_rStr, 0, _rStr.getLength());
     173             :     }
     174           0 :     OUString titlecase( const OUString& _rStr ) const
     175             :     {
     176           0 :         return titlecase(_rStr, 0, _rStr.getLength());
     177             :     }
     178             : 
     179             :     sal_Int16 getType( const OUString& rStr, sal_Int32 nPos ) const;
     180             :     sal_Int16 getCharacterDirection( const OUString& rStr, sal_Int32 nPos ) const;
     181             :     sal_Int16 getScript( const OUString& rStr, sal_Int32 nPos ) const;
     182             :     sal_Int32 getCharacterType( const OUString& rStr, sal_Int32 nPos ) const;
     183             :     sal_Int32 getStringType( const OUString& rStr, sal_Int32 nPos, sal_Int32 nCount ) const;
     184             : 
     185             :     ::com::sun::star::i18n::ParseResult parseAnyToken(
     186             :                                     const OUString& rStr,
     187             :                                     sal_Int32 nPos,
     188             :                                     sal_Int32 nStartCharFlags,
     189             :                                     const OUString& userDefinedCharactersStart,
     190             :                                     sal_Int32 nContCharFlags,
     191             :                                     const OUString& userDefinedCharactersCont ) const;
     192             : 
     193             :     ::com::sun::star::i18n::ParseResult parsePredefinedToken(
     194             :                                     sal_Int32 nTokenType,
     195             :                                     const OUString& rStr,
     196             :                                     sal_Int32 nPos,
     197             :                                     sal_Int32 nStartCharFlags,
     198             :                                     const OUString& userDefinedCharactersStart,
     199             :                                     sal_Int32 nContCharFlags,
     200             :                                     const OUString& userDefinedCharactersCont ) const;
     201             : 
     202             :     // Functionality of class International methods
     203             : 
     204             :     bool isAlpha( const OUString& rStr, sal_Int32 nPos ) const;
     205             :     bool isLetter( const OUString& rStr, sal_Int32 nPos ) const;
     206             :     bool isDigit( const OUString& rStr, sal_Int32 nPos ) const;
     207             :     bool isAlphaNumeric( const OUString& rStr, sal_Int32 nPos ) const;
     208             :     bool isLetterNumeric( const OUString& rStr, sal_Int32 nPos ) const;
     209             :     bool isAlpha( const OUString& rStr ) const;
     210             :     bool isLetter( const OUString& rStr ) const;
     211             :     bool isNumeric( const OUString& rStr ) const;
     212             :     bool isAlphaNumeric( const OUString& rStr ) const;
     213             :     bool isLetterNumeric( const OUString& rStr ) const;
     214             : 
     215             : private:
     216             : 
     217             :     const ::com::sun::star::lang::Locale &  getMyLocale() const;
     218             : };
     219             : 
     220             : #endif // INCLUDED_UNOTOOLS_CHARCLASS_HXX
     221             : 
     222             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10