lok: Don't attempt to select the exact text after a failed search.
[LibreOffice.git] / i18npool / source / transliteration / transliteration_caseignore.cxx
blobdcfefe3f6d5ab97713c836205f0585a21df01355
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/uno/XComponentContext.hpp>
22 #include <i18nutil/oneToOneMapping.hxx>
23 #include <i18nutil/casefolding.hxx>
25 #include "transliteration_caseignore.hxx"
27 using namespace ::com::sun::star::uno;
28 using namespace ::com::sun::star::lang;
30 namespace com { namespace sun { namespace star { namespace i18n {
32 Transliteration_caseignore::Transliteration_caseignore()
34 nMappingType = MappingTypeFullFolding;
35 moduleLoaded = (TransliterationModules)0;
36 transliterationName = "case ignore (generic)";
37 implementationName = "com.sun.star.i18n.Transliteration.Transliteration_caseignore";
40 void SAL_CALL
41 Transliteration_caseignore::loadModule( TransliterationModules modName, const Locale& rLocale )
42 throw(RuntimeException, std::exception)
44 moduleLoaded = (TransliterationModules) (moduleLoaded|modName);
45 aLocale = rLocale;
48 sal_Int16 SAL_CALL Transliteration_caseignore::getType() throw(RuntimeException, std::exception)
50 // It's NOT TransliterationType::ONE_TO_ONE because it's using casefolding
51 return TransliterationType::IGNORE;
55 Sequence< OUString > SAL_CALL
56 Transliteration_caseignore::transliterateRange( const OUString& str1, const OUString& str2 )
57 throw( RuntimeException, std::exception)
59 if (str1.getLength() != 1 || str2.getLength() != 1)
60 throw RuntimeException();
62 static Transliteration_u2l u2l;
63 static Transliteration_l2u l2u;
65 u2l.loadModule((TransliterationModules)0, aLocale);
66 l2u.loadModule((TransliterationModules)0, aLocale);
68 OUString l1 = u2l.transliterateString2String(str1, 0, str1.getLength());
69 OUString u1 = l2u.transliterateString2String(str1, 0, str1.getLength());
70 OUString l2 = u2l.transliterateString2String(str2, 0, str2.getLength());
71 OUString u2 = l2u.transliterateString2String(str2, 0, str2.getLength());
73 if ((l1 == u1) && (l2 == u2)) {
74 Sequence< OUString > r(2);
75 r[0] = l1;
76 r[1] = l2;
77 return r;
78 } else {
79 Sequence< OUString > r(4);
80 r[0] = l1;
81 r[1] = l2;
82 r[2] = u1;
83 r[3] = u2;
84 return r;
88 sal_Bool SAL_CALL
89 Transliteration_caseignore::equals(
90 const OUString& str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32& nMatch1,
91 const OUString& str2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32& nMatch2)
92 throw(::com::sun::star::uno::RuntimeException, std::exception)
94 return (compare(str1, pos1, nCount1, nMatch1, str2, pos2, nCount2, nMatch2) == 0);
97 sal_Int32 SAL_CALL
98 Transliteration_caseignore::compareSubstring(
99 const OUString& str1, sal_Int32 off1, sal_Int32 len1,
100 const OUString& str2, sal_Int32 off2, sal_Int32 len2)
101 throw(RuntimeException, std::exception)
103 sal_Int32 nMatch1, nMatch2;
104 return compare(str1, off1, len1, nMatch1, str2, off2, len2, nMatch2);
108 sal_Int32 SAL_CALL
109 Transliteration_caseignore::compareString(
110 const OUString& str1,
111 const OUString& str2)
112 throw(RuntimeException, std::exception)
114 sal_Int32 nMatch1, nMatch2;
115 return compare(str1, 0, str1.getLength(), nMatch1, str2, 0, str2.getLength(), nMatch2);
118 sal_Int32 SAL_CALL
119 Transliteration_caseignore::compare(
120 const OUString& str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32& nMatch1,
121 const OUString& str2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32& nMatch2)
122 throw(RuntimeException)
124 const sal_Unicode *unistr1 = const_cast<sal_Unicode*>(str1.getStr()) + pos1;
125 const sal_Unicode *unistr2 = const_cast<sal_Unicode*>(str2.getStr()) + pos2;
126 sal_Unicode c1, c2;
127 MappingElement e1, e2;
128 nMatch1 = nMatch2 = 0;
130 #define NOT_END_OF_STR1 (nMatch1 < nCount1 || e1.current < e1.element.nmap)
131 #define NOT_END_OF_STR2 (nMatch2 < nCount2 || e2.current < e2.element.nmap)
133 while (NOT_END_OF_STR1 && NOT_END_OF_STR2) {
134 c1 = casefolding::getNextChar(unistr1, nMatch1, nCount1, e1, aLocale, nMappingType, moduleLoaded);
135 c2 = casefolding::getNextChar(unistr2, nMatch2, nCount2, e2, aLocale, nMappingType, moduleLoaded);
136 if (c1 != c2) {
137 nMatch1--; nMatch2--;
138 return c1 > c2 ? 1 : -1;
142 return (!NOT_END_OF_STR1 && !NOT_END_OF_STR2) ? 0
143 : (NOT_END_OF_STR1 ? 1 : -1);
146 } } } }
148 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
149 com_sun_star_i18n_Transliteration_IGNORE_CASE_get_implementation(
150 css::uno::XComponentContext *,
151 css::uno::Sequence<css::uno::Any> const &)
153 return cppu::acquire(new css::i18n::Transliteration_caseignore());
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */