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