Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / sw / inc / breakit.hxx
blob1c6f9d5c7dbd59a7413243ec0500309e97c9ff3a
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 .
20 #ifndef INCLUDED_SW_INC_BREAKIT_HXX
21 #define INCLUDED_SW_INC_BREAKIT_HXX
23 #include <memory>
24 #include <com/sun/star/uno/Reference.h>
25 #include <com/sun/star/uno/XComponentContext.hpp>
26 #include <com/sun/star/i18n/XBreakIterator.hpp>
27 #include <com/sun/star/i18n/XScriptTypeDetector.hpp>
28 #include <com/sun/star/i18n/ForbiddenCharacters.hpp>
29 #include <i18nlangtag/languagetag.hxx>
30 #include <swdllapi.h>
32 enum class SvtScriptType;
34 class SW_DLLPUBLIC SwBreakIt
36 css::uno::Reference< css::uno::XComponentContext > m_xContext;
37 css::uno::Reference<css::i18n::XBreakIterator> m_xBreak;
39 std::unique_ptr<LanguageTag> m_xLanguageTag; ///< language tag of the current locale
40 std::unique_ptr<css::i18n::ForbiddenCharacters> m_xForbidden;
42 LanguageType aForbiddenLang; ///< language of the current forbiddenChar struct
44 void GetLocale_( const LanguageType aLang );
45 void GetLocale_( const LanguageTag& rLanguageTag );
46 void GetForbidden_( const LanguageType aLang );
48 SwBreakIt(SwBreakIt const&) = delete;
49 SwBreakIt& operator=(SwBreakIt const&) = delete;
51 // private (see @ Create_, Delete_).
52 explicit SwBreakIt(const css::uno::Reference<css::uno::XComponentContext> & rxContext);
54 public:
55 // private (see @ source/core/bastyp/init.cxx).
56 static void Create_(
57 const css::uno::Reference< css::uno::XComponentContext > & rxContext);
58 static void Delete_();
60 public:
61 static SwBreakIt * Get();
63 css::uno::Reference< css::i18n::XBreakIterator > const & GetBreakIter()
65 return m_xBreak;
68 const css::lang::Locale& GetLocale( const LanguageType aLang )
70 if (!m_xLanguageTag || m_xLanguageTag->getLanguageType() != aLang)
71 GetLocale_(aLang);
72 return m_xLanguageTag->getLocale();
75 const css::lang::Locale& GetLocale( const LanguageTag& rLanguageTag )
77 // Use LanguageType comparison instead of LanguageTag::operator!=()
78 // because here the LanguageTag is already a known LanguageType value
79 // assigned, so LanguageTag does not need to convert to BCP47 for
80 // comparison.
81 if (!m_xLanguageTag || m_xLanguageTag->getLanguageType() != rLanguageTag.getLanguageType())
82 GetLocale_(rLanguageTag);
83 return m_xLanguageTag->getLocale();
86 const LanguageTag& GetLanguageTag( const LanguageType aLang )
88 if (!m_xLanguageTag || m_xLanguageTag->getLanguageType() != aLang)
89 GetLocale_(aLang);
90 return *m_xLanguageTag;
93 const LanguageTag& GetLanguageTag( const LanguageTag& rLanguageTag )
95 // Use LanguageType comparison instead of LanguageTag::operator!=()
96 // because here the LanguageTag is already a known LanguageType value
97 // assigned, so LanguageTag does not need to convert to BCP47 for
98 // comparison.
99 if (!m_xLanguageTag || m_xLanguageTag->getLanguageType() != rLanguageTag.getLanguageType())
100 GetLocale_( rLanguageTag );
101 return *m_xLanguageTag;
104 const css::i18n::ForbiddenCharacters& GetForbidden( const LanguageType aLang )
106 if (!m_xForbidden || aForbiddenLang != aLang)
107 GetForbidden_( aLang );
108 return *m_xForbidden;
111 sal_uInt16 GetRealScriptOfText( const OUString& rText, sal_Int32 nPos ) const;
112 SvtScriptType GetAllScriptsOfText( const OUString& rText ) const;
114 sal_Int32 getGraphemeCount(const OUString& rStr,
115 sal_Int32 nStart, sal_Int32 nEnd) const;
116 sal_Int32 getGraphemeCount(const OUString& rStr) const
118 return getGraphemeCount(rStr, 0, rStr.getLength());
122 #define SW_BREAKITER() SwBreakIt::Get()
124 // @@@ backward compatibility @@@
125 SW_DLLPUBLIC extern SwBreakIt* g_pBreakIt;
127 #endif
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */