1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_i18npool.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir // prevent internal compiler error with MSVC6SP3
32*cdf0e10cSrcweir #include <utility>
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #include <i18nutil/oneToOneMapping.hxx>
35*cdf0e10cSrcweir #include <i18nutil/casefolding.hxx>
36*cdf0e10cSrcweir #include "transliteration_caseignore.hxx"
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
39*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
40*cdf0e10cSrcweir using namespace ::rtl;
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir namespace com { namespace sun { namespace star { namespace i18n {
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir Transliteration_caseignore::Transliteration_caseignore()
45*cdf0e10cSrcweir {
46*cdf0e10cSrcweir 	nMappingType = MappingTypeFullFolding;
47*cdf0e10cSrcweir 	moduleLoaded = (TransliterationModules)0;
48*cdf0e10cSrcweir 	transliterationName = "case ignore (generic)";
49*cdf0e10cSrcweir 	implementationName = "com.sun.star.i18n.Transliteration.Transliteration_caseignore";
50*cdf0e10cSrcweir }
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir #if 0
53*cdf0e10cSrcweir /* NOTE: We had this, derived from Transliteration_caseignore, but it was
54*cdf0e10cSrcweir  * unused code. Deactivated with #i89580# but left for reference in case
55*cdf0e10cSrcweir  * MappingTypeSimpleFolding would be needed at some time.
56*cdf0e10cSrcweir  */
57*cdf0e10cSrcweir Transliteration_simplecaseignore::Transliteration_simplecaseignore()
58*cdf0e10cSrcweir {
59*cdf0e10cSrcweir 	nMappingType = MappingTypeSimpleFolding;
60*cdf0e10cSrcweir 	moduleLoaded = (TransliterationModules)0;
61*cdf0e10cSrcweir 	transliterationName = "simple case ignore (generic)";
62*cdf0e10cSrcweir 	implementationName = "com.sun.star.i18n.Transliteration.Transliteration_simplecaseignore";
63*cdf0e10cSrcweir }
64*cdf0e10cSrcweir #endif
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir void SAL_CALL
67*cdf0e10cSrcweir Transliteration_caseignore::loadModule( TransliterationModules modName, const Locale& rLocale )
68*cdf0e10cSrcweir 	throw(RuntimeException)
69*cdf0e10cSrcweir {
70*cdf0e10cSrcweir 	moduleLoaded = (TransliterationModules) (moduleLoaded|modName);
71*cdf0e10cSrcweir 	aLocale = rLocale;
72*cdf0e10cSrcweir }
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir sal_Int16 SAL_CALL Transliteration_caseignore::getType() throw(RuntimeException)
75*cdf0e10cSrcweir {
76*cdf0e10cSrcweir 	// It's NOT TransliterationType::ONE_TO_ONE because it's using casefolding
77*cdf0e10cSrcweir 	return TransliterationType::IGNORE;
78*cdf0e10cSrcweir }
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir Sequence< OUString > SAL_CALL
82*cdf0e10cSrcweir Transliteration_caseignore::transliterateRange( const OUString& str1, const OUString& str2 )
83*cdf0e10cSrcweir 	throw( RuntimeException)
84*cdf0e10cSrcweir {
85*cdf0e10cSrcweir 	if (str1.getLength() != 1 || str2.getLength() != 1)
86*cdf0e10cSrcweir 	    throw RuntimeException();
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir 	static Transliteration_u2l u2l;
89*cdf0e10cSrcweir 	static Transliteration_l2u l2u;
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir 	u2l.loadModule((TransliterationModules)0, aLocale);
92*cdf0e10cSrcweir 	l2u.loadModule((TransliterationModules)0, aLocale);
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir 	OUString l1 = u2l.transliterateString2String(str1, 0, str1.getLength());
95*cdf0e10cSrcweir 	OUString u1 = l2u.transliterateString2String(str1, 0, str1.getLength());
96*cdf0e10cSrcweir 	OUString l2 = u2l.transliterateString2String(str2, 0, str2.getLength());
97*cdf0e10cSrcweir 	OUString u2 = l2u.transliterateString2String(str2, 0, str2.getLength());
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir 	if ((l1 == u1) && (l2 == u2)) {
100*cdf0e10cSrcweir 	    Sequence< OUString > r(2);
101*cdf0e10cSrcweir 	    r[0] = l1;
102*cdf0e10cSrcweir 	    r[1] = l2;
103*cdf0e10cSrcweir 	    return r;
104*cdf0e10cSrcweir 	} else {
105*cdf0e10cSrcweir 	    Sequence< OUString > r(4);
106*cdf0e10cSrcweir 	    r[0] = l1;
107*cdf0e10cSrcweir 	    r[1] = l2;
108*cdf0e10cSrcweir 	    r[2] = u1;
109*cdf0e10cSrcweir 	    r[3] = u2;
110*cdf0e10cSrcweir 	    return r;
111*cdf0e10cSrcweir 	}
112*cdf0e10cSrcweir }
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir sal_Bool SAL_CALL
115*cdf0e10cSrcweir Transliteration_caseignore::equals(
116*cdf0e10cSrcweir 	const ::rtl::OUString& str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32& nMatch1,
117*cdf0e10cSrcweir 	const ::rtl::OUString& str2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32& nMatch2)
118*cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
119*cdf0e10cSrcweir {
120*cdf0e10cSrcweir 	return (compare(str1, pos1, nCount1, nMatch1, str2, pos2, nCount2, nMatch2) == 0);
121*cdf0e10cSrcweir }
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir sal_Int32 SAL_CALL
124*cdf0e10cSrcweir Transliteration_caseignore::compareSubstring(
125*cdf0e10cSrcweir 	const ::rtl::OUString& str1, sal_Int32 off1, sal_Int32 len1,
126*cdf0e10cSrcweir 	const ::rtl::OUString& str2, sal_Int32 off2, sal_Int32 len2)
127*cdf0e10cSrcweir 	throw(RuntimeException)
128*cdf0e10cSrcweir {
129*cdf0e10cSrcweir 	sal_Int32 nMatch1, nMatch2;
130*cdf0e10cSrcweir 	return compare(str1, off1, len1, nMatch1, str2, off2, len2, nMatch2);
131*cdf0e10cSrcweir }
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir sal_Int32 SAL_CALL
135*cdf0e10cSrcweir Transliteration_caseignore::compareString(
136*cdf0e10cSrcweir 	const ::rtl::OUString& str1,
137*cdf0e10cSrcweir 	const ::rtl::OUString& str2)
138*cdf0e10cSrcweir 	throw(RuntimeException)
139*cdf0e10cSrcweir {
140*cdf0e10cSrcweir 	sal_Int32 nMatch1, nMatch2;
141*cdf0e10cSrcweir 	return compare(str1, 0, str1.getLength(), nMatch1, str2, 0, str2.getLength(), nMatch2);
142*cdf0e10cSrcweir }
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir sal_Int32 SAL_CALL
145*cdf0e10cSrcweir Transliteration_caseignore::compare(
146*cdf0e10cSrcweir 	const ::rtl::OUString& str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32& nMatch1,
147*cdf0e10cSrcweir 	const ::rtl::OUString& str2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32& nMatch2)
148*cdf0e10cSrcweir 	throw(RuntimeException)
149*cdf0e10cSrcweir {
150*cdf0e10cSrcweir 	const sal_Unicode *unistr1 = (sal_Unicode*) str1.getStr() + pos1;
151*cdf0e10cSrcweir 	const sal_Unicode *unistr2 = (sal_Unicode*) str2.getStr() + pos2;
152*cdf0e10cSrcweir 	sal_Unicode c1, c2;
153*cdf0e10cSrcweir 	MappingElement e1, e2;
154*cdf0e10cSrcweir 	nMatch1 = nMatch2 = 0;
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir #define NOT_END_OF_STR1 (nMatch1 < nCount1 || e1.current < e1.element.nmap)
157*cdf0e10cSrcweir #define NOT_END_OF_STR2 (nMatch2 < nCount2 || e2.current < e2.element.nmap)
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 	while (NOT_END_OF_STR1 && NOT_END_OF_STR2) {
160*cdf0e10cSrcweir 	    c1 = casefolding::getNextChar(unistr1, nMatch1, nCount1, e1, aLocale, nMappingType, moduleLoaded);
161*cdf0e10cSrcweir 	    c2 = casefolding::getNextChar(unistr2, nMatch2, nCount2, e2, aLocale, nMappingType, moduleLoaded);
162*cdf0e10cSrcweir 	    if (c1 != c2) {
163*cdf0e10cSrcweir 		nMatch1--; nMatch2--;
164*cdf0e10cSrcweir 		return c1 > c2 ? 1 : -1;
165*cdf0e10cSrcweir 	    }
166*cdf0e10cSrcweir 	}
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir 	return (!NOT_END_OF_STR1 && !NOT_END_OF_STR2) ? 0
169*cdf0e10cSrcweir 				: (NOT_END_OF_STR1 ? 1 : -1);
170*cdf0e10cSrcweir }
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir } } } }
173