Bump version to 6.4-15
[LibreOffice.git] / include / unotools / transliterationwrapper.hxx
blob882975bac2a5b8f9994585d245ce3977bd4c5657
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 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 { namespace sun { namespace star { namespace uno { template <typename > class Sequence; } } } }
30 namespace com { namespace sun { namespace star { namespace i18n { class XExtendedTransliteration; } } } }
32 namespace com { namespace sun { namespace star {
33 namespace uno {
34 class XComponentContext;
36 }}}
37 enum class TransliterationFlags;
39 namespace utl
42 class UNOTOOLS_DLLPUBLIC TransliterationWrapper
44 css::uno::Reference< css::i18n::XExtendedTransliteration > xTrans;
45 LanguageTag aLanguageTag;
46 TransliterationFlags const nType;
47 mutable bool bFirstCall;
49 TransliterationWrapper( const TransliterationWrapper& ) = delete;
50 TransliterationWrapper& operator=( const TransliterationWrapper& ) = delete;
52 void loadModuleImpl() const;
53 void setLanguageLocaleImpl( LanguageType nLang );
55 public:
56 TransliterationWrapper( const css::uno::Reference< css::uno::XComponentContext > & rxContext,
57 TransliterationFlags nType );
59 ~TransliterationWrapper();
61 TransliterationFlags getType() const { return nType; }
63 bool needLanguageForTheMode() const;
65 /** set a new language and load the corresponding transliteration module if
66 needed for the mode set with nType in the ctor */
67 void loadModuleIfNeeded( LanguageType nLang );
69 /** Load the transliteration module specified by rModuleName, which has to
70 be the UNO service implementation name that is expanded to the full UNO
71 service implementation name, for example, "NumToCharKanjiShort_ja_JP"
72 expands to
73 "com.sun.star.i18n.Transliteration.NumToCharKanjiShort_ja_JP".
74 @ATTENTION!
75 This method ignores the mode type set with the constructor and
76 interferes with the loadModuleIfNeeded() method and the transliterate()
77 method that gets a LanguageType passed as parameter. Using one of
78 those may load a different module and overwrite this setting. Only the
79 transliterate() method that takes no LanguageType parameter may be used
80 for a specific module loaded with this method. */
81 void loadModuleByImplName( const OUString& rModuleName, LanguageType nLang );
83 /** This transliteration method corresponds with the loadModuleByImplName()
84 method. It relies on a module being loaded and does not try load one.
85 If for any reason the string can't be transliterated the original
86 string is returned. */
87 OUString transliterate( const OUString& rStr,
88 sal_Int32 nStart, sal_Int32 nLen ) const;
90 // Wrapper implementations of class Transliteration
91 OUString transliterate( const OUString& rStr, LanguageType nLanguage,
92 sal_Int32 nStart, sal_Int32 nLen,
93 css::uno::Sequence <sal_Int32>* pOffset );
95 /** If two strings are equal per this transliteration.
96 Returns the number of matched code points in any case, even if strings
97 are not equal, for example:
98 equals( "a", 0, 1, nMatch1, "aaa", 0, 3, nMatch2 )
99 returns false and nMatch:=1 and nMatch2:=1
100 equals( "aab", 0, 3, nMatch1, "aaa", 0, 3, nMatch2 )
101 returns false and nMatch:=2 and nMatch2:=2
103 bool equals(
104 const OUString& rStr1, sal_Int32 nPos1, sal_Int32 nCount1, sal_Int32& nMatch1,
105 const OUString& rStr2, sal_Int32 nPos2, sal_Int32 nCount2, sal_Int32& nMatch2 ) const;
107 sal_Int32 compareString( const OUString& rStr1, const OUString& rStr2 ) const;
109 // helpers
111 /** If two strings are really equal as per this translation, and not just
112 one string is matching the start of the other. Use this method instead
113 of compareString()==0 because it is much faster.
115 bool isEqual( const OUString& rStr1, const OUString& rStr2 ) const;
117 /** If string rStr1 matches the start of string rStr2, i.e. "a" in "aaa"
119 bool isMatch( const OUString& rStr1, const OUString& rStr2 ) const;
123 } // namespace utl
125 #endif
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */