1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
24 #include <com/sun/star/uno/Reference.h>
25 #include <com/sun/star/i18n/ForbiddenCharacters.hpp>
26 #include <i18nlangtag/languagetag.hxx>
29 enum class SvtScriptType
: sal_uInt8
;
30 namespace com::sun::star::i18n
{ class XBreakIterator
; }
31 namespace com::sun::star::uno
{ class XComponentContext
; }
33 class SW_DLLPUBLIC SwBreakIt
35 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
36 css::uno::Reference
<css::i18n::XBreakIterator
> m_xBreak
;
38 std::unique_ptr
<LanguageTag
> m_xLanguageTag
; ///< language tag of the current locale
39 std::optional
<css::i18n::ForbiddenCharacters
> m_oForbidden
;
41 LanguageType m_aForbiddenLang
; ///< language of the current forbiddenChar struct
43 void GetLocale_( const LanguageType aLang
);
44 void GetLocale_( const LanguageTag
& rLanguageTag
);
45 void GetForbidden_( const LanguageType aLang
);
47 SwBreakIt(SwBreakIt
const&) = delete;
48 SwBreakIt
& operator=(SwBreakIt
const&) = delete;
50 // private (see @ Create_, Delete_).
51 explicit SwBreakIt(css::uno::Reference
<css::uno::XComponentContext
> xContext
);
54 // private (see @ source/core/bastyp/init.cxx).
56 const css::uno::Reference
< css::uno::XComponentContext
> & rxContext
);
57 static void Delete_();
60 static SwBreakIt
* Get();
62 css::uno::Reference
< css::i18n::XBreakIterator
> const & GetBreakIter() const
67 const css::lang::Locale
& GetLocale( const LanguageType aLang
)
69 if (!m_xLanguageTag
|| m_xLanguageTag
->getLanguageType() != aLang
)
71 return m_xLanguageTag
->getLocale();
74 const css::lang::Locale
& GetLocale( const LanguageTag
& rLanguageTag
)
76 // Use LanguageType comparison instead of LanguageTag::operator!=()
77 // because here the LanguageTag is already a known LanguageType value
78 // assigned, so LanguageTag does not need to convert to BCP47 for
80 if (!m_xLanguageTag
|| m_xLanguageTag
->getLanguageType() != rLanguageTag
.getLanguageType())
81 GetLocale_(rLanguageTag
);
82 return m_xLanguageTag
->getLocale();
85 const LanguageTag
& GetLanguageTag( const LanguageType aLang
)
87 if (!m_xLanguageTag
|| m_xLanguageTag
->getLanguageType() != aLang
)
89 return *m_xLanguageTag
;
92 const LanguageTag
& GetLanguageTag( const LanguageTag
& rLanguageTag
)
94 // Use LanguageType comparison instead of LanguageTag::operator!=()
95 // because here the LanguageTag is already a known LanguageType value
96 // assigned, so LanguageTag does not need to convert to BCP47 for
98 if (!m_xLanguageTag
|| m_xLanguageTag
->getLanguageType() != rLanguageTag
.getLanguageType())
99 GetLocale_( rLanguageTag
);
100 return *m_xLanguageTag
;
103 const css::i18n::ForbiddenCharacters
& GetForbidden( const LanguageType aLang
)
105 if (!m_oForbidden
|| m_aForbiddenLang
!= aLang
)
106 GetForbidden_( aLang
);
107 return *m_oForbidden
;
110 sal_uInt16
GetRealScriptOfText( const OUString
& rText
, sal_Int32 nPos
) const;
111 SvtScriptType
GetAllScriptsOfText( const OUString
& rText
) const;
113 sal_Int32
getGraphemeCount(const OUString
& rStr
,
114 sal_Int32 nStart
, sal_Int32 nEnd
) const;
115 sal_Int32
getGraphemeCount(const OUString
& rStr
) const
117 return getGraphemeCount(rStr
, 0, rStr
.getLength());
121 #define SW_BREAKITER() SwBreakIt::Get()
123 // @@@ backward compatibility @@@
124 SW_DLLPUBLIC
extern SwBreakIt
* g_pBreakIt
;
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */