Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / i18npool / inc / breakiterator_unicode.hxx
blob41831c676f28455586801bc4e71b30825199f9cd
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 <unicode/utext.h>
26 #include <memory>
27 #include <unordered_map>
29 namespace i18npool {
31 #define LOAD_CHARACTER_BREAKITERATOR 0
32 #define LOAD_WORD_BREAKITERATOR 1
33 #define LOAD_SENTENCE_BREAKITERATOR 2
34 #define LOAD_LINE_BREAKITERATOR 3
37 // class BreakIterator_Unicode
39 class BreakIterator_Unicode : public BreakIteratorImpl
41 public:
42 BreakIterator_Unicode();
43 virtual ~BreakIterator_Unicode() override;
45 virtual sal_Int32 SAL_CALL previousCharacters( const OUString& Text, sal_Int32 nStartPos,
46 const css::lang::Locale& nLocale, sal_Int16 nCharacterIteratorMode, sal_Int32 nCount,
47 sal_Int32& nDone ) override;
48 virtual sal_Int32 SAL_CALL nextCharacters( const OUString& Text, sal_Int32 nStartPos,
49 const css::lang::Locale& rLocale, sal_Int16 nCharacterIteratorMode, sal_Int32 nCount,
50 sal_Int32& nDone ) override;
52 virtual css::i18n::Boundary SAL_CALL previousWord( const OUString& Text, sal_Int32 nStartPos,
53 const css::lang::Locale& nLocale, sal_Int16 WordType) override;
54 virtual css::i18n::Boundary SAL_CALL nextWord( const OUString& Text, sal_Int32 nStartPos,
55 const css::lang::Locale& nLocale, sal_Int16 WordType) override;
56 virtual css::i18n::Boundary SAL_CALL getWordBoundary( const OUString& Text, sal_Int32 nPos,
57 const css::lang::Locale& nLocale, sal_Int16 WordType, sal_Bool bDirection ) override;
59 virtual sal_Int32 SAL_CALL beginOfSentence( const OUString& Text, sal_Int32 nStartPos,
60 const css::lang::Locale& nLocale ) override;
61 virtual sal_Int32 SAL_CALL endOfSentence( const OUString& Text, sal_Int32 nStartPos,
62 const css::lang::Locale& nLocale ) override;
64 virtual css::i18n::LineBreakResults SAL_CALL getLineBreak( const OUString& Text, sal_Int32 nStartPos,
65 const css::lang::Locale& nLocale, sal_Int32 nMinBreakPos,
66 const css::i18n::LineBreakHyphenationOptions& hOptions,
67 const css::i18n::LineBreakUserOptions& bOptions ) override;
69 //XServiceInfo
70 virtual OUString SAL_CALL getImplementationName() override;
71 virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
72 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
74 protected:
75 const sal_Char *cBreakIterator, *lineRule;
77 /** Used as map value. */
78 struct BI_ValueData
80 OUString maICUText;
81 UText* mpUt;
82 std::shared_ptr< icu::BreakIterator > mpBreakIterator;
84 BI_ValueData() : mpUt(nullptr)
87 ~BI_ValueData()
89 utext_close(mpUt);
93 struct BI_Data
95 std::shared_ptr< BI_ValueData > mpValue;
96 OString maBIMapKey;
97 } character, sentence, line, *icuBI;
98 BI_Data words[4]; // 4 is css::i18n::WordType enumeration size
100 /// @throws css::uno::RuntimeException
101 void loadICUBreakIterator(const css::lang::Locale& rLocale,
102 sal_Int16 rBreakType, sal_Int16 rWordType, const sal_Char* name, const OUString& rText);
104 public:
105 typedef std::unordered_map< OString, std::shared_ptr< BI_ValueData > > BIMap;
110 #endif
112 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */