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

Generated by: LCOV version 1.11