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