bump product version to 6.3.0.0.beta1
[LibreOffice.git] / i18npool / source / transliteration / transliteration_caseignore.cxx
blob61db2286e7145174161793d8eecc16217d5065cb
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/i18n/TransliterationType.hpp>
21 #include <rtl/ref.hxx>
23 #include <i18nutil/casefolding.hxx>
24 #include <i18nutil/transliteration.hxx>
26 #include <transliteration_caseignore.hxx>
28 namespace com::sun::star::uno { class XComponentContext; }
30 using namespace ::com::sun::star::uno;
31 using namespace ::com::sun::star::i18n;
32 using namespace ::com::sun::star::lang;
34 namespace i18npool {
36 Transliteration_caseignore::Transliteration_caseignore()
38 nMappingType = MappingType::FullFolding;
39 moduleLoaded = TransliterationFlags::NONE;
40 transliterationName = "case ignore (generic)";
41 implementationName = "com.sun.star.i18n.Transliteration.Transliteration_caseignore";
44 void SAL_CALL
45 Transliteration_caseignore::loadModule( TransliterationModules modName, const Locale& rLocale )
47 moduleLoaded |= static_cast<TransliterationFlags>(modName);
48 aLocale = rLocale;
51 sal_Int16 SAL_CALL Transliteration_caseignore::getType()
53 // It's NOT TransliterationType::ONE_TO_ONE because it's using casefolding
54 return TransliterationType::IGNORE;
58 Sequence< OUString > SAL_CALL
59 Transliteration_caseignore::transliterateRange( const OUString& str1, const OUString& str2 )
61 if (str1.getLength() != 1 || str2.getLength() != 1)
62 throw RuntimeException();
64 static rtl::Reference< Transliteration_u2l > u2l(new Transliteration_u2l);
65 static rtl::Reference< Transliteration_l2u > l2u(new Transliteration_l2u);
67 u2l->loadModule(TransliterationModules(0), aLocale);
68 l2u->loadModule(TransliterationModules(0), aLocale);
70 OUString l1 = u2l->transliterateString2String(str1, 0, str1.getLength());
71 OUString u1 = l2u->transliterateString2String(str1, 0, str1.getLength());
72 OUString l2 = u2l->transliterateString2String(str2, 0, str2.getLength());
73 OUString u2 = l2u->transliterateString2String(str2, 0, str2.getLength());
75 if ((l1 == u1) && (l2 == u2)) {
76 Sequence< OUString > r(2);
77 r[0] = l1;
78 r[1] = l2;
79 return r;
80 } else {
81 Sequence< OUString > r(4);
82 r[0] = l1;
83 r[1] = l2;
84 r[2] = u1;
85 r[3] = u2;
86 return r;
90 sal_Bool SAL_CALL
91 Transliteration_caseignore::equals(
92 const OUString& str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32& nMatch1,
93 const OUString& str2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32& nMatch2)
95 return (compare(str1, pos1, nCount1, nMatch1, str2, pos2, nCount2, nMatch2) == 0);
98 sal_Int32 SAL_CALL
99 Transliteration_caseignore::compareSubstring(
100 const OUString& str1, sal_Int32 off1, sal_Int32 len1,
101 const OUString& str2, sal_Int32 off2, sal_Int32 len2)
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)
113 sal_Int32 nMatch1, nMatch2;
114 return compare(str1, 0, str1.getLength(), nMatch1, str2, 0, str2.getLength(), nMatch2);
117 sal_Int32
118 Transliteration_caseignore::compare(
119 const OUString& str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32& nMatch1,
120 const OUString& str2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32& nMatch2)
122 const sal_Unicode *unistr1 = const_cast<sal_Unicode*>(str1.getStr()) + pos1;
123 const sal_Unicode *unistr2 = const_cast<sal_Unicode*>(str2.getStr()) + pos2;
124 sal_Unicode c1, c2;
125 i18nutil::MappingElement e1, e2;
126 nMatch1 = nMatch2 = 0;
128 #define NOT_END_OF_STR1 (nMatch1 < nCount1 || e1.current < e1.element.nmap)
129 #define NOT_END_OF_STR2 (nMatch2 < nCount2 || e2.current < e2.element.nmap)
131 while (NOT_END_OF_STR1 && NOT_END_OF_STR2) {
132 c1 = i18nutil::casefolding::getNextChar(unistr1, nMatch1, nCount1, e1, aLocale, nMappingType, moduleLoaded);
133 c2 = i18nutil::casefolding::getNextChar(unistr2, nMatch2, nCount2, e2, aLocale, nMappingType, moduleLoaded);
134 if (c1 != c2) {
135 nMatch1--; nMatch2--;
136 return c1 > c2 ? 1 : -1;
140 return (!NOT_END_OF_STR1 && !NOT_END_OF_STR2) ? 0
141 : (NOT_END_OF_STR1 ? 1 : -1);
146 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
147 com_sun_star_i18n_Transliteration_IGNORE_CASE_get_implementation(
148 css::uno::XComponentContext *,
149 css::uno::Sequence<css::uno::Any> const &)
151 return cppu::acquire(new i18npool::Transliteration_caseignore());
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */