/src/libreoffice/sw/inc/breakit.hxx
Line | Count | Source |
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 | | #pragma once |
21 | | |
22 | | #include <memory> |
23 | | #include <optional> |
24 | | #include <com/sun/star/uno/Reference.h> |
25 | | #include <com/sun/star/i18n/ForbiddenCharacters.hpp> |
26 | | #include <i18nlangtag/languagetag.hxx> |
27 | | #include <rtl/ref.hxx> |
28 | | #include <i18npool/breakiterator.hxx> |
29 | | #include "swdllapi.h" |
30 | | |
31 | | enum class SvtScriptType : sal_uInt8; |
32 | | namespace com::sun::star::uno { class XComponentContext; } |
33 | | |
34 | | class SW_DLLPUBLIC SwBreakIt |
35 | | { |
36 | | css::uno::Reference< css::uno::XComponentContext > m_xContext; |
37 | | rtl::Reference<i18npool::BreakIterator> m_xBreak; |
38 | | |
39 | | std::unique_ptr<LanguageTag> m_xLanguageTag; ///< language tag of the current locale |
40 | | std::optional<css::i18n::ForbiddenCharacters> m_oForbidden; |
41 | | |
42 | | LanguageType m_aForbiddenLang; ///< language of the current forbiddenChar struct |
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 | | |
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_(); |
59 | | |
60 | | public: |
61 | | static SwBreakIt * Get(); |
62 | | |
63 | | rtl::Reference< i18npool::BreakIterator > const & GetBreakIter() const |
64 | 6.73M | { |
65 | 6.73M | return m_xBreak; |
66 | 6.73M | } |
67 | | |
68 | | const css::lang::Locale& GetLocale( const LanguageType aLang ) |
69 | 670k | { |
70 | 670k | if (!m_xLanguageTag || m_xLanguageTag->getLanguageType() != aLang) |
71 | 10.7k | GetLocale_(aLang); |
72 | 670k | return m_xLanguageTag->getLocale(); |
73 | 670k | } |
74 | | |
75 | | const css::lang::Locale& GetLocale( const LanguageTag& rLanguageTag ) |
76 | 0 | { |
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 | 0 | if (!m_xLanguageTag || m_xLanguageTag->getLanguageType() != rLanguageTag.getLanguageType()) |
82 | 0 | GetLocale_(rLanguageTag); |
83 | 0 | return m_xLanguageTag->getLocale(); |
84 | 0 | } |
85 | | |
86 | | const LanguageTag& GetLanguageTag( const LanguageType aLang ) |
87 | 537 | { |
88 | 537 | if (!m_xLanguageTag || m_xLanguageTag->getLanguageType() != aLang) |
89 | 441 | GetLocale_(aLang); |
90 | 537 | return *m_xLanguageTag; |
91 | 537 | } |
92 | | |
93 | | const LanguageTag& GetLanguageTag( const LanguageTag& rLanguageTag ) |
94 | 7 | { |
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 | 7 | if (!m_xLanguageTag || m_xLanguageTag->getLanguageType() != rLanguageTag.getLanguageType()) |
100 | 6 | GetLocale_( rLanguageTag ); |
101 | 7 | return *m_xLanguageTag; |
102 | 7 | } |
103 | | |
104 | | const css::i18n::ForbiddenCharacters& GetForbidden( const LanguageType aLang ) |
105 | 466k | { |
106 | 466k | if (!m_oForbidden || m_aForbiddenLang != aLang) |
107 | 537 | GetForbidden_( aLang ); |
108 | 466k | return *m_oForbidden; |
109 | 466k | } |
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 | 0 | { |
118 | 0 | return getGraphemeCount(rStr, 0, rStr.getLength()); |
119 | 0 | } |
120 | | }; |
121 | | |
122 | 0 | #define SW_BREAKITER() SwBreakIt::Get() |
123 | | |
124 | | // @@@ backward compatibility @@@ |
125 | | SW_DLLPUBLIC extern SwBreakIt* g_pBreakIt; |
126 | | |
127 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |