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