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 .
19 #include "unotools/unotoolsdllapi.h"
21 #ifndef _UNOTOOLS_TRANSLITERATIONWRAPPER_HXX
22 #define _UNOTOOLS_TRANSLITERATIONWRAPPER_HXX
23 #include <tools/string.hxx>
24 #include <tools/solar.h>
25 #include <i18nlangtag/languagetag.hxx>
26 #include <com/sun/star/i18n/XExtendedTransliteration.hpp>
28 namespace com
{ namespace sun
{ namespace star
{
30 class XComponentContext
;
37 class UNOTOOLS_DLLPUBLIC TransliterationWrapper
39 ::com::sun::star::uno::Reference
<
40 ::com::sun::star::i18n::XExtendedTransliteration
> xTrans
;
41 LanguageTag aLanguageTag
;
43 mutable sal_Bool bFirstCall
;
45 // not implemented, prevent usage
46 TransliterationWrapper( const TransliterationWrapper
& );
47 TransliterationWrapper
& operator=( const TransliterationWrapper
& );
49 void loadModuleImpl() const;
50 void setLanguageLocaleImpl( sal_uInt16 nLang
);
53 TransliterationWrapper( const ::com::sun::star::uno::Reference
<
54 ::com::sun::star::uno::XComponentContext
> & rxContext
,
57 ~TransliterationWrapper();
59 // get current Locale / Language
60 const ::com::sun::star::lang::Locale
& getLocale() const { return aLanguageTag
.getLocale();}
61 sal_uInt16
getLanguage() const { return aLanguageTag
.getLanguageType(); }
63 sal_uInt32
getType() const { return nType
; }
65 sal_Bool
needLanguageForTheMode() const;
67 /** set a new language and load the corresponding transliteration module if
68 needed for the mode set with nType in the ctor */
69 void loadModuleIfNeeded( sal_uInt16 nLang
);
71 /** Load the transliteration module specified by rModuleName, which has to
72 be the UNO service implementation name that is expanded to the full UNO
73 service implementation name, for example, "NumToCharKanjiShort_ja_JP"
75 "com.sun.star.i18n.Transliteration.NumToCharKanjiShort_ja_JP".
77 This method ignores the mode type set with the constructor and
78 interferes with the loadModuleIfNeeded() method and the transliterate()
79 method that gets a LanguageType passed as parameter. Using one of
80 those may load a different module and overwrite this setting. Only the
81 transliterate() method that takes no LanguageType parameter may be used
82 for a specific module loaded with this method. */
83 void loadModuleByImplName( const String
& rModuleName
, sal_uInt16 nLang
);
85 /** This transliteration method corresponds with the loadModuleByImplName()
86 method. It relies on a module being loaded and does not try load one.
87 If for any reason the string can't be transliterated the original
88 string is returned. */
89 String
transliterate( const String
& rStr
,
90 xub_StrLen nStart
, xub_StrLen nLen
,
91 ::com::sun::star::uno::Sequence
<sal_Int32
>* pOffset
) const;
93 // Wrapper implementations of class Transliteration
94 String
transliterate( const String
& rStr
, sal_uInt16 nLanguage
,
95 xub_StrLen nStart
, xub_StrLen nLen
,
96 ::com::sun::star::uno::Sequence
<sal_Int32
>* pOffset
);
98 /** If two strings are equal per this transliteration.
99 Returns the number of matched code points in any case, even if strings
100 are not equal, for example:
101 equals( "a", 0, 1, nMatch1, "aaa", 0, 3, nMatch2 )
102 returns false and nMatch:=1 and nMatch2:=1
103 equals( "aab", 0, 3, nMatch1, "aaa", 0, 3, nMatch2 )
104 returns false and nMatch:=2 and nMatch2:=2
107 const String
& rStr1
, sal_Int32 nPos1
, sal_Int32 nCount1
, sal_Int32
& nMatch1
,
108 const String
& rStr2
, sal_Int32 nPos2
, sal_Int32 nCount2
, sal_Int32
& nMatch2
) const;
110 sal_Int32
compareString( const String
& rStr1
, const String
& rStr2
) const;
115 /** If two strings are really equal as per this translation, and not just
116 one string is matching the start of the other. Use this method instead
117 of compareString()==0 because it is much faster.
119 sal_Bool
isEqual( const String
& rStr1
, const String
& rStr2
) const;
121 /** If string rStr1 matches the start of string rStr2, i.e. "a" in "aaa"
123 sal_Bool
isMatch( const String
& rStr1
, const String
& rStr2
) const;
127 // ............................................................................
129 // ............................................................................
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */