Line data Source code
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 <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>
31 :
32 : enum class SvtScriptType;
33 :
34 : class SW_DLLPUBLIC SwBreakIt : private ::boost::noncopyable
35 : {
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;
38 :
39 : LanguageTag * m_pLanguageTag; ///< language tag of the current locale
40 : com::sun::star::i18n::ForbiddenCharacters * m_pForbidden;
41 :
42 : LanguageType 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 : void createBreakIterator() const;
49 :
50 : // private (see @ _Create, _Delete).
51 : explicit SwBreakIt(
52 : const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > & rxContext);
53 : ~SwBreakIt();
54 :
55 : public:
56 : // private (see @ source/core/bastyp/init.cxx).
57 : static void _Create(
58 : const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > & rxContext);
59 : static void _Delete();
60 :
61 : public:
62 : static SwBreakIt * Get();
63 :
64 397605213 : com::sun::star::uno::Reference< com::sun::star::i18n::XBreakIterator > GetBreakIter()
65 : {
66 397605213 : createBreakIterator();
67 397605213 : return xBreak;
68 : }
69 :
70 225402791 : const com::sun::star::lang::Locale& GetLocale( const LanguageType aLang )
71 : {
72 225402791 : if( !m_pLanguageTag || m_pLanguageTag->getLanguageType() != aLang )
73 2798 : _GetLocale( aLang );
74 225402791 : return m_pLanguageTag->getLocale();
75 : }
76 :
77 0 : const com::sun::star::lang::Locale& GetLocale( const LanguageTag& rLanguageTag )
78 : {
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
82 : // comparison.
83 0 : if( !m_pLanguageTag || m_pLanguageTag->getLanguageType() != rLanguageTag.getLanguageType() )
84 0 : _GetLocale( rLanguageTag );
85 0 : return m_pLanguageTag->getLocale();
86 : }
87 :
88 205 : const LanguageTag& GetLanguageTag( const LanguageType aLang )
89 : {
90 205 : if( !m_pLanguageTag || m_pLanguageTag->getLanguageType() != aLang )
91 138 : _GetLocale( aLang );
92 205 : return *m_pLanguageTag;
93 : }
94 :
95 49 : const LanguageTag& GetLanguageTag( const LanguageTag& rLanguageTag )
96 : {
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
100 : // comparison.
101 49 : if( !m_pLanguageTag || m_pLanguageTag->getLanguageType() != rLanguageTag.getLanguageType() )
102 24 : _GetLocale( rLanguageTag );
103 49 : return *m_pLanguageTag;
104 : }
105 :
106 33530 : const com::sun::star::i18n::ForbiddenCharacters& GetForbidden( const LanguageType aLang )
107 : {
108 33530 : if( !m_pForbidden || aForbiddenLang != aLang )
109 205 : _GetForbidden( aLang );
110 33530 : return *m_pForbidden;
111 : }
112 :
113 : sal_uInt16 GetRealScriptOfText( const OUString& rText, sal_Int32 nPos ) const;
114 : SvtScriptType GetAllScriptsOfText( const OUString& rText ) const;
115 :
116 : sal_Int32 getGraphemeCount(const OUString& rStr,
117 : sal_Int32 nStart, sal_Int32 nEnd) const;
118 258433 : sal_Int32 getGraphemeCount(const OUString& rStr) const
119 : {
120 258433 : return getGraphemeCount(rStr, 0, rStr.getLength());
121 : }
122 : };
123 :
124 : #define SW_BREAKITER() SwBreakIt::Get()
125 :
126 : // @@@ backward compatibility @@@
127 : SW_DLLPUBLIC extern SwBreakIt* g_pBreakIt;
128 :
129 : #endif
130 :
131 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|