LibreOffice Module sw (master)  1
breakit.hxx
Go to the documentation of this file.
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 <memory>
24 #include <com/sun/star/uno/Reference.h>
25 #include <com/sun/star/i18n/ForbiddenCharacters.hpp>
27 #include "swdllapi.h"
28 
29 enum class SvtScriptType;
30 namespace com { namespace sun { namespace star { namespace i18n { class XBreakIterator; } } } }
31 namespace com { namespace sun { namespace star { namespace uno { class XComponentContext; } } } }
32 
34 {
35  css::uno::Reference< css::uno::XComponentContext > m_xContext;
36  css::uno::Reference<css::i18n::XBreakIterator> m_xBreak;
37 
38  std::unique_ptr<LanguageTag> m_xLanguageTag;
39  std::unique_ptr<css::i18n::ForbiddenCharacters> m_xForbidden;
40 
42 
43  void GetLocale_( const LanguageType aLang );
44  void GetLocale_( const LanguageTag& rLanguageTag );
45  void GetForbidden_( const LanguageType aLang );
46 
47  SwBreakIt(SwBreakIt const&) = delete;
48  SwBreakIt& operator=(SwBreakIt const&) = delete;
49 
50  // private (see @ Create_, Delete_).
51  explicit SwBreakIt(const css::uno::Reference<css::uno::XComponentContext> & rxContext);
52 
53 public:
54  // private (see @ source/core/bastyp/init.cxx).
55  static void Create_(
56  const css::uno::Reference< css::uno::XComponentContext > & rxContext);
57  static void Delete_();
58 
59 public:
60  static SwBreakIt * Get();
61 
62  css::uno::Reference< css::i18n::XBreakIterator > const & GetBreakIter()
63  {
64  return m_xBreak;
65  }
66 
67  const css::lang::Locale& GetLocale( const LanguageType aLang )
68  {
69  if (!m_xLanguageTag || m_xLanguageTag->getLanguageType() != aLang)
70  GetLocale_(aLang);
71  return m_xLanguageTag->getLocale();
72  }
73 
74  const css::lang::Locale& GetLocale( const LanguageTag& rLanguageTag )
75  {
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
79  // comparison.
80  if (!m_xLanguageTag || m_xLanguageTag->getLanguageType() != rLanguageTag.getLanguageType())
81  GetLocale_(rLanguageTag);
82  return m_xLanguageTag->getLocale();
83  }
84 
85  const LanguageTag& GetLanguageTag( const LanguageType aLang )
86  {
87  if (!m_xLanguageTag || m_xLanguageTag->getLanguageType() != aLang)
88  GetLocale_(aLang);
89  return *m_xLanguageTag;
90  }
91 
92  const LanguageTag& GetLanguageTag( const LanguageTag& rLanguageTag )
93  {
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
97  // comparison.
98  if (!m_xLanguageTag || m_xLanguageTag->getLanguageType() != rLanguageTag.getLanguageType())
99  GetLocale_( rLanguageTag );
100  return *m_xLanguageTag;
101  }
102 
103  const css::i18n::ForbiddenCharacters& GetForbidden( const LanguageType aLang )
104  {
105  if (!m_xForbidden || m_aForbiddenLang != aLang)
106  GetForbidden_( aLang );
107  return *m_xForbidden;
108  }
109 
110  sal_uInt16 GetRealScriptOfText( const OUString& rText, sal_Int32 nPos ) const;
111  SvtScriptType GetAllScriptsOfText( const OUString& rText ) const;
112 
113  sal_Int32 getGraphemeCount(const OUString& rStr,
114  sal_Int32 nStart, sal_Int32 nEnd) const;
115  sal_Int32 getGraphemeCount(const OUString& rStr) const
116  {
117  return getGraphemeCount(rStr, 0, rStr.getLength());
118  }
119 };
120 
121 #define SW_BREAKITER() SwBreakIt::Get()
122 
123 // @@@ backward compatibility @@@
125 
126 #endif
127 
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
LanguageType m_aForbiddenLang
language of the current forbiddenChar struct
Definition: breakit.hxx:41
css::uno::Reference< css::uno::XComponentContext > m_xContext
Definition: breakit.hxx:35
LanguageType getLanguageType(bool bResolveSystem=true) const
std::unique_ptr< LanguageTag > m_xLanguageTag
language tag of the current locale
Definition: breakit.hxx:38
const LanguageTag & GetLanguageTag(const LanguageType aLang)
Definition: breakit.hxx:85
const css::lang::Locale & GetLocale(const LanguageTag &rLanguageTag)
Definition: breakit.hxx:74
SvtScriptType
const LanguageTag & GetLanguageTag(const LanguageTag &rLanguageTag)
Definition: breakit.hxx:92
SW_DLLPUBLIC SwBreakIt * g_pBreakIt
Definition: breakit.cxx:34
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
const css::lang::Locale & GetLocale(const LanguageType aLang)
Definition: breakit.hxx:67
sal_Int32 getGraphemeCount(const OUString &rStr) const
Definition: breakit.hxx:115
css::uno::Reference< css::i18n::XBreakIterator > m_xBreak
Definition: breakit.hxx:36
css::uno::Reference< css::i18n::XBreakIterator > const & GetBreakIter()
Definition: breakit.hxx:62
std::unique_ptr< css::i18n::ForbiddenCharacters > m_xForbidden
Definition: breakit.hxx:39
SVX_DLLPUBLIC MSO_SPT Get(const OUString &)
const css::i18n::ForbiddenCharacters & GetForbidden(const LanguageType aLang)
Definition: breakit.hxx:103