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 .
20 #ifndef INCLUDED_SW_INC_BREAKIT_HXX
21 #define INCLUDED_SW_INC_BREAKIT_HXX
23 #include <boost/noncopyable.hpp>
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>
32 enum class SvtScriptType
;
34 class SW_DLLPUBLIC SwBreakIt
: private ::boost::noncopyable
36 com::sun::star::uno::Reference
< com::sun::star::uno::XComponentContext
> m_xContext
;
37 mutable com::sun::star::uno::Reference
< com::sun::star::i18n::XBreakIterator
> xBreak
;
39 LanguageTag
* m_pLanguageTag
; ///< language tag of the current locale
40 com::sun::star::i18n::ForbiddenCharacters
* m_pForbidden
;
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 void createBreakIterator() const;
50 // private (see @ _Create, _Delete).
52 const com::sun::star::uno::Reference
< com::sun::star::uno::XComponentContext
> & rxContext
);
56 // private (see @ source/core/bastyp/init.cxx).
58 const com::sun::star::uno::Reference
< com::sun::star::uno::XComponentContext
> & rxContext
);
59 static void _Delete();
62 static SwBreakIt
* Get();
64 com::sun::star::uno::Reference
< com::sun::star::i18n::XBreakIterator
> GetBreakIter()
66 createBreakIterator();
70 const com::sun::star::lang::Locale
& GetLocale( const LanguageType aLang
)
72 if( !m_pLanguageTag
|| m_pLanguageTag
->getLanguageType() != aLang
)
74 return m_pLanguageTag
->getLocale();
77 const com::sun::star::lang::Locale
& GetLocale( const LanguageTag
& rLanguageTag
)
79 // Use LanguageType comparison instead of LanguageTag::operator!=()
80 // because here the LanguageTag is already a known LanguageType value
81 // assigned, so LanguageTag does not need to convert to BCP47 for
83 if( !m_pLanguageTag
|| m_pLanguageTag
->getLanguageType() != rLanguageTag
.getLanguageType() )
84 _GetLocale( rLanguageTag
);
85 return m_pLanguageTag
->getLocale();
88 const LanguageTag
& GetLanguageTag( const LanguageType aLang
)
90 if( !m_pLanguageTag
|| m_pLanguageTag
->getLanguageType() != aLang
)
92 return *m_pLanguageTag
;
95 const LanguageTag
& GetLanguageTag( const LanguageTag
& rLanguageTag
)
97 // Use LanguageType comparison instead of LanguageTag::operator!=()
98 // because here the LanguageTag is already a known LanguageType value
99 // assigned, so LanguageTag does not need to convert to BCP47 for
101 if( !m_pLanguageTag
|| m_pLanguageTag
->getLanguageType() != rLanguageTag
.getLanguageType() )
102 _GetLocale( rLanguageTag
);
103 return *m_pLanguageTag
;
106 const com::sun::star::i18n::ForbiddenCharacters
& GetForbidden( const LanguageType aLang
)
108 if( !m_pForbidden
|| aForbiddenLang
!= aLang
)
109 _GetForbidden( aLang
);
110 return *m_pForbidden
;
113 sal_uInt16
GetRealScriptOfText( const OUString
& rText
, sal_Int32 nPos
) const;
114 SvtScriptType
GetAllScriptsOfText( const OUString
& rText
) const;
116 sal_Int32
getGraphemeCount(const OUString
& rStr
,
117 sal_Int32 nStart
, sal_Int32 nEnd
) const;
118 sal_Int32
getGraphemeCount(const OUString
& rStr
) const
120 return getGraphemeCount(rStr
, 0, rStr
.getLength());
124 #define SW_BREAKITER() SwBreakIt::Get()
126 // @@@ backward compatibility @@@
127 SW_DLLPUBLIC
extern SwBreakIt
* g_pBreakIt
;
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */