LibreOffice Module i18npool (master)  1
cclass_unicode.hxx
Go to the documentation of this file.
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 #ifndef INCLUDED_I18NPOOL_INC_CCLASS_UNICODE_HXX
20 #define INCLUDED_I18NPOOL_INC_CCLASS_UNICODE_HXX
21 
22 #include <com/sun/star/i18n/XCharacterClassification.hpp>
23 #include <cppuhelper/implbase.hxx>
24 #include <com/sun/star/lang/XServiceInfo.hpp>
25 #include <rtl/ref.hxx>
26 
27 #include <o3tl/typed_flags_set.hxx>
28 #include <memory>
29 
30 namespace com::sun::star::uno { class XComponentContext; }
31 namespace com::sun::star::i18n { class XNativeNumberSupplier; }
32 namespace com::sun::star::i18n { class XLocaleData5; }
33 namespace i18npool { class Transliteration_casemapping; }
34 
35 
37 enum class ParserFlags : sal_uInt32 {
38  ILLEGAL = 0x00000000,
39  CHAR = 0x00000001,
40  CHAR_BOOL = 0x00000002,
41  CHAR_WORD = 0x00000004,
42  CHAR_VALUE = 0x00000008,
43  CHAR_STRING = 0x00000010,
44  CHAR_DONTCARE = 0x00000020,
45  BOOL = 0x00000040,
46  WORD = 0x00000080,
47  WORD_SEP = 0x00000100,
48  VALUE = 0x00000200,
49  VALUE_SEP = 0x00000400,
50  VALUE_EXP = 0x00000800,
51  VALUE_SIGN = 0x00001000,
52  VALUE_EXP_VALUE = 0x00002000,
53  VALUE_DIGIT = 0x00004000,
54  NAME_SEP = 0x20000000,
55  STRING_SEP = 0x40000000,
56  EXCLUDED = 0x80000000,
57 };
58 namespace o3tl {
59  template<> struct typed_flags<ParserFlags> : is_typed_flags<ParserFlags, 0xe0007fff> {};
60 }
61 
62 
63 namespace i18npool {
64 
65 class cclass_Unicode final : public cppu::WeakImplHelper < css::i18n::XCharacterClassification, css::lang::XServiceInfo >
66 {
67 public:
68  cclass_Unicode(const css::uno::Reference < css::uno::XComponentContext >& rxContext );
69  virtual ~cclass_Unicode() override;
70 
71  virtual OUString SAL_CALL toUpper( const OUString& Text, sal_Int32 nPos, sal_Int32 nCount,
72  const css::lang::Locale& rLocale ) override;
73  virtual OUString SAL_CALL toLower( const OUString& Text, sal_Int32 nPos, sal_Int32 nCount,
74  const css::lang::Locale& rLocale ) override;
75  virtual OUString SAL_CALL toTitle( const OUString& Text, sal_Int32 nPos, sal_Int32 nCount,
76  const css::lang::Locale& rLocale ) override;
77  virtual sal_Int16 SAL_CALL getType( const OUString& Text, sal_Int32 nPos ) override;
78  virtual sal_Int16 SAL_CALL getCharacterDirection( const OUString& Text, sal_Int32 nPos ) override;
79  virtual sal_Int16 SAL_CALL getScript( const OUString& Text, sal_Int32 nPos ) override;
80  virtual sal_Int32 SAL_CALL getCharacterType( const OUString& text, sal_Int32 nPos,
81  const css::lang::Locale& rLocale ) override;
82  virtual sal_Int32 SAL_CALL getStringType( const OUString& text, sal_Int32 nPos, sal_Int32 nCount,
83  const css::lang::Locale& rLocale ) override;
84  virtual css::i18n::ParseResult SAL_CALL parseAnyToken( const OUString& Text, sal_Int32 nPos,
85  const css::lang::Locale& rLocale, sal_Int32 nStartCharFlags, const OUString& userDefinedCharactersStart,
86  sal_Int32 nContCharFlags, const OUString& userDefinedCharactersCont ) override;
87  virtual css::i18n::ParseResult SAL_CALL parsePredefinedToken( sal_Int32 nTokenType, const OUString& Text,
88  sal_Int32 nPos, const css::lang::Locale& rLocale, sal_Int32 nStartCharFlags,
89  const OUString& userDefinedCharactersStart, sal_Int32 nContCharFlags,
90  const OUString& userDefinedCharactersCont ) override;
91 
92  //XServiceInfo
93  virtual OUString SAL_CALL getImplementationName() override;
94  virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
95  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
96 
97 private:
99 
100 // --- parser specific (implemented in cclass_unicode_parser.cxx) ---
101 
103  {
104  ssGetChar, // initial state; -> ssBounce, ssGetValue, ssRewindFromValue, ssGetWord, ssGetWordFirstChar, ssGetString, ssGetBool, ssStop
105  ssGetValue, // -> ssBounce, ssRewindFromValue, ssStopBack, ssGetWord
106  ssGetWord, // -> ssBounce, ssStop, ssStopBack
107  ssGetWordFirstChar, // -> ssBounce, ssGetWord, ssStop, ssStopBack
108  ssGetString, // -> ssBounce, ssStop
109  ssGetBool, // -> ssBounce, ssStop, ssStopBack
110  ssRewindFromValue, // -> ssBounce, ssGetValue, ssGetWord, ssGetWordFirstChar, ssGetString, ssGetBool, ssStop, ssIgnoreLeadingInRewind
111  ssIgnoreLeadingInRewind, // -> ssBounce, ssGetValue, ssRewindFromValue, ssGetWord, ssGetWordFirstChar, ssGetString, ssGetBool, ssStop
112  ssStopBack, // -> ssStop
113  ssBounce, // -> ssStopBack
115  };
116 
117  static const sal_uInt8 nDefCnt;
119  static const sal_Int32 pParseTokensType[];
120 
122  static const sal_Unicode* StrChr( const sal_Unicode* pStr, sal_uInt32 c );
123 
124 
125  css::uno::Reference < css::uno::XComponentContext > m_xContext;
126 
128  css::lang::Locale aParserLocale;
129  css::uno::Reference < css::i18n::XLocaleData5 > mxLocaleData;
130  css::uno::Reference < css::i18n::XNativeNumberSupplier > xNatNumSup;
131  OUString aStartChars;
132  OUString aContChars;
133  std::unique_ptr<ParserFlags[]> pTable;
134  std::unique_ptr<ParserFlags[]> pStart;
135  std::unique_ptr<ParserFlags[]> pCont;
136  sal_Int32 nStartTypes;
137  sal_Int32 nContTypes;
142 
144  static sal_Int32 getParseTokensType(sal_uInt32 c, bool isFirst);
145 
147  ParserFlags getFlags(sal_uInt32 c);
148 
150  ParserFlags getFlagsExtended(sal_uInt32 c) const;
151 
153  ParserFlags getStartCharsFlags( sal_uInt32 c );
154 
157 
159  void setupParserTable( const css::lang::Locale& rLocale, sal_Int32 startCharTokenType,
160  const OUString& userDefinedCharactersStart, sal_Int32 contCharTokenType,
161  const OUString& userDefinedCharactersCont );
162 
164  void initParserTable( const css::lang::Locale& rLocale, sal_Int32 startCharTokenType,
165  const OUString& userDefinedCharactersStart, sal_Int32 contCharTokenType,
166  const OUString& userDefinedCharactersCont );
167 
169  void destroyParserTable();
170 
172  void parseText( css::i18n::ParseResult& r, const OUString& rText, sal_Int32 nPos,
173  sal_Int32 nTokenType = 0xffffffff );
174 
176  void setupInternational( const css::lang::Locale& rLocale );
177 
179  static sal_Int32 getCharType( const OUString& Text, sal_Int32 *nPos, sal_Int32 increment);
180 
181 };
182 
183 }
184 
185 #endif
186 
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void destroyParserTable()
Destroy parser table.
virtual OUString SAL_CALL toLower(const OUString &Text, sal_Int32 nPos, sal_Int32 nCount, const css::lang::Locale &rLocale) override
void parseText(css::i18n::ParseResult &r, const OUString &rText, sal_Int32 nPos, sal_Int32 nTokenType=0xffffffff)
Parse a text.
static const sal_Unicode * StrChr(const sal_Unicode *pStr, sal_uInt32 c)
If and where c occurs in pStr.
css::uno::Reference< css::i18n::XNativeNumberSupplier > xNatNumSup
virtual sal_Int32 SAL_CALL getCharacterType(const OUString &text, sal_Int32 nPos, const css::lang::Locale &rLocale) override
ParserFlags getStartCharsFlags(sal_uInt32 c)
Access parser table flags for user defined start characters.
std::unique_ptr< ParserFlags[]> pStart
void setupInternational(const css::lang::Locale &rLocale)
Setup International class, new'ed only if different from existing.
css::lang::Locale aParserLocale
used for parser only
virtual ~cclass_Unicode() override
cclass_Unicode(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
static const sal_uInt8 nDefCnt
sal_uInt16 sal_Unicode
css::uno::Reference< css::i18n::XLocaleData5 > mxLocaleData
static sal_Int32 getParseTokensType(sal_uInt32 c, bool isFirst)
Get corresponding KParseTokens flag for a character.
const wchar_t *typedef BOOL
int nCount
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
std::unique_ptr< ParserFlags[]> pTable
static const sal_Int32 pParseTokensType[]
ParserFlags getFlagsExtended(sal_uInt32 c) const
Access parser flags via International and special definitions.
exports com.sun.star. text
virtual OUString SAL_CALL toTitle(const OUString &Text, sal_Int32 nPos, sal_Int32 nCount, const css::lang::Locale &rLocale) override
virtual sal_Int32 SAL_CALL getStringType(const OUString &text, sal_Int32 nPos, sal_Int32 nCount, const css::lang::Locale &rLocale) override
virtual css::i18n::ParseResult SAL_CALL parseAnyToken(const OUString &Text, sal_Int32 nPos, const css::lang::Locale &rLocale, sal_Int32 nStartCharFlags, const OUString &userDefinedCharactersStart, sal_Int32 nContCharFlags, const OUString &userDefinedCharactersCont) override
virtual sal_Int16 SAL_CALL getType(const OUString &Text, sal_Int32 nPos) override
virtual sal_Int16 SAL_CALL getCharacterDirection(const OUString &Text, sal_Int32 nPos) override
virtual css::i18n::ParseResult SAL_CALL parsePredefinedToken(sal_Int32 nTokenType, const OUString &Text, sal_Int32 nPos, const css::lang::Locale &rLocale, sal_Int32 nStartCharFlags, const OUString &userDefinedCharactersStart, sal_Int32 nContCharFlags, const OUString &userDefinedCharactersCont) override
unsigned char sal_Bool
ParserFlags getContCharsFlags(sal_Unicode c)
Access parser table flags for user defined continuation characters.
void initParserTable(const css::lang::Locale &rLocale, sal_Int32 startCharTokenType, const OUString &userDefinedCharactersStart, sal_Int32 contCharTokenType, const OUString &userDefinedCharactersCont)
Init parser table.
Constant values shared between i18npool and, for example, the number formatter.
virtual sal_Int16 SAL_CALL getScript(const OUString &Text, sal_Int32 nPos) override
unsigned short WORD
static sal_Int32 getCharType(const OUString &Text, sal_Int32 *nPos, sal_Int32 increment)
Implementation of getCharacterType() for one single character.
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
static const ParserFlags pDefaultParserTable[]
std::unique_ptr< ParserFlags[]> pCont
ParserFlags
Flag values of table.
unsigned char sal_uInt8
ParserFlags getFlags(sal_uInt32 c)
Access parser table flags.
virtual OUString SAL_CALL getImplementationName() override
void setupParserTable(const css::lang::Locale &rLocale, sal_Int32 startCharTokenType, const OUString &userDefinedCharactersStart, sal_Int32 contCharTokenType, const OUString &userDefinedCharactersCont)
Setup parser table. Calls initParserTable() only if needed.
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual OUString SAL_CALL toUpper(const OUString &Text, sal_Int32 nPos, sal_Int32 nCount, const css::lang::Locale &rLocale) override
sal_uInt16 nPos
rtl::Reference< Transliteration_casemapping > trans