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

Generated by: LCOV version 1.10