cid#1640468 Dereference after null check
[LibreOffice.git] / i18npool / inc / breakiteratorImpl.hxx
bloba2700b7a9bf91b6038f54adac7e1d5cafe9e9248
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 #pragma once
21 #include <com/sun/star/lang/XServiceInfo.hpp>
22 #include <com/sun/star/i18n/XBreakIterator.hpp>
23 #include <cppuhelper/implbase.hxx>
25 #include <utility>
26 #include <vector>
28 namespace com::sun::star::uno { class XComponentContext; }
30 namespace i18npool {
34 class BreakIteratorImpl : public cppu::WeakImplHelper
36 css::i18n::XBreakIterator,
37 css::lang::XServiceInfo
40 public:
41 BreakIteratorImpl( const css::uno::Reference < css::uno::XComponentContext >& rxContext );
42 BreakIteratorImpl();
43 virtual ~BreakIteratorImpl() override;
45 virtual sal_Int32 SAL_CALL nextCharacters( const OUString& Text, sal_Int32 nStartPos,
46 const css::lang::Locale& rLocale, sal_Int16 nCharacterIteratorMode, sal_Int32 nCount,
47 sal_Int32& nDone ) override;
48 virtual sal_Int32 SAL_CALL previousCharacters( const OUString& Text, sal_Int32 nStartPos,
49 const css::lang::Locale& nLocale, 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_Bool SAL_CALL isBeginWord( const OUString& Text, sal_Int32 nPos,
60 const css::lang::Locale& nLocale, sal_Int16 WordType ) override;
61 virtual sal_Bool SAL_CALL isEndWord( const OUString& Text, sal_Int32 nPos,
62 const css::lang::Locale& nLocale, sal_Int16 WordType ) override;
63 virtual sal_Int16 SAL_CALL getWordType( const OUString& Text, sal_Int32 nPos,
64 const css::lang::Locale& nLocale ) override;
66 virtual sal_Int32 SAL_CALL beginOfSentence( const OUString& Text, sal_Int32 nStartPos,
67 const css::lang::Locale& nLocale ) override;
68 virtual sal_Int32 SAL_CALL endOfSentence( const OUString& Text, sal_Int32 nStartPos,
69 const css::lang::Locale& nLocale ) override;
71 virtual css::i18n::LineBreakResults SAL_CALL getLineBreak( const OUString& Text, sal_Int32 nStartPos,
72 const css::lang::Locale& nLocale, sal_Int32 nMinBreakPos,
73 const css::i18n::LineBreakHyphenationOptions& hOptions,
74 const css::i18n::LineBreakUserOptions& bOptions ) override;
76 virtual sal_Int16 SAL_CALL getScriptType( const OUString& Text, sal_Int32 nPos ) override;
77 virtual sal_Int32 SAL_CALL beginOfScript( const OUString& Text, sal_Int32 nStartPos,
78 sal_Int16 ScriptType ) override;
79 virtual sal_Int32 SAL_CALL endOfScript( const OUString& Text, sal_Int32 nStartPos,
80 sal_Int16 ScriptType ) override;
81 virtual sal_Int32 SAL_CALL previousScript( const OUString& Text, sal_Int32 nStartPos,
82 sal_Int16 ScriptType ) override;
83 virtual sal_Int32 SAL_CALL nextScript( const OUString& Text, sal_Int32 nStartPos,
84 sal_Int16 ScriptType ) override;
86 virtual sal_Int32 SAL_CALL beginOfCharBlock( const OUString& Text, sal_Int32 nStartPos,
87 const css::lang::Locale& nLocale, sal_Int16 CharType ) override;
88 virtual sal_Int32 SAL_CALL endOfCharBlock( const OUString& Text, sal_Int32 nStartPos,
89 const css::lang::Locale& nLocale, sal_Int16 CharType ) override;
90 virtual sal_Int32 SAL_CALL previousCharBlock( const OUString& Text, sal_Int32 nStartPos,
91 const css::lang::Locale& nLocale, sal_Int16 CharType ) override;
92 virtual sal_Int32 SAL_CALL nextCharBlock( const OUString& Text, sal_Int32 nStartPos,
93 const css::lang::Locale& nLocale, sal_Int16 CharType ) override;
95 //XServiceInfo
96 virtual OUString SAL_CALL getImplementationName() override;
97 virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
98 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
100 static sal_Int16 getScriptClass(sal_uInt32 currentChar);
101 protected:
102 css::i18n::Boundary result; // for word break iterator
104 private:
106 struct lookupTableItem {
107 lookupTableItem(css::lang::Locale _aLocale, css::uno::Reference < XBreakIterator > _xBI) : aLocale(std::move(_aLocale)), xBI(std::move(_xBI)) {};
108 css::lang::Locale aLocale;
109 css::uno::Reference < XBreakIterator > xBI;
111 std::vector<lookupTableItem> lookupTable;
112 css::lang::Locale aLocale;
113 css::uno::Reference < XBreakIterator > xBI;
114 css::uno::Reference < css::uno::XComponentContext > m_xContext;
116 /// @throws css::uno::RuntimeException
117 bool createLocaleSpecificBreakIterator( const OUString& aLocaleName );
118 /// @throws css::uno::RuntimeException
119 const css::uno::Reference < XBreakIterator > & getLocaleSpecificBreakIterator( const css::lang::Locale& rLocale );
123 } // i18npool
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */