/src/CMake/Source/cmStringReplaceHelper.h
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
2 | | file LICENSE.rst or https://cmake.org/licensing for details. */ |
3 | | #pragma once |
4 | | |
5 | | #include <string> |
6 | | #include <utility> |
7 | | #include <vector> |
8 | | |
9 | | #include <cm/string_view> |
10 | | |
11 | | #include "cmsys/RegularExpression.hxx" |
12 | | |
13 | | class cmMakefile; |
14 | | |
15 | | class cmStringReplaceHelper |
16 | | { |
17 | | public: |
18 | | cmStringReplaceHelper(std::string const& regex, std::string replace_expr, |
19 | | cmMakefile* makefile = nullptr); |
20 | | |
21 | | bool IsRegularExpressionValid() const |
22 | 0 | { |
23 | 0 | return this->RegularExpression.is_valid(); |
24 | 0 | } |
25 | | bool IsReplaceExpressionValid() const |
26 | 0 | { |
27 | 0 | return this->ValidReplaceExpression; |
28 | 0 | } |
29 | | |
30 | | bool Replace(cm::string_view input, std::string& output); |
31 | | |
32 | 0 | std::string const& GetError() { return this->ErrorString; } |
33 | | |
34 | | private: |
35 | | class RegexReplacement |
36 | | { |
37 | | public: |
38 | | RegexReplacement(char const* s) |
39 | 0 | : Number(-1) |
40 | 0 | , Value(s) |
41 | 0 | { |
42 | 0 | } |
43 | | RegexReplacement(std::string s) |
44 | 0 | : Number(-1) |
45 | 0 | , Value(std::move(s)) |
46 | 0 | { |
47 | 0 | } |
48 | | RegexReplacement(int n) |
49 | 0 | : Number(n) |
50 | 0 | { |
51 | 0 | } |
52 | | RegexReplacement() = default; |
53 | | |
54 | | int Number; |
55 | | std::string Value; |
56 | | }; |
57 | | |
58 | | void ParseReplaceExpression(); |
59 | | |
60 | | std::string ErrorString; |
61 | | std::string RegExString; |
62 | | cmsys::RegularExpression RegularExpression; |
63 | | bool ValidReplaceExpression = true; |
64 | | std::string ReplaceExpression; |
65 | | std::vector<RegexReplacement> Replacements; |
66 | | cmMakefile* Makefile = nullptr; |
67 | | }; |