bump product version to 5.0.4.1
[LibreOffice.git] / include / unotools / transliterationwrapper.hxx
blob7d0dce0e16907d17abba6c68315334edd8c253dc
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 .
19 #include <unotools/unotoolsdllapi.h>
21 #ifndef INCLUDED_UNOTOOLS_TRANSLITERATIONWRAPPER_HXX
22 #define INCLUDED_UNOTOOLS_TRANSLITERATIONWRAPPER_HXX
24 #include <rtl/ustring.hxx>
25 #include <i18nlangtag/languagetag.hxx>
26 #include <com/sun/star/i18n/XExtendedTransliteration.hpp>
28 namespace com { namespace sun { namespace star {
29 namespace uno {
30 class XComponentContext;
32 }}}
34 namespace utl
37 class UNOTOOLS_DLLPUBLIC TransliterationWrapper
39 ::com::sun::star::uno::Reference<
40 ::com::sun::star::i18n::XExtendedTransliteration > xTrans;
41 LanguageTag aLanguageTag;
42 sal_uInt32 nType;
43 mutable bool bFirstCall;
45 TransliterationWrapper( const TransliterationWrapper& ) SAL_DELETED_FUNCTION;
46 TransliterationWrapper& operator=( const TransliterationWrapper& ) SAL_DELETED_FUNCTION;
48 void loadModuleImpl() const;
49 void setLanguageLocaleImpl( sal_uInt16 nLang );
51 public:
52 TransliterationWrapper( const ::com::sun::star::uno::Reference<
53 ::com::sun::star::uno::XComponentContext > & rxContext,
54 sal_uInt32 nType );
56 ~TransliterationWrapper();
58 // get current Locale / Language
59 const ::com::sun::star::lang::Locale& getLocale() const { return aLanguageTag.getLocale();}
60 sal_uInt16 getLanguage() const { return aLanguageTag.getLanguageType(); }
62 sal_uInt32 getType() const { return nType; }
64 bool needLanguageForTheMode() const;
66 /** set a new language and load the corresponding transliteration module if
67 needed for the mode set with nType in the ctor */
68 void loadModuleIfNeeded( sal_uInt16 nLang );
70 /** Load the transliteration module specified by rModuleName, which has to
71 be the UNO service implementation name that is expanded to the full UNO
72 service implementation name, for example, "NumToCharKanjiShort_ja_JP"
73 expands to
74 "com.sun.star.i18n.Transliteration.NumToCharKanjiShort_ja_JP".
75 @ATTENTION!
76 This method ignores the mode type set with the constructor and
77 interferes with the loadModuleIfNeeded() method and the transliterate()
78 method that gets a LanguageType passed as parameter. Using one of
79 those may load a different module and overwrite this setting. Only the
80 transliterate() method that takes no LanguageType parameter may be used
81 for a specific module loaded with this method. */
82 void loadModuleByImplName( const OUString& rModuleName, sal_uInt16 nLang );
84 /** This transliteration method corresponds with the loadModuleByImplName()
85 method. It relies on a module being loaded and does not try load one.
86 If for any reason the string can't be transliterated the original
87 string is returned. */
88 OUString transliterate( const OUString& rStr,
89 sal_Int32 nStart, sal_Int32 nLen,
90 ::com::sun::star::uno::Sequence <sal_Int32>* pOffset ) const;
92 // Wrapper implementations of class Transliteration
93 OUString transliterate( const OUString& rStr, sal_uInt16 nLanguage,
94 sal_Int32 nStart, sal_Int32 nLen,
95 ::com::sun::star::uno::Sequence <sal_Int32>* pOffset );
97 /** If two strings are equal per this transliteration.
98 Returns the number of matched code points in any case, even if strings
99 are not equal, for example:
100 equals( "a", 0, 1, nMatch1, "aaa", 0, 3, nMatch2 )
101 returns false and nMatch:=1 and nMatch2:=1
102 equals( "aab", 0, 3, nMatch1, "aaa", 0, 3, nMatch2 )
103 returns false and nMatch:=2 and nMatch2:=2
105 bool equals(
106 const OUString& rStr1, sal_Int32 nPos1, sal_Int32 nCount1, sal_Int32& nMatch1,
107 const OUString& rStr2, sal_Int32 nPos2, sal_Int32 nCount2, sal_Int32& nMatch2 ) const;
109 sal_Int32 compareString( const OUString& rStr1, const OUString& rStr2 ) const;
111 // helpers
113 /** If two strings are really equal as per this translation, and not just
114 one string is matching the start of the other. Use this method instead
115 of compareString()==0 because it is much faster.
117 bool isEqual( const OUString& rStr1, const OUString& rStr2 ) const;
119 /** If string rStr1 matches the start of string rStr2, i.e. "a" in "aaa"
121 bool isMatch( const OUString& rStr1, const OUString& rStr2 ) const;
125 } // namespace utl
127 #endif
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */