CMake Nightly Date Stamp
[kiteware-cmake.git] / Source / cmStringReplaceHelper.h
blobfd59d17243947a3977a1b43415c8afde800b4b56
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
5 #include <string>
6 #include <utility>
7 #include <vector>
9 #include "cmsys/RegularExpression.hxx"
11 class cmMakefile;
13 class cmStringReplaceHelper
15 public:
16 cmStringReplaceHelper(const std::string& regex, std::string replace_expr,
17 cmMakefile* makefile = nullptr);
19 bool IsRegularExpressionValid() const
21 return this->RegularExpression.is_valid();
23 bool IsReplaceExpressionValid() const
25 return this->ValidReplaceExpression;
28 bool Replace(const std::string& input, std::string& output);
30 const std::string& GetError() { return this->ErrorString; }
32 private:
33 class RegexReplacement
35 public:
36 RegexReplacement(const char* s)
37 : Number(-1)
38 , Value(s)
41 RegexReplacement(std::string s)
42 : Number(-1)
43 , Value(std::move(s))
46 RegexReplacement(int n)
47 : Number(n)
50 RegexReplacement() = default;
52 int Number;
53 std::string Value;
56 void ParseReplaceExpression();
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;