/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 | | #pragma once |
20 | | |
21 | | #include <sal/types.h> |
22 | | #include <com/sun/star/lang/Locale.hpp> |
23 | | #include <com/sun/star/util/SearchAlgorithms.hpp> |
24 | | #include <com/sun/star/util/SearchAlgorithms2.hpp> |
25 | | #include <com/sun/star/util/SearchOptions2.hpp> |
26 | | #include <i18nutil/transliteration.hxx> |
27 | | #include <utility> |
28 | | |
29 | | namespace i18nutil |
30 | | { |
31 | | |
32 | | inline constexpr css::util::SearchAlgorithms downgradeSearchAlgorithms2(sal_Int16 searchAlgorithms2) |
33 | 3 | { |
34 | 3 | switch (searchAlgorithms2) |
35 | 3 | { |
36 | 1 | case css::util::SearchAlgorithms2::ABSOLUTE: |
37 | 1 | return css::util::SearchAlgorithms_ABSOLUTE; |
38 | 0 | case css::util::SearchAlgorithms2::REGEXP: |
39 | 0 | return css::util::SearchAlgorithms_REGEXP; |
40 | 0 | case css::util::SearchAlgorithms2::APPROXIMATE: |
41 | 0 | return css::util::SearchAlgorithms_APPROXIMATE; |
42 | 0 | default: // default what? |
43 | 2 | case css::util::SearchAlgorithms2::WILDCARD: // something valid |
44 | 2 | return css::util::SearchAlgorithms_ABSOLUTE; |
45 | 3 | } |
46 | 3 | } |
47 | | |
48 | | inline constexpr sal_Int16 upgradeSearchAlgorithms(css::util::SearchAlgorithms searchAlgorithms) |
49 | 0 | { |
50 | 0 | switch (searchAlgorithms) |
51 | 0 | { |
52 | 0 | default: // default what? |
53 | 0 | case css::util::SearchAlgorithms_ABSOLUTE: |
54 | 0 | return css::util::SearchAlgorithms2::ABSOLUTE; |
55 | 0 | case css::util::SearchAlgorithms_REGEXP: |
56 | 0 | return css::util::SearchAlgorithms2::REGEXP; |
57 | 0 | case css::util::SearchAlgorithms_APPROXIMATE: |
58 | 0 | return css::util::SearchAlgorithms2::APPROXIMATE; |
59 | 0 | } |
60 | 0 | } |
61 | | |
62 | | /** |
63 | | * This is a wrapper around com::sun::star::util::SearchOptions and SearchOptions2, |
64 | | * but using the more type-safe TransliterationFlags enum, and without obsolete |
65 | | * algorithmType, which is superseded by AlgorithmType2. |
66 | | */ |
67 | | struct SAL_WARN_UNUSED SearchOptions2 { |
68 | | sal_Int32 searchFlag; |
69 | | OUString searchString; |
70 | | OUString replaceString; |
71 | | css::lang::Locale Locale; |
72 | | sal_Int32 changedChars; |
73 | | sal_Int32 deletedChars; |
74 | | sal_Int32 insertedChars; |
75 | | TransliterationFlags transliterateFlags; |
76 | | |
77 | | sal_Int16 AlgorithmType2; |
78 | | sal_Int32 WildcardEscapeCharacter; |
79 | | |
80 | | SearchOptions2& operator=(css::util::SearchOptions2 const & other) |
81 | 0 | { |
82 | 0 | searchFlag = other.searchFlag; |
83 | 0 | searchString = other.searchString; |
84 | 0 | replaceString = other.replaceString; |
85 | 0 | Locale = other.Locale; |
86 | 0 | changedChars = other.changedChars; |
87 | 0 | deletedChars = other.deletedChars; |
88 | 0 | insertedChars = other.insertedChars; |
89 | 0 | transliterateFlags = static_cast<TransliterationFlags>(other.transliterateFlags); |
90 | 0 | AlgorithmType2 = other.AlgorithmType2; |
91 | 0 | WildcardEscapeCharacter = other.WildcardEscapeCharacter; |
92 | 0 | return *this; |
93 | 0 | } |
94 | | |
95 | | css::util::SearchOptions2 toUnoSearchOptions2() const |
96 | 3 | { |
97 | 3 | return css::util::SearchOptions2(downgradeSearchAlgorithms2(AlgorithmType2), searchFlag, |
98 | 3 | searchString, replaceString, |
99 | 3 | Locale, |
100 | 3 | changedChars, deletedChars, insertedChars, |
101 | 3 | static_cast<sal_Int32>(transliterateFlags), |
102 | 3 | AlgorithmType2, WildcardEscapeCharacter); |
103 | 3 | } |
104 | | |
105 | | SearchOptions2() |
106 | 47 | : searchFlag(0) |
107 | 47 | , changedChars(0) |
108 | 47 | , deletedChars(0) |
109 | 47 | , insertedChars(0) |
110 | 47 | , transliterateFlags(TransliterationFlags::NONE) |
111 | 47 | , AlgorithmType2(0) |
112 | 47 | , WildcardEscapeCharacter(0) |
113 | 47 | {} |
114 | | |
115 | | SearchOptions2(const sal_Int32 searchFlag_, |
116 | | OUString searchString_, OUString replaceString_, |
117 | | css::lang::Locale Locale_, |
118 | | const sal_Int32 changedChars_, const sal_Int32 deletedChars_, const sal_Int32 insertedChars_, |
119 | | const TransliterationFlags& transliterateFlags_, |
120 | | const sal_Int16 AlgorithmType2_, const sal_Int32 WildcardEscapeCharacter_) |
121 | 17 | : searchFlag(searchFlag_) |
122 | 17 | , searchString(std::move(searchString_)) |
123 | 17 | , replaceString(std::move(replaceString_)) |
124 | 17 | , Locale(std::move(Locale_)) |
125 | 17 | , changedChars(changedChars_) |
126 | 17 | , deletedChars(deletedChars_) |
127 | 17 | , insertedChars(insertedChars_) |
128 | 17 | , transliterateFlags(transliterateFlags_) |
129 | 17 | , AlgorithmType2(AlgorithmType2_) |
130 | 17 | , WildcardEscapeCharacter(WildcardEscapeCharacter_) |
131 | 17 | {} |
132 | | }; |
133 | | |
134 | | }; // namespace |
135 | | |
136 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |