1*449ab281SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*449ab281SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*449ab281SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*449ab281SAndrew Rist  * distributed with this work for additional information
6*449ab281SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*449ab281SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*449ab281SAndrew Rist  * "License"); you may not use this file except in compliance
9*449ab281SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*449ab281SAndrew Rist  *
11*449ab281SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*449ab281SAndrew Rist  *
13*449ab281SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*449ab281SAndrew Rist  * software distributed under the License is distributed on an
15*449ab281SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*449ab281SAndrew Rist  * KIND, either express or implied.  See the License for the
17*449ab281SAndrew Rist  * specific language governing permissions and limitations
18*449ab281SAndrew Rist  * under the License.
19*449ab281SAndrew Rist  *
20*449ab281SAndrew Rist  *************************************************************/
21*449ab281SAndrew Rist 
22*449ab281SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_i18npool.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir // prevent internal compiler error with MSVC6SP3
28cdf0e10cSrcweir #include <utility>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <i18nutil/oneToOneMapping.hxx>
31cdf0e10cSrcweir #include <i18nutil/casefolding.hxx>
32cdf0e10cSrcweir #include "transliteration_caseignore.hxx"
33cdf0e10cSrcweir 
34cdf0e10cSrcweir using namespace ::com::sun::star::uno;
35cdf0e10cSrcweir using namespace ::com::sun::star::lang;
36cdf0e10cSrcweir using namespace ::rtl;
37cdf0e10cSrcweir 
38cdf0e10cSrcweir namespace com { namespace sun { namespace star { namespace i18n {
39cdf0e10cSrcweir 
Transliteration_caseignore()40cdf0e10cSrcweir Transliteration_caseignore::Transliteration_caseignore()
41cdf0e10cSrcweir {
42cdf0e10cSrcweir 	nMappingType = MappingTypeFullFolding;
43cdf0e10cSrcweir 	moduleLoaded = (TransliterationModules)0;
44cdf0e10cSrcweir 	transliterationName = "case ignore (generic)";
45cdf0e10cSrcweir 	implementationName = "com.sun.star.i18n.Transliteration.Transliteration_caseignore";
46cdf0e10cSrcweir }
47cdf0e10cSrcweir 
48cdf0e10cSrcweir #if 0
49cdf0e10cSrcweir /* NOTE: We had this, derived from Transliteration_caseignore, but it was
50cdf0e10cSrcweir  * unused code. Deactivated with #i89580# but left for reference in case
51cdf0e10cSrcweir  * MappingTypeSimpleFolding would be needed at some time.
52cdf0e10cSrcweir  */
53cdf0e10cSrcweir Transliteration_simplecaseignore::Transliteration_simplecaseignore()
54cdf0e10cSrcweir {
55cdf0e10cSrcweir 	nMappingType = MappingTypeSimpleFolding;
56cdf0e10cSrcweir 	moduleLoaded = (TransliterationModules)0;
57cdf0e10cSrcweir 	transliterationName = "simple case ignore (generic)";
58cdf0e10cSrcweir 	implementationName = "com.sun.star.i18n.Transliteration.Transliteration_simplecaseignore";
59cdf0e10cSrcweir }
60cdf0e10cSrcweir #endif
61cdf0e10cSrcweir 
62cdf0e10cSrcweir void SAL_CALL
loadModule(TransliterationModules modName,const Locale & rLocale)63cdf0e10cSrcweir Transliteration_caseignore::loadModule( TransliterationModules modName, const Locale& rLocale )
64cdf0e10cSrcweir 	throw(RuntimeException)
65cdf0e10cSrcweir {
66cdf0e10cSrcweir 	moduleLoaded = (TransliterationModules) (moduleLoaded|modName);
67cdf0e10cSrcweir 	aLocale = rLocale;
68cdf0e10cSrcweir }
69cdf0e10cSrcweir 
getType()70cdf0e10cSrcweir sal_Int16 SAL_CALL Transliteration_caseignore::getType() throw(RuntimeException)
71cdf0e10cSrcweir {
72cdf0e10cSrcweir 	// It's NOT TransliterationType::ONE_TO_ONE because it's using casefolding
73cdf0e10cSrcweir 	return TransliterationType::IGNORE;
74cdf0e10cSrcweir }
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 
77cdf0e10cSrcweir Sequence< OUString > SAL_CALL
transliterateRange(const OUString & str1,const OUString & str2)78cdf0e10cSrcweir Transliteration_caseignore::transliterateRange( const OUString& str1, const OUString& str2 )
79cdf0e10cSrcweir 	throw( RuntimeException)
80cdf0e10cSrcweir {
81cdf0e10cSrcweir 	if (str1.getLength() != 1 || str2.getLength() != 1)
82cdf0e10cSrcweir 	    throw RuntimeException();
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 	static Transliteration_u2l u2l;
85cdf0e10cSrcweir 	static Transliteration_l2u l2u;
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 	u2l.loadModule((TransliterationModules)0, aLocale);
88cdf0e10cSrcweir 	l2u.loadModule((TransliterationModules)0, aLocale);
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 	OUString l1 = u2l.transliterateString2String(str1, 0, str1.getLength());
91cdf0e10cSrcweir 	OUString u1 = l2u.transliterateString2String(str1, 0, str1.getLength());
92cdf0e10cSrcweir 	OUString l2 = u2l.transliterateString2String(str2, 0, str2.getLength());
93cdf0e10cSrcweir 	OUString u2 = l2u.transliterateString2String(str2, 0, str2.getLength());
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 	if ((l1 == u1) && (l2 == u2)) {
96cdf0e10cSrcweir 	    Sequence< OUString > r(2);
97cdf0e10cSrcweir 	    r[0] = l1;
98cdf0e10cSrcweir 	    r[1] = l2;
99cdf0e10cSrcweir 	    return r;
100cdf0e10cSrcweir 	} else {
101cdf0e10cSrcweir 	    Sequence< OUString > r(4);
102cdf0e10cSrcweir 	    r[0] = l1;
103cdf0e10cSrcweir 	    r[1] = l2;
104cdf0e10cSrcweir 	    r[2] = u1;
105cdf0e10cSrcweir 	    r[3] = u2;
106cdf0e10cSrcweir 	    return r;
107cdf0e10cSrcweir 	}
108cdf0e10cSrcweir }
109cdf0e10cSrcweir 
110cdf0e10cSrcweir sal_Bool SAL_CALL
equals(const::rtl::OUString & str1,sal_Int32 pos1,sal_Int32 nCount1,sal_Int32 & nMatch1,const::rtl::OUString & str2,sal_Int32 pos2,sal_Int32 nCount2,sal_Int32 & nMatch2)111cdf0e10cSrcweir Transliteration_caseignore::equals(
112cdf0e10cSrcweir 	const ::rtl::OUString& str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32& nMatch1,
113cdf0e10cSrcweir 	const ::rtl::OUString& str2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32& nMatch2)
114cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
115cdf0e10cSrcweir {
116cdf0e10cSrcweir 	return (compare(str1, pos1, nCount1, nMatch1, str2, pos2, nCount2, nMatch2) == 0);
117cdf0e10cSrcweir }
118cdf0e10cSrcweir 
119cdf0e10cSrcweir sal_Int32 SAL_CALL
compareSubstring(const::rtl::OUString & str1,sal_Int32 off1,sal_Int32 len1,const::rtl::OUString & str2,sal_Int32 off2,sal_Int32 len2)120cdf0e10cSrcweir Transliteration_caseignore::compareSubstring(
121cdf0e10cSrcweir 	const ::rtl::OUString& str1, sal_Int32 off1, sal_Int32 len1,
122cdf0e10cSrcweir 	const ::rtl::OUString& str2, sal_Int32 off2, sal_Int32 len2)
123cdf0e10cSrcweir 	throw(RuntimeException)
124cdf0e10cSrcweir {
125cdf0e10cSrcweir 	sal_Int32 nMatch1, nMatch2;
126cdf0e10cSrcweir 	return compare(str1, off1, len1, nMatch1, str2, off2, len2, nMatch2);
127cdf0e10cSrcweir }
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 
130cdf0e10cSrcweir sal_Int32 SAL_CALL
compareString(const::rtl::OUString & str1,const::rtl::OUString & str2)131cdf0e10cSrcweir Transliteration_caseignore::compareString(
132cdf0e10cSrcweir 	const ::rtl::OUString& str1,
133cdf0e10cSrcweir 	const ::rtl::OUString& str2)
134cdf0e10cSrcweir 	throw(RuntimeException)
135cdf0e10cSrcweir {
136cdf0e10cSrcweir 	sal_Int32 nMatch1, nMatch2;
137cdf0e10cSrcweir 	return compare(str1, 0, str1.getLength(), nMatch1, str2, 0, str2.getLength(), nMatch2);
138cdf0e10cSrcweir }
139cdf0e10cSrcweir 
140cdf0e10cSrcweir sal_Int32 SAL_CALL
compare(const::rtl::OUString & str1,sal_Int32 pos1,sal_Int32 nCount1,sal_Int32 & nMatch1,const::rtl::OUString & str2,sal_Int32 pos2,sal_Int32 nCount2,sal_Int32 & nMatch2)141cdf0e10cSrcweir Transliteration_caseignore::compare(
142cdf0e10cSrcweir 	const ::rtl::OUString& str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32& nMatch1,
143cdf0e10cSrcweir 	const ::rtl::OUString& str2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32& nMatch2)
144cdf0e10cSrcweir 	throw(RuntimeException)
145cdf0e10cSrcweir {
146cdf0e10cSrcweir 	const sal_Unicode *unistr1 = (sal_Unicode*) str1.getStr() + pos1;
147cdf0e10cSrcweir 	const sal_Unicode *unistr2 = (sal_Unicode*) str2.getStr() + pos2;
148cdf0e10cSrcweir 	sal_Unicode c1, c2;
149cdf0e10cSrcweir 	MappingElement e1, e2;
150cdf0e10cSrcweir 	nMatch1 = nMatch2 = 0;
151cdf0e10cSrcweir 
152cdf0e10cSrcweir #define NOT_END_OF_STR1 (nMatch1 < nCount1 || e1.current < e1.element.nmap)
153cdf0e10cSrcweir #define NOT_END_OF_STR2 (nMatch2 < nCount2 || e2.current < e2.element.nmap)
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 	while (NOT_END_OF_STR1 && NOT_END_OF_STR2) {
156cdf0e10cSrcweir 	    c1 = casefolding::getNextChar(unistr1, nMatch1, nCount1, e1, aLocale, nMappingType, moduleLoaded);
157cdf0e10cSrcweir 	    c2 = casefolding::getNextChar(unistr2, nMatch2, nCount2, e2, aLocale, nMappingType, moduleLoaded);
158cdf0e10cSrcweir 	    if (c1 != c2) {
159cdf0e10cSrcweir 		nMatch1--; nMatch2--;
160cdf0e10cSrcweir 		return c1 > c2 ? 1 : -1;
161cdf0e10cSrcweir 	    }
162cdf0e10cSrcweir 	}
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 	return (!NOT_END_OF_STR1 && !NOT_END_OF_STR2) ? 0
165cdf0e10cSrcweir 				: (NOT_END_OF_STR1 ? 1 : -1);
166cdf0e10cSrcweir }
167cdf0e10cSrcweir 
168cdf0e10cSrcweir } } } }
169