Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / i18npool / inc / breakiterator_unicode.hxx
blobc9e644e31f429b476c77bddd4cf663cd0965d570
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_I18NPOOL_INC_BREAKITERATOR_UNICODE_HXX
20 #define INCLUDED_I18NPOOL_INC_BREAKITERATOR_UNICODE_HXX
22 #include <breakiteratorImpl.hxx>
24 #include <unicode/brkiter.h>
25 #include <memory>
26 #include <unordered_map>
28 namespace com { namespace sun { namespace star { namespace i18n {
30 #define LOAD_CHARACTER_BREAKITERATOR 0
31 #define LOAD_WORD_BREAKITERATOR 1
32 #define LOAD_SENTENCE_BREAKITERATOR 2
33 #define LOAD_LINE_BREAKITERATOR 3
36 // class BreakIterator_Unicode
38 class BreakIterator_Unicode : public BreakIteratorImpl
40 public:
41 BreakIterator_Unicode();
42 virtual ~BreakIterator_Unicode() override;
44 virtual sal_Int32 SAL_CALL previousCharacters( const OUString& Text, sal_Int32 nStartPos,
45 const css::lang::Locale& nLocale, sal_Int16 nCharacterIteratorMode, sal_Int32 nCount,
46 sal_Int32& nDone ) override;
47 virtual sal_Int32 SAL_CALL nextCharacters( const OUString& Text, sal_Int32 nStartPos,
48 const css::lang::Locale& rLocale, sal_Int16 nCharacterIteratorMode, sal_Int32 nCount,
49 sal_Int32& nDone ) override;
51 virtual Boundary SAL_CALL previousWord( const OUString& Text, sal_Int32 nStartPos,
52 const css::lang::Locale& nLocale, sal_Int16 WordType) override;
53 virtual Boundary SAL_CALL nextWord( const OUString& Text, sal_Int32 nStartPos,
54 const css::lang::Locale& nLocale, sal_Int16 WordType) override;
55 virtual Boundary SAL_CALL getWordBoundary( const OUString& Text, sal_Int32 nPos,
56 const css::lang::Locale& nLocale, sal_Int16 WordType, sal_Bool bDirection ) override;
58 virtual sal_Int32 SAL_CALL beginOfSentence( const OUString& Text, sal_Int32 nStartPos,
59 const css::lang::Locale& nLocale ) override;
60 virtual sal_Int32 SAL_CALL endOfSentence( const OUString& Text, sal_Int32 nStartPos,
61 const css::lang::Locale& nLocale ) override;
63 virtual LineBreakResults SAL_CALL getLineBreak( const OUString& Text, sal_Int32 nStartPos,
64 const css::lang::Locale& nLocale, sal_Int32 nMinBreakPos,
65 const LineBreakHyphenationOptions& hOptions, const LineBreakUserOptions& bOptions ) override;
67 //XServiceInfo
68 virtual OUString SAL_CALL getImplementationName() override;
69 virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
70 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
72 protected:
73 const sal_Char *cBreakIterator, *lineRule;
75 /** Used as map value. */
76 struct BI_ValueData
78 OUString maICUText;
79 UText* mpUt;
80 std::shared_ptr< icu::BreakIterator > mpBreakIterator;
82 BI_ValueData() : mpUt(nullptr)
85 ~BI_ValueData()
87 utext_close(mpUt);
91 struct BI_Data
93 std::shared_ptr< BI_ValueData > mpValue;
94 OString maBIMapKey;
95 } character, sentence, line, *icuBI;
96 BI_Data words[4]; // 4 is css::i18n::WordType enumeration size
98 /// @throws css::uno::RuntimeException
99 void SAL_CALL loadICUBreakIterator(const css::lang::Locale& rLocale,
100 sal_Int16 rBreakType, sal_Int16 rWordType, const sal_Char* name, const OUString& rText);
102 public:
103 typedef std::unordered_map< OString, std::shared_ptr< BI_ValueData >, OStringHash > BIMap;
106 } } } }
108 #endif
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */