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 #include <com/sun/star/uno/XComponentContext.hpp>
22 #include <i18nutil/oneToOneMapping.hxx>
23 #include <i18nutil/casefolding.hxx>
25 #include "transliteration_caseignore.hxx"
27 using namespace ::com::sun::star::uno
;
28 using namespace ::com::sun::star::lang
;
29 using namespace ::rtl
;
31 namespace com
{ namespace sun
{ namespace star
{ namespace i18n
{
33 Transliteration_caseignore::Transliteration_caseignore()
35 nMappingType
= MappingTypeFullFolding
;
36 moduleLoaded
= (TransliterationModules
)0;
37 transliterationName
= "case ignore (generic)";
38 implementationName
= "com.sun.star.i18n.Transliteration.Transliteration_caseignore";
42 Transliteration_caseignore::loadModule( TransliterationModules modName
, const Locale
& rLocale
)
43 throw(RuntimeException
, std::exception
)
45 moduleLoaded
= (TransliterationModules
) (moduleLoaded
|modName
);
49 sal_Int16 SAL_CALL
Transliteration_caseignore::getType() throw(RuntimeException
, std::exception
)
51 // It's NOT TransliterationType::ONE_TO_ONE because it's using casefolding
52 return TransliterationType::IGNORE
;
56 Sequence
< OUString
> SAL_CALL
57 Transliteration_caseignore::transliterateRange( const OUString
& str1
, const OUString
& str2
)
58 throw( RuntimeException
, std::exception
)
60 if (str1
.getLength() != 1 || str2
.getLength() != 1)
61 throw RuntimeException();
63 static Transliteration_u2l u2l
;
64 static Transliteration_l2u l2u
;
66 u2l
.loadModule((TransliterationModules
)0, aLocale
);
67 l2u
.loadModule((TransliterationModules
)0, aLocale
);
69 OUString l1
= u2l
.transliterateString2String(str1
, 0, str1
.getLength());
70 OUString u1
= l2u
.transliterateString2String(str1
, 0, str1
.getLength());
71 OUString l2
= u2l
.transliterateString2String(str2
, 0, str2
.getLength());
72 OUString u2
= l2u
.transliterateString2String(str2
, 0, str2
.getLength());
74 if ((l1
== u1
) && (l2
== u2
)) {
75 Sequence
< OUString
> r(2);
80 Sequence
< OUString
> r(4);
90 Transliteration_caseignore::equals(
91 const OUString
& str1
, sal_Int32 pos1
, sal_Int32 nCount1
, sal_Int32
& nMatch1
,
92 const OUString
& str2
, sal_Int32 pos2
, sal_Int32 nCount2
, sal_Int32
& nMatch2
)
93 throw(::com::sun::star::uno::RuntimeException
, std::exception
)
95 return (compare(str1
, pos1
, nCount1
, nMatch1
, str2
, pos2
, nCount2
, nMatch2
) == 0);
99 Transliteration_caseignore::compareSubstring(
100 const OUString
& str1
, sal_Int32 off1
, sal_Int32 len1
,
101 const OUString
& str2
, sal_Int32 off2
, sal_Int32 len2
)
102 throw(RuntimeException
, std::exception
)
104 sal_Int32 nMatch1
, nMatch2
;
105 return compare(str1
, off1
, len1
, nMatch1
, str2
, off2
, len2
, nMatch2
);
110 Transliteration_caseignore::compareString(
111 const OUString
& str1
,
112 const OUString
& str2
)
113 throw(RuntimeException
, std::exception
)
115 sal_Int32 nMatch1
, nMatch2
;
116 return compare(str1
, 0, str1
.getLength(), nMatch1
, str2
, 0, str2
.getLength(), nMatch2
);
120 Transliteration_caseignore::compare(
121 const OUString
& str1
, sal_Int32 pos1
, sal_Int32 nCount1
, sal_Int32
& nMatch1
,
122 const OUString
& str2
, sal_Int32 pos2
, sal_Int32 nCount2
, sal_Int32
& nMatch2
)
123 throw(RuntimeException
)
125 const sal_Unicode
*unistr1
= (sal_Unicode
*) str1
.getStr() + pos1
;
126 const sal_Unicode
*unistr2
= (sal_Unicode
*) str2
.getStr() + pos2
;
128 MappingElement e1
, e2
;
129 nMatch1
= nMatch2
= 0;
131 #define NOT_END_OF_STR1 (nMatch1 < nCount1 || e1.current < e1.element.nmap)
132 #define NOT_END_OF_STR2 (nMatch2 < nCount2 || e2.current < e2.element.nmap)
134 while (NOT_END_OF_STR1
&& NOT_END_OF_STR2
) {
135 c1
= casefolding::getNextChar(unistr1
, nMatch1
, nCount1
, e1
, aLocale
, nMappingType
, moduleLoaded
);
136 c2
= casefolding::getNextChar(unistr2
, nMatch2
, nCount2
, e2
, aLocale
, nMappingType
, moduleLoaded
);
138 nMatch1
--; nMatch2
--;
139 return c1
> c2
? 1 : -1;
143 return (!NOT_END_OF_STR1
&& !NOT_END_OF_STR2
) ? 0
144 : (NOT_END_OF_STR1
? 1 : -1);
149 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
150 com_sun_star_i18n_Transliteration_IGNORE_CASE_get_implementation(
151 css::uno::XComponentContext
*,
152 css::uno::Sequence
<css::uno::Any
> const &)
154 return cppu::acquire(new css::i18n::Transliteration_caseignore());
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */