1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: transliteration_caseignore.cxx,v $
10 * $Revision: 1.11.24.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_i18npool.hxx"
34 // prevent internal compiler error with MSVC6SP3
37 #include <i18nutil/oneToOneMapping.hxx>
38 #include <i18nutil/casefolding.hxx>
39 #include "transliteration_caseignore.hxx"
41 using namespace ::com::sun::star::uno
;
42 using namespace ::com::sun::star::lang
;
43 using namespace ::rtl
;
45 namespace com
{ namespace sun
{ namespace star
{ namespace i18n
{
47 Transliteration_caseignore::Transliteration_caseignore()
49 nMappingType
= MappingTypeFullFolding
;
50 moduleLoaded
= (TransliterationModules
)0;
51 transliterationName
= "case ignore (generic)";
52 implementationName
= "com.sun.star.i18n.Transliteration.Transliteration_caseignore";
56 /* NOTE: We had this, derived from Transliteration_caseignore, but it was
57 * unused code. Deactivated with #i89580# but left for reference in case
58 * MappingTypeSimpleFolding would be needed at some time.
60 Transliteration_simplecaseignore::Transliteration_simplecaseignore()
62 nMappingType
= MappingTypeSimpleFolding
;
63 moduleLoaded
= (TransliterationModules
)0;
64 transliterationName
= "simple case ignore (generic)";
65 implementationName
= "com.sun.star.i18n.Transliteration.Transliteration_simplecaseignore";
70 Transliteration_caseignore::loadModule( TransliterationModules modName
, const Locale
& rLocale
)
71 throw(RuntimeException
)
73 moduleLoaded
= (TransliterationModules
) (moduleLoaded
|modName
);
77 sal_Int16 SAL_CALL
Transliteration_caseignore::getType() throw(RuntimeException
)
79 // It's NOT TransliterationType::ONE_TO_ONE because it's using casefolding
80 return TransliterationType::IGNORE
;
84 Sequence
< OUString
> SAL_CALL
85 Transliteration_caseignore::transliterateRange( const OUString
& str1
, const OUString
& str2
)
86 throw( RuntimeException
)
88 if (str1
.getLength() != 1 || str2
.getLength() != 1)
89 throw RuntimeException();
91 static Transliteration_u2l u2l
;
92 static Transliteration_l2u l2u
;
94 u2l
.loadModule((TransliterationModules
)0, aLocale
);
95 l2u
.loadModule((TransliterationModules
)0, aLocale
);
97 OUString l1
= u2l
.transliterateString2String(str1
, 0, str1
.getLength());
98 OUString u1
= l2u
.transliterateString2String(str1
, 0, str1
.getLength());
99 OUString l2
= u2l
.transliterateString2String(str2
, 0, str2
.getLength());
100 OUString u2
= l2u
.transliterateString2String(str2
, 0, str2
.getLength());
102 if ((l1
== u1
) && (l2
== u2
)) {
103 Sequence
< OUString
> r(2);
108 Sequence
< OUString
> r(4);
118 Transliteration_caseignore::equals(
119 const ::rtl::OUString
& str1
, sal_Int32 pos1
, sal_Int32 nCount1
, sal_Int32
& nMatch1
,
120 const ::rtl::OUString
& str2
, sal_Int32 pos2
, sal_Int32 nCount2
, sal_Int32
& nMatch2
)
121 throw(::com::sun::star::uno::RuntimeException
)
123 return (compare(str1
, pos1
, nCount1
, nMatch1
, str2
, pos2
, nCount2
, nMatch2
) == 0);
127 Transliteration_caseignore::compareSubstring(
128 const ::rtl::OUString
& str1
, sal_Int32 off1
, sal_Int32 len1
,
129 const ::rtl::OUString
& str2
, sal_Int32 off2
, sal_Int32 len2
)
130 throw(RuntimeException
)
132 sal_Int32 nMatch1
, nMatch2
;
133 return compare(str1
, off1
, len1
, nMatch1
, str2
, off2
, len2
, nMatch2
);
138 Transliteration_caseignore::compareString(
139 const ::rtl::OUString
& str1
,
140 const ::rtl::OUString
& str2
)
141 throw(RuntimeException
)
143 sal_Int32 nMatch1
, nMatch2
;
144 return compare(str1
, 0, str1
.getLength(), nMatch1
, str2
, 0, str2
.getLength(), nMatch2
);
148 Transliteration_caseignore::compare(
149 const ::rtl::OUString
& str1
, sal_Int32 pos1
, sal_Int32 nCount1
, sal_Int32
& nMatch1
,
150 const ::rtl::OUString
& str2
, sal_Int32 pos2
, sal_Int32 nCount2
, sal_Int32
& nMatch2
)
151 throw(RuntimeException
)
153 const sal_Unicode
*unistr1
= (sal_Unicode
*) str1
.getStr() + pos1
;
154 const sal_Unicode
*unistr2
= (sal_Unicode
*) str2
.getStr() + pos2
;
156 MappingElement e1
, e2
;
157 nMatch1
= nMatch2
= 0;
159 #define NOT_END_OF_STR1 (nMatch1 < nCount1 || e1.current < e1.element.nmap)
160 #define NOT_END_OF_STR2 (nMatch2 < nCount2 || e2.current < e2.element.nmap)
162 while (NOT_END_OF_STR1
&& NOT_END_OF_STR2
) {
163 c1
= casefolding::getNextChar(unistr1
, nMatch1
, nCount1
, e1
, aLocale
, nMappingType
, moduleLoaded
);
164 c2
= casefolding::getNextChar(unistr2
, nMatch2
, nCount2
, e2
, aLocale
, nMappingType
, moduleLoaded
);
166 nMatch1
--; nMatch2
--;
167 return c1
> c2
? 1 : -1;
171 return (!NOT_END_OF_STR1
&& !NOT_END_OF_STR2
) ? 0
172 : (NOT_END_OF_STR1
? 1 : -1);