1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-05-10 07:10:32 +08:00
CMake/Source/cmStringReplaceHelper.h
Kitware Robot 0b96ae1f6a Revise C++ coding style using clang-format with "east const"
Run the `clang-format.bash` script to update all our C and C++ code to a
new style defined by `.clang-format`, now with "east const" enforcement.
Use `clang-format` version 18.

* If you reached this commit for a line in `git blame`, re-run the blame
  operation starting at the parent of this commit to see older history
  for the content.

* See the parent commit for instructions to rebase a change across this
  style transition commit.

Issue: #26123
2025-01-23 13:09:50 -05:00

66 lines
1.4 KiB
C++

/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#pragma once
#include <string>
#include <utility>
#include <vector>
#include "cmsys/RegularExpression.hxx"
class cmMakefile;
class cmStringReplaceHelper
{
public:
cmStringReplaceHelper(std::string const& regex, std::string replace_expr,
cmMakefile* makefile = nullptr);
bool IsRegularExpressionValid() const
{
return this->RegularExpression.is_valid();
}
bool IsReplaceExpressionValid() const
{
return this->ValidReplaceExpression;
}
bool Replace(std::string const& input, std::string& output);
std::string const& GetError() { return this->ErrorString; }
private:
class RegexReplacement
{
public:
RegexReplacement(char const* s)
: Number(-1)
, Value(s)
{
}
RegexReplacement(std::string s)
: Number(-1)
, Value(std::move(s))
{
}
RegexReplacement(int n)
: Number(n)
{
}
RegexReplacement() = default;
int Number;
std::string Value;
};
void ParseReplaceExpression();
std::string ErrorString;
std::string RegExString;
cmsys::RegularExpression RegularExpression;
bool ValidReplaceExpression = true;
std::string ReplaceExpression;
std::vector<RegexReplacement> Replacements;
cmMakefile* Makefile = nullptr;
};