bump product version to 4.1.6.2
[LibreOffice.git] / sw / inc / breakit.hxx
blob0776ae648cb29e05225c92f6b265ae2994d4376f
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 _BREAKIT_HXX
21 #define _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>
30 #include <swdllapi.h>
32 /*************************************************************************
33 * class SwBreakIt
34 *************************************************************************/
37 class SW_DLLPUBLIC SwBreakIt : private ::boost::noncopyable
39 com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > m_xContext;
40 mutable com::sun::star::uno::Reference< com::sun::star::i18n::XBreakIterator > xBreak;
42 LanguageTag * m_pLanguageTag; ///< language tag of the current locale
43 com::sun::star::i18n::ForbiddenCharacters * m_pForbidden;
45 LanguageType aForbiddenLang; ///< language of the current forbiddenChar struct
47 void _GetLocale( const LanguageType aLang );
48 void _GetLocale( const LanguageTag& rLanguageTag );
49 void _GetForbidden( const LanguageType aLang );
51 void createBreakIterator() const;
53 // private (see @ _Create, _Delete).
54 explicit SwBreakIt(
55 const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > & rxContext);
56 ~SwBreakIt();
58 public:
59 // private (see @ source/core/bastyp/init.cxx).
60 static void _Create(
61 const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > & rxContext);
62 static void _Delete();
64 public:
65 static SwBreakIt * Get();
67 com::sun::star::uno::Reference< com::sun::star::i18n::XBreakIterator > GetBreakIter()
69 createBreakIterator();
70 return xBreak;
73 const com::sun::star::lang::Locale& GetLocale( const LanguageType aLang )
75 if( !m_pLanguageTag || m_pLanguageTag->getLanguageType() != aLang )
76 _GetLocale( aLang );
77 return m_pLanguageTag->getLocale();
80 const com::sun::star::lang::Locale& GetLocale( const LanguageTag& rLanguageTag )
82 // Use LanguageType comparison instead of LanguageTag::operator!=()
83 // because here the LanguageTag is already a known LanguageType value
84 // assigned, so LanguageTag does not need to convert to BCP47 for
85 // comparison.
86 if( !m_pLanguageTag || m_pLanguageTag->getLanguageType() != rLanguageTag.getLanguageType() )
87 _GetLocale( rLanguageTag );
88 return m_pLanguageTag->getLocale();
91 const LanguageTag& GetLanguageTag( const LanguageType aLang )
93 if( !m_pLanguageTag || m_pLanguageTag->getLanguageType() != aLang )
94 _GetLocale( aLang );
95 return *m_pLanguageTag;
98 const LanguageTag& GetLanguageTag( const LanguageTag& rLanguageTag )
100 // Use LanguageType comparison instead of LanguageTag::operator!=()
101 // because here the LanguageTag is already a known LanguageType value
102 // assigned, so LanguageTag does not need to convert to BCP47 for
103 // comparison.
104 if( !m_pLanguageTag || m_pLanguageTag->getLanguageType() != rLanguageTag.getLanguageType() )
105 _GetLocale( rLanguageTag );
106 return *m_pLanguageTag;
109 const com::sun::star::i18n::ForbiddenCharacters& GetForbidden( const LanguageType aLang )
111 if( !m_pForbidden || aForbiddenLang != aLang )
112 _GetForbidden( aLang );
113 return *m_pForbidden;
116 sal_uInt16 GetRealScriptOfText( const OUString& rTxt, sal_Int32 nPos ) const;
117 sal_uInt16 GetAllScriptsOfText( const OUString& rTxt ) const;
119 sal_Int32 getGraphemeCount(const OUString& rStr,
120 sal_Int32 nStart, sal_Int32 nEnd) const;
121 sal_Int32 getGraphemeCount(const OUString& rStr) const
123 return getGraphemeCount(rStr, 0, rStr.getLength());
127 #define SW_BREAKITER() SwBreakIt::Get()
129 // @@@ backward compatibility @@@
130 SW_DLLPUBLIC extern SwBreakIt* g_pBreakIt;
132 #endif
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */