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_UNOTOOLS_TRANSLITERATIONWRAPPER_HXX
21 #define INCLUDED_UNOTOOLS_TRANSLITERATIONWRAPPER_HXX
23 #include <unotools/unotoolsdllapi.h>
24 #include <rtl/ustring.hxx>
25 #include <i18nlangtag/languagetag.hxx>
26 #include <i18nlangtag/lang.h>
27 #include <com/sun/star/uno/Reference.hxx>
29 namespace com::sun::star::uno
{ template <typename
> class Sequence
; }
30 namespace com::sun::star::i18n
{ class XExtendedTransliteration
; }
31 namespace com::sun::star::uno
{ class XComponentContext
; }
32 enum class TransliterationFlags
;
37 class UNOTOOLS_DLLPUBLIC TransliterationWrapper
39 css::uno::Reference
< css::i18n::XExtendedTransliteration
> xTrans
;
40 LanguageTag aLanguageTag
;
41 TransliterationFlags nType
;
42 mutable bool bFirstCall
;
44 TransliterationWrapper( const TransliterationWrapper
& ) = delete;
45 TransliterationWrapper
& operator=( const TransliterationWrapper
& ) = delete;
47 void loadModuleImpl() const;
48 void setLanguageLocaleImpl( LanguageType nLang
);
51 TransliterationWrapper( const css::uno::Reference
< css::uno::XComponentContext
> & rxContext
,
52 TransliterationFlags nType
);
54 ~TransliterationWrapper();
56 TransliterationFlags
getType() const { return nType
; }
58 bool needLanguageForTheMode() const;
60 /** set a new language and load the corresponding transliteration module if
61 needed for the mode set with nType in the ctor */
62 void loadModuleIfNeeded( LanguageType nLang
);
64 /** Load the transliteration module specified by rModuleName, which has to
65 be the UNO service implementation name that is expanded to the full UNO
66 service implementation name, for example, "NumToCharKanjiShort_ja_JP"
68 "com.sun.star.i18n.Transliteration.NumToCharKanjiShort_ja_JP".
70 This method ignores the mode type set with the constructor and
71 interferes with the loadModuleIfNeeded() method and the transliterate()
72 method that gets a LanguageType passed as parameter. Using one of
73 those may load a different module and overwrite this setting. Only the
74 transliterate() method that takes no LanguageType parameter may be used
75 for a specific module loaded with this method. */
76 void loadModuleByImplName( const OUString
& rModuleName
, LanguageType nLang
);
78 /** This transliteration method corresponds with the loadModuleByImplName()
79 method. It relies on a module being loaded and does not try load one.
80 If for any reason the string can't be transliterated the original
81 string is returned. */
82 OUString
transliterate( const OUString
& rStr
,
83 sal_Int32 nStart
, sal_Int32 nLen
) const;
85 // Wrapper implementations of class Transliteration
86 OUString
transliterate( const OUString
& rStr
, LanguageType nLanguage
,
87 sal_Int32 nStart
, sal_Int32 nLen
,
88 css::uno::Sequence
<sal_Int32
>* pOffset
);
90 /** If two strings are equal per this transliteration.
91 Returns the number of matched code points in any case, even if strings
92 are not equal, for example:
93 equals( "a", 0, 1, nMatch1, "aaa", 0, 3, nMatch2 )
94 returns false and nMatch:=1 and nMatch2:=1
95 equals( "aab", 0, 3, nMatch1, "aaa", 0, 3, nMatch2 )
96 returns false and nMatch:=2 and nMatch2:=2
99 const OUString
& rStr1
, sal_Int32 nPos1
, sal_Int32 nCount1
, sal_Int32
& nMatch1
,
100 const OUString
& rStr2
, sal_Int32 nPos2
, sal_Int32 nCount2
, sal_Int32
& nMatch2
) const;
102 sal_Int32
compareString( const OUString
& rStr1
, const OUString
& rStr2
) const;
106 /** If two strings are really equal as per this translation, and not just
107 one string is matching the start of the other. Use this method instead
108 of compareString()==0 because it is much faster.
110 bool isEqual( const OUString
& rStr1
, const OUString
& rStr2
) const;
112 /** If string rStr1 matches the start of string rStr2, i.e. "a" in "aaa"
114 bool isMatch( const OUString
& rStr1
, const OUString
& rStr2
) const;
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */