LibreOffice Module sw (master) 1
breakit.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
20#ifndef INCLUDED_SW_INC_BREAKIT_HXX
21#define INCLUDED_SW_INC_BREAKIT_HXX
22
23#include <memory>
24#include <optional>
25#include <com/sun/star/uno/Reference.h>
26#include <com/sun/star/i18n/ForbiddenCharacters.hpp>
28#include "swdllapi.h"
29
30enum class SvtScriptType : sal_uInt8;
31namespace com::sun::star::i18n { class XBreakIterator; }
32namespace com::sun::star::uno { class XComponentContext; }
33
35{
36 css::uno::Reference< css::uno::XComponentContext > m_xContext;
37 css::uno::Reference<css::i18n::XBreakIterator> m_xBreak;
38
39 std::unique_ptr<LanguageTag> m_xLanguageTag;
40 std::optional<css::i18n::ForbiddenCharacters> m_oForbidden;
41
43
44 void GetLocale_( const LanguageType aLang );
45 void GetLocale_( const LanguageTag& rLanguageTag );
46 void GetForbidden_( const LanguageType aLang );
47
48 SwBreakIt(SwBreakIt const&) = delete;
49 SwBreakIt& operator=(SwBreakIt const&) = delete;
50
51 // private (see @ Create_, Delete_).
52 explicit SwBreakIt(css::uno::Reference<css::uno::XComponentContext> xContext);
53
54public:
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_();
59
60public:
61 static SwBreakIt * Get();
62
63 css::uno::Reference< css::i18n::XBreakIterator > const & GetBreakIter() const
64 {
65 return m_xBreak;
66 }
67
68 const css::lang::Locale& GetLocale( const LanguageType aLang )
69 {
70 if (!m_xLanguageTag || m_xLanguageTag->getLanguageType() != aLang)
71 GetLocale_(aLang);
72 return m_xLanguageTag->getLocale();
73 }
74
75 const css::lang::Locale& GetLocale( const LanguageTag& rLanguageTag )
76 {
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();
84 }
85
87 {
88 if (!m_xLanguageTag || m_xLanguageTag->getLanguageType() != aLang)
89 GetLocale_(aLang);
90 return *m_xLanguageTag;
91 }
92
93 const LanguageTag& GetLanguageTag( const LanguageTag& rLanguageTag )
94 {
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;
102 }
103
104 const css::i18n::ForbiddenCharacters& GetForbidden( const LanguageType aLang )
105 {
106 if (!m_oForbidden || m_aForbiddenLang != aLang)
107 GetForbidden_( aLang );
108 return *m_oForbidden;
109 }
110
111 sal_uInt16 GetRealScriptOfText( const OUString& rText, sal_Int32 nPos ) const;
112 SvtScriptType GetAllScriptsOfText( const OUString& rText ) const;
113
114 sal_Int32 getGraphemeCount(const OUString& rStr,
115 sal_Int32 nStart, sal_Int32 nEnd) const;
116 sal_Int32 getGraphemeCount(const OUString& rStr) const
117 {
118 return getGraphemeCount(rStr, 0, rStr.getLength());
119 }
120};
121
122#define SW_BREAKITER() SwBreakIt::Get()
123
124// @@@ backward compatibility @@@
126
127#endif
128
129/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SW_DLLPUBLIC SwBreakIt * g_pBreakIt
Definition: breakit.cxx:34
LanguageType getLanguageType(bool bResolveSystem=true) const
const css::i18n::ForbiddenCharacters & GetForbidden(const LanguageType aLang)
Definition: breakit.hxx:104
sal_Int32 getGraphemeCount(const OUString &rStr) const
Definition: breakit.hxx:116
const LanguageTag & GetLanguageTag(const LanguageTag &rLanguageTag)
Definition: breakit.hxx:93
std::optional< css::i18n::ForbiddenCharacters > m_oForbidden
Definition: breakit.hxx:40
const css::lang::Locale & GetLocale(const LanguageTag &rLanguageTag)
Definition: breakit.hxx:75
css::uno::Reference< css::i18n::XBreakIterator > const & GetBreakIter() const
Definition: breakit.hxx:63
SwBreakIt(SwBreakIt const &)=delete
SwBreakIt & operator=(SwBreakIt const &)=delete
const css::lang::Locale & GetLocale(const LanguageType aLang)
Definition: breakit.hxx:68
LanguageType m_aForbiddenLang
language of the current forbiddenChar struct
Definition: breakit.hxx:42
std::unique_ptr< LanguageTag > m_xLanguageTag
language tag of the current locale
Definition: breakit.hxx:39
css::uno::Reference< css::uno::XComponentContext > m_xContext
Definition: breakit.hxx:36
css::uno::Reference< css::i18n::XBreakIterator > m_xBreak
Definition: breakit.hxx:37
SwBreakIt(css::uno::Reference< css::uno::XComponentContext > xContext)
const LanguageTag & GetLanguageTag(const LanguageType aLang)
Definition: breakit.hxx:86
SvtScriptType
SVXCORE_DLLPUBLIC MSO_SPT Get(const OUString &)
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
unsigned char sal_uInt8