/src/libreoffice/include/i18nutil/searchopt.hxx
Line | Count | Source |
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 | | #ifndef INCLUDED_I18NUTIL_SEARCHOPT_HXX |
20 | | #define INCLUDED_I18NUTIL_SEARCHOPT_HXX |
21 | | |
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> |
28 | | #include <utility> |
29 | | |
30 | | namespace i18nutil |
31 | | { |
32 | | |
33 | | inline constexpr css::util::SearchAlgorithms downgradeSearchAlgorithms2(sal_Int16 searchAlgorithms2) |
34 | 3 | { |
35 | 3 | switch (searchAlgorithms2) |
36 | 3 | { |
37 | 1 | case css::util::SearchAlgorithms2::ABSOLUTE: |
38 | 1 | return css::util::SearchAlgorithms_ABSOLUTE; |
39 | 0 | case css::util::SearchAlgorithms2::REGEXP: |
40 | 0 | return css::util::SearchAlgorithms_REGEXP; |
41 | 0 | case css::util::SearchAlgorithms2::APPROXIMATE: |
42 | 0 | return css::util::SearchAlgorithms_APPROXIMATE; |
43 | 0 | default: // default what? |
44 | 2 | case css::util::SearchAlgorithms2::WILDCARD: // something valid |
45 | 2 | return css::util::SearchAlgorithms_ABSOLUTE; |
46 | 3 | } |
47 | 3 | } |
48 | | |
49 | | inline constexpr sal_Int16 upgradeSearchAlgorithms(css::util::SearchAlgorithms searchAlgorithms) |
50 | 0 | { |
51 | 0 | switch (searchAlgorithms) |
52 | 0 | { |
53 | 0 | default: // default what? |
54 | 0 | case css::util::SearchAlgorithms_ABSOLUTE: |
55 | 0 | return css::util::SearchAlgorithms2::ABSOLUTE; |
56 | 0 | case css::util::SearchAlgorithms_REGEXP: |
57 | 0 | return css::util::SearchAlgorithms2::REGEXP; |
58 | 0 | case css::util::SearchAlgorithms_APPROXIMATE: |
59 | 0 | return css::util::SearchAlgorithms2::APPROXIMATE; |
60 | 0 | } |
61 | 0 | } |
62 | | |
63 | | /** |
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. |
67 | | */ |
68 | | struct SAL_WARN_UNUSED SearchOptions2 { |
69 | | sal_Int32 searchFlag; |
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; |
77 | | |
78 | | sal_Int16 AlgorithmType2; |
79 | | sal_Int32 WildcardEscapeCharacter; |
80 | | |
81 | | SearchOptions2& operator=(css::util::SearchOptions2 const & other) |
82 | 0 | { |
83 | 0 | searchFlag = other.searchFlag; |
84 | 0 | searchString = other.searchString; |
85 | 0 | replaceString = other.replaceString; |
86 | 0 | Locale = other.Locale; |
87 | 0 | changedChars = other.changedChars; |
88 | 0 | deletedChars = other.deletedChars; |
89 | 0 | insertedChars = other.insertedChars; |
90 | 0 | transliterateFlags = static_cast<TransliterationFlags>(other.transliterateFlags); |
91 | 0 | AlgorithmType2 = other.AlgorithmType2; |
92 | 0 | WildcardEscapeCharacter = other.WildcardEscapeCharacter; |
93 | 0 | return *this; |
94 | 0 | } |
95 | | |
96 | | css::util::SearchOptions2 toUnoSearchOptions2() const |
97 | 3 | { |
98 | 3 | return css::util::SearchOptions2(downgradeSearchAlgorithms2(AlgorithmType2), searchFlag, |
99 | 3 | searchString, replaceString, |
100 | 3 | Locale, |
101 | 3 | changedChars, deletedChars, insertedChars, |
102 | 3 | static_cast<sal_Int32>(transliterateFlags), |
103 | 3 | AlgorithmType2, WildcardEscapeCharacter); |
104 | 3 | } |
105 | | |
106 | | SearchOptions2() |
107 | 49 | : searchFlag(0) |
108 | 49 | , changedChars(0) |
109 | 49 | , deletedChars(0) |
110 | 49 | , insertedChars(0) |
111 | 49 | , transliterateFlags(TransliterationFlags::NONE) |
112 | 49 | , AlgorithmType2(0) |
113 | 49 | , WildcardEscapeCharacter(0) |
114 | 49 | {} |
115 | | |
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 | 17 | : searchFlag(searchFlag_) |
123 | 17 | , searchString(std::move(searchString_)) |
124 | 17 | , replaceString(std::move(replaceString_)) |
125 | 17 | , Locale(std::move(Locale_)) |
126 | 17 | , changedChars(changedChars_) |
127 | 17 | , deletedChars(deletedChars_) |
128 | 17 | , insertedChars(insertedChars_) |
129 | 17 | , transliterateFlags(transliterateFlags_) |
130 | 17 | , AlgorithmType2(AlgorithmType2_) |
131 | 17 | , WildcardEscapeCharacter(WildcardEscapeCharacter_) |
132 | 17 | {} |
133 | | }; |
134 | | |
135 | | }; // namespace |
136 | | |
137 | | #endif |
138 | | |
139 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |