LibreOffice Module i18npool (master) 1
transliteration_caseignore.cxx
Go to the documentation of this file.
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#include <com/sun/star/i18n/TransliterationType.hpp>
21#include <rtl/ref.hxx>
22
25
27
28namespace com::sun::star::uno { class XComponentContext; }
29
30using namespace ::com::sun::star::uno;
31using namespace ::com::sun::star::i18n;
32using namespace ::com::sun::star::lang;
33
34namespace i18npool {
35
37{
38 nMappingType = MappingType::FullFolding;
39 moduleLoaded = TransliterationFlags::NONE;
40 transliterationName = "case ignore (generic)";
41 implementationName = "com.sun.star.i18n.Transliteration.IGNORE_CASE";
42}
43
44void SAL_CALL
45Transliteration_caseignore::loadModule( TransliterationModules modName, const Locale& rLocale )
46{
47 moduleLoaded |= static_cast<TransliterationFlags>(modName);
48 aLocale = rLocale;
49}
50
52{
53 // It's NOT TransliterationType::ONE_TO_ONE because it's using casefolding
54 return TransliterationType::IGNORE;
55}
56
57
58Sequence< OUString > SAL_CALL
59Transliteration_caseignore::transliterateRange( const OUString& str1, const OUString& str2 )
60{
61 if (str1.getLength() != 1 || str2.getLength() != 1)
62 throw RuntimeException();
63
66
67 u2l->loadModule(TransliterationModules(0), aLocale);
68 l2u->loadModule(TransliterationModules(0), aLocale);
69
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());
74
75 if ((l1 == u1) && (l2 == u2)) {
76 return { l1, l2 };
77 } else {
78 return { l1, l2, u1, u2 };
79 }
80}
81
82sal_Bool SAL_CALL
84 const OUString& str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32& nMatch1,
85 const OUString& str2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32& nMatch2)
86{
87 return (compare(str1, pos1, nCount1, nMatch1, str2, pos2, nCount2, nMatch2) == 0);
88}
89
90sal_Int32 SAL_CALL
92 const OUString& str1, sal_Int32 off1, sal_Int32 len1,
93 const OUString& str2, sal_Int32 off2, sal_Int32 len2)
94{
95 sal_Int32 nMatch1, nMatch2;
96 return compare(str1, off1, len1, nMatch1, str2, off2, len2, nMatch2);
97}
98
99
100sal_Int32 SAL_CALL
102 const OUString& str1,
103 const OUString& str2)
104{
105 sal_Int32 nMatch1, nMatch2;
106 return compare(str1, 0, str1.getLength(), nMatch1, str2, 0, str2.getLength(), nMatch2);
107}
108
109sal_Int32
111 const OUString& str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32& nMatch1,
112 const OUString& str2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32& nMatch2)
113{
114 const sal_Unicode *unistr1 = const_cast<sal_Unicode*>(str1.getStr()) + pos1;
115 const sal_Unicode *unistr2 = const_cast<sal_Unicode*>(str2.getStr()) + pos2;
116 sal_Unicode c1, c2;
118 nMatch1 = nMatch2 = 0;
119
120#define NOT_END_OF_STR1 (nMatch1 < nCount1 || e1.current < e1.element.nmap)
121#define NOT_END_OF_STR2 (nMatch2 < nCount2 || e2.current < e2.element.nmap)
122
124 c1 = i18nutil::casefolding::getNextChar(unistr1, nMatch1, nCount1, e1, aLocale, nMappingType, moduleLoaded);
125 c2 = i18nutil::casefolding::getNextChar(unistr2, nMatch2, nCount2, e2, aLocale, nMappingType, moduleLoaded);
126 if (c1 != c2) {
127 nMatch1--; nMatch2--;
128 return c1 > c2 ? 1 : -1;
129 }
130 }
131
132 return (!NOT_END_OF_STR1 && !NOT_END_OF_STR2) ? 0
133 : (NOT_END_OF_STR1 ? 1 : -1);
134}
135
136}
137
138extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
140 css::uno::XComponentContext *,
141 css::uno::Sequence<css::uno::Any> const &)
142{
143 return cppu::acquire(new i18npool::Transliteration_caseignore());
144}
145
146/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 SAL_CALL compareString(const OUString &s1, const OUString &s2) override
void SAL_CALL loadModule(css::i18n::TransliterationModules modName, const css::lang::Locale &rLocale) override
css::uno::Sequence< OUString > SAL_CALL transliterateRange(const OUString &str1, const OUString &str2) override
sal_Int32 compare(const OUString &str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32 &nMatch1, const OUString &str2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32 &nMatch2)
sal_Bool SAL_CALL equals(const OUString &str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32 &nMatch1, const OUString &src2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32 &nMatch2) override
sal_Int32 SAL_CALL compareSubstring(const OUString &s1, sal_Int32 off1, sal_Int32 len1, const OUString &s2, sal_Int32 off2, sal_Int32 len2) override
Constant values shared between i18npool and, for example, the number formatter.
TransliterationFlags
#define NOT_END_OF_STR1
#define NOT_END_OF_STR2
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_i18n_Transliteration_IGNORE_CASE_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
unsigned char sal_Bool
sal_uInt16 sal_Unicode