1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
19 #ifndef INCLUDED_I18NUTIL_SEARCHOPT_HXX
20 #define INCLUDED_I18NUTIL_SEARCHOPT_HXX
22 #include <sal/types.h>
23 #include <com/sun/star/lang/Locale.hpp>
24 #include <com/sun/star/util/SearchAlgorithms.hpp>
25 #include <com/sun/star/util/SearchAlgorithms2.hpp>
26 #include <com/sun/star/util/SearchOptions2.hpp>
27 #include <i18nutil/transliteration.hxx>
33 inline constexpr css::util::SearchAlgorithms
downgradeSearchAlgorithms2(sal_Int16 searchAlgorithms2
)
35 switch (searchAlgorithms2
)
37 case css::util::SearchAlgorithms2::ABSOLUTE
:
38 return css::util::SearchAlgorithms_ABSOLUTE
;
39 case css::util::SearchAlgorithms2::REGEXP
:
40 return css::util::SearchAlgorithms_REGEXP
;
41 case css::util::SearchAlgorithms2::APPROXIMATE
:
42 return css::util::SearchAlgorithms_APPROXIMATE
;
43 default: // default what?
44 case css::util::SearchAlgorithms2::WILDCARD
: // something valid
45 return css::util::SearchAlgorithms_ABSOLUTE
;
49 inline constexpr sal_Int16
upgradeSearchAlgorithms(css::util::SearchAlgorithms searchAlgorithms
)
51 switch (searchAlgorithms
)
53 default: // default what?
54 case css::util::SearchAlgorithms_ABSOLUTE
:
55 return css::util::SearchAlgorithms2::ABSOLUTE
;
56 case css::util::SearchAlgorithms_REGEXP
:
57 return css::util::SearchAlgorithms2::REGEXP
;
58 case css::util::SearchAlgorithms_APPROXIMATE
:
59 return css::util::SearchAlgorithms2::APPROXIMATE
;
64 * This is a wrapper around com::sun::star::util::SearchOptions and SearchOptions2,
65 * but using the more type-safe TransliterationFlags enum, and without obsolete
66 * algorithmType, which is superseded by AlgorithmType2.
68 struct SAL_WARN_UNUSED SearchOptions2
{
70 OUString searchString
;
71 OUString replaceString
;
72 css::lang::Locale Locale
;
73 sal_Int32 changedChars
;
74 sal_Int32 deletedChars
;
75 sal_Int32 insertedChars
;
76 TransliterationFlags transliterateFlags
;
78 sal_Int16 AlgorithmType2
;
79 sal_Int32 WildcardEscapeCharacter
;
81 SearchOptions2
& operator=(css::util::SearchOptions2
const & other
)
83 searchFlag
= other
.searchFlag
;
84 searchString
= other
.searchString
;
85 replaceString
= other
.replaceString
;
86 Locale
= other
.Locale
;
87 changedChars
= other
.changedChars
;
88 deletedChars
= other
.deletedChars
;
89 insertedChars
= other
.insertedChars
;
90 transliterateFlags
= static_cast<TransliterationFlags
>(other
.transliterateFlags
);
91 AlgorithmType2
= other
.AlgorithmType2
;
92 WildcardEscapeCharacter
= other
.WildcardEscapeCharacter
;
96 css::util::SearchOptions2
toUnoSearchOptions2() const
98 return css::util::SearchOptions2(downgradeSearchAlgorithms2(AlgorithmType2
), searchFlag
,
99 searchString
, replaceString
,
101 changedChars
, deletedChars
, insertedChars
,
102 static_cast<sal_Int32
>(transliterateFlags
),
103 AlgorithmType2
, WildcardEscapeCharacter
);
111 , transliterateFlags(TransliterationFlags::NONE
)
113 , WildcardEscapeCharacter(0)
116 SearchOptions2(const sal_Int32 searchFlag_
,
117 OUString searchString_
, OUString replaceString_
,
118 css::lang::Locale Locale_
,
119 const sal_Int32 changedChars_
, const sal_Int32 deletedChars_
, const sal_Int32 insertedChars_
,
120 const TransliterationFlags
& transliterateFlags_
,
121 const sal_Int16 AlgorithmType2_
, const sal_Int32 WildcardEscapeCharacter_
)
122 : searchFlag(searchFlag_
)
123 , searchString(std::move(searchString_
))
124 , replaceString(std::move(replaceString_
))
125 , Locale(std::move(Locale_
))
126 , changedChars(changedChars_
)
127 , deletedChars(deletedChars_
)
128 , insertedChars(insertedChars_
)
129 , transliterateFlags(transliterateFlags_
)
130 , AlgorithmType2(AlgorithmType2_
)
131 , WildcardEscapeCharacter(WildcardEscapeCharacter_
)
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */