Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : // prevent internal compiler error with MSVC6SP3
22 : #include <utility>
23 :
24 : #include <i18nutil/oneToOneMapping.hxx>
25 : #include <i18nutil/casefolding.hxx>
26 : #include "transliteration_caseignore.hxx"
27 :
28 : using namespace ::com::sun::star::uno;
29 : using namespace ::com::sun::star::lang;
30 : using namespace ::rtl;
31 :
32 : namespace com { namespace sun { namespace star { namespace i18n {
33 :
34 14 : Transliteration_caseignore::Transliteration_caseignore()
35 : {
36 14 : nMappingType = MappingTypeFullFolding;
37 14 : moduleLoaded = (TransliterationModules)0;
38 14 : transliterationName = "case ignore (generic)";
39 14 : implementationName = "com.sun.star.i18n.Transliteration.Transliteration_caseignore";
40 14 : }
41 :
42 : void SAL_CALL
43 138 : Transliteration_caseignore::loadModule( TransliterationModules modName, const Locale& rLocale )
44 : throw(RuntimeException)
45 : {
46 138 : moduleLoaded = (TransliterationModules) (moduleLoaded|modName);
47 138 : aLocale = rLocale;
48 138 : }
49 :
50 0 : sal_Int16 SAL_CALL Transliteration_caseignore::getType() throw(RuntimeException)
51 : {
52 : // It's NOT TransliterationType::ONE_TO_ONE because it's using casefolding
53 0 : return TransliterationType::IGNORE;
54 : }
55 :
56 :
57 : Sequence< OUString > SAL_CALL
58 0 : Transliteration_caseignore::transliterateRange( const OUString& str1, const OUString& str2 )
59 : throw( RuntimeException)
60 : {
61 0 : if (str1.getLength() != 1 || str2.getLength() != 1)
62 0 : throw RuntimeException();
63 :
64 0 : static Transliteration_u2l u2l;
65 0 : static Transliteration_l2u l2u;
66 :
67 0 : u2l.loadModule((TransliterationModules)0, aLocale);
68 0 : l2u.loadModule((TransliterationModules)0, aLocale);
69 :
70 0 : OUString l1 = u2l.transliterateString2String(str1, 0, str1.getLength());
71 0 : OUString u1 = l2u.transliterateString2String(str1, 0, str1.getLength());
72 0 : OUString l2 = u2l.transliterateString2String(str2, 0, str2.getLength());
73 0 : OUString u2 = l2u.transliterateString2String(str2, 0, str2.getLength());
74 :
75 0 : if ((l1 == u1) && (l2 == u2)) {
76 0 : Sequence< OUString > r(2);
77 0 : r[0] = l1;
78 0 : r[1] = l2;
79 0 : return r;
80 : } else {
81 0 : Sequence< OUString > r(4);
82 0 : r[0] = l1;
83 0 : r[1] = l2;
84 0 : r[2] = u1;
85 0 : r[3] = u2;
86 0 : return r;
87 0 : }
88 : }
89 :
90 : sal_Bool SAL_CALL
91 1439 : Transliteration_caseignore::equals(
92 : const ::rtl::OUString& str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32& nMatch1,
93 : const ::rtl::OUString& str2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32& nMatch2)
94 : throw(::com::sun::star::uno::RuntimeException)
95 : {
96 1439 : return (compare(str1, pos1, nCount1, nMatch1, str2, pos2, nCount2, nMatch2) == 0);
97 : }
98 :
99 : sal_Int32 SAL_CALL
100 0 : Transliteration_caseignore::compareSubstring(
101 : const ::rtl::OUString& str1, sal_Int32 off1, sal_Int32 len1,
102 : const ::rtl::OUString& str2, sal_Int32 off2, sal_Int32 len2)
103 : throw(RuntimeException)
104 : {
105 : sal_Int32 nMatch1, nMatch2;
106 0 : return compare(str1, off1, len1, nMatch1, str2, off2, len2, nMatch2);
107 : }
108 :
109 :
110 : sal_Int32 SAL_CALL
111 3 : Transliteration_caseignore::compareString(
112 : const ::rtl::OUString& str1,
113 : const ::rtl::OUString& str2)
114 : throw(RuntimeException)
115 : {
116 : sal_Int32 nMatch1, nMatch2;
117 3 : return compare(str1, 0, str1.getLength(), nMatch1, str2, 0, str2.getLength(), nMatch2);
118 : }
119 :
120 : sal_Int32 SAL_CALL
121 1442 : Transliteration_caseignore::compare(
122 : const ::rtl::OUString& str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32& nMatch1,
123 : const ::rtl::OUString& str2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32& nMatch2)
124 : throw(RuntimeException)
125 : {
126 1442 : const sal_Unicode *unistr1 = (sal_Unicode*) str1.getStr() + pos1;
127 1442 : const sal_Unicode *unistr2 = (sal_Unicode*) str2.getStr() + pos2;
128 : sal_Unicode c1, c2;
129 1442 : MappingElement e1, e2;
130 1442 : nMatch1 = nMatch2 = 0;
131 :
132 : #define NOT_END_OF_STR1 (nMatch1 < nCount1 || e1.current < e1.element.nmap)
133 : #define NOT_END_OF_STR2 (nMatch2 < nCount2 || e2.current < e2.element.nmap)
134 :
135 5136 : while (NOT_END_OF_STR1 && NOT_END_OF_STR2) {
136 3440 : c1 = casefolding::getNextChar(unistr1, nMatch1, nCount1, e1, aLocale, nMappingType, moduleLoaded);
137 3440 : c2 = casefolding::getNextChar(unistr2, nMatch2, nCount2, e2, aLocale, nMappingType, moduleLoaded);
138 3440 : if (c1 != c2) {
139 1188 : nMatch1--; nMatch2--;
140 1188 : return c1 > c2 ? 1 : -1;
141 : }
142 : }
143 :
144 740 : return (!NOT_END_OF_STR1 && !NOT_END_OF_STR2) ? 0
145 514 : : (NOT_END_OF_STR1 ? 1 : -1);
146 : }
147 :
148 : } } } }
149 :
150 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|