mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-01-26 19:09:06 +00:00
Extend usage for cm::string_view for more flexibility
This commit is contained in:
parent
34b7e7ac64
commit
ab60f1a010
@ -166,7 +166,7 @@ std::string cmGeneratorExpression::StripEmptyListElements(
|
||||
}
|
||||
|
||||
static std::string extractAllGeneratorExpressions(
|
||||
std::string const& input,
|
||||
cm::string_view input,
|
||||
std::map<std::string, std::vector<std::string>>* collected)
|
||||
{
|
||||
std::string result;
|
||||
@ -176,9 +176,9 @@ static std::string extractAllGeneratorExpressions(
|
||||
std::stack<char const*> colons; // indices of ":"
|
||||
while ((pos = input.find("$<", lastPos)) != std::string::npos) {
|
||||
result += input.substr(lastPos, pos - lastPos);
|
||||
starts.push(input.c_str() + pos);
|
||||
starts.push(input.data() + pos);
|
||||
pos += 2;
|
||||
char const* c = input.c_str() + pos;
|
||||
char const* c = input.data() + pos;
|
||||
char const* const cStart = c;
|
||||
for (; *c; ++c) {
|
||||
if (cmGeneratorExpression::StartsWithGeneratorExpression(c)) {
|
||||
@ -209,7 +209,7 @@ static std::string extractAllGeneratorExpressions(
|
||||
}
|
||||
std::string::size_type const traversed = (c - cStart) + 1;
|
||||
if (!*c) {
|
||||
result += "$<" + input.substr(pos, traversed);
|
||||
result += cmStrCat("$<", input.substr(pos, traversed));
|
||||
}
|
||||
pos += traversed;
|
||||
lastPos = pos;
|
||||
@ -220,7 +220,7 @@ static std::string extractAllGeneratorExpressions(
|
||||
return cmGeneratorExpression::StripEmptyListElements(result);
|
||||
}
|
||||
|
||||
static std::string stripAllGeneratorExpressions(std::string const& input)
|
||||
static std::string stripAllGeneratorExpressions(cm::string_view input)
|
||||
{
|
||||
return extractAllGeneratorExpressions(input, nullptr);
|
||||
}
|
||||
@ -243,7 +243,7 @@ static void prefixItems(std::string const& content, std::string& result,
|
||||
}
|
||||
|
||||
static std::string stripExportInterface(
|
||||
std::string const& input, cmGeneratorExpression::PreprocessContext context,
|
||||
cm::string_view input, cmGeneratorExpression::PreprocessContext context,
|
||||
cm::string_view importPrefix)
|
||||
{
|
||||
std::string result;
|
||||
@ -282,7 +282,7 @@ static std::string stripExportInterface(
|
||||
assert(false && "Invalid position found");
|
||||
}
|
||||
nestingLevel = 1;
|
||||
char const* c = input.c_str() + pos;
|
||||
char const* c = input.data() + pos;
|
||||
char const* const cStart = c;
|
||||
for (; *c; ++c) {
|
||||
if (cmGeneratorExpression::StartsWithGeneratorExpression(c)) {
|
||||
@ -300,7 +300,8 @@ static std::string stripExportInterface(
|
||||
result += input.substr(pos, c - cStart);
|
||||
} else if (context == cmGeneratorExpression::InstallInterface &&
|
||||
foundGenex == FoundGenex::InstallInterface) {
|
||||
std::string const content = input.substr(pos, c - cStart);
|
||||
std::string const content =
|
||||
static_cast<std::string>(input.substr(pos, c - cStart));
|
||||
if (!importPrefix.empty()) {
|
||||
prefixItems(content, result, importPrefix);
|
||||
} else {
|
||||
@ -390,7 +391,7 @@ void cmGeneratorExpression::Split(std::string const& input,
|
||||
}
|
||||
}
|
||||
|
||||
std::string cmGeneratorExpression::Preprocess(std::string const& input,
|
||||
std::string cmGeneratorExpression::Preprocess(cm::string_view input,
|
||||
PreprocessContext context,
|
||||
cm::string_view importPrefix)
|
||||
{
|
||||
|
||||
@ -65,7 +65,7 @@ public:
|
||||
InstallInterface
|
||||
};
|
||||
|
||||
static std::string Preprocess(std::string const& input,
|
||||
static std::string Preprocess(cm::string_view input,
|
||||
PreprocessContext context,
|
||||
cm::string_view importPrefix = {});
|
||||
|
||||
|
||||
@ -20,8 +20,7 @@ cmStringReplaceHelper::cmStringReplaceHelper(std::string const& regex,
|
||||
this->ParseReplaceExpression();
|
||||
}
|
||||
|
||||
bool cmStringReplaceHelper::Replace(std::string const& input,
|
||||
std::string& output)
|
||||
bool cmStringReplaceHelper::Replace(cm::string_view input, std::string& output)
|
||||
{
|
||||
output.clear();
|
||||
|
||||
@ -36,7 +35,7 @@ bool cmStringReplaceHelper::Replace(std::string const& input,
|
||||
auto& re = this->RegularExpression;
|
||||
std::string::size_type base = 0;
|
||||
unsigned optNonEmpty = 0;
|
||||
while (re.find(input, base, optAnchor | optNonEmpty)) {
|
||||
while (re.find(input.data(), base, optAnchor | optNonEmpty)) {
|
||||
if (this->Makefile) {
|
||||
this->Makefile->ClearMatches();
|
||||
this->Makefile->StoreMatches(re);
|
||||
|
||||
@ -6,6 +6,8 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <cm/string_view>
|
||||
|
||||
#include "cmsys/RegularExpression.hxx"
|
||||
|
||||
class cmMakefile;
|
||||
@ -25,7 +27,7 @@ public:
|
||||
return this->ValidReplaceExpression;
|
||||
}
|
||||
|
||||
bool Replace(std::string const& input, std::string& output);
|
||||
bool Replace(cm::string_view input, std::string& output);
|
||||
|
||||
std::string const& GetError() { return this->ErrorString; }
|
||||
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
#include "cmStringAlgorithms.h"
|
||||
#include "cmSystemTools.h"
|
||||
|
||||
std::string cmTimestamp::CurrentTime(std::string const& formatString,
|
||||
std::string cmTimestamp::CurrentTime(cm::string_view formatString,
|
||||
bool utcFlag) const
|
||||
{
|
||||
// get current time with microsecond resolution
|
||||
@ -63,11 +63,12 @@ std::string cmTimestamp::CurrentTime(std::string const& formatString,
|
||||
}
|
||||
|
||||
return this->CreateTimestampFromTimeT(currentTimeT, microseconds,
|
||||
formatString, utcFlag);
|
||||
static_cast<std::string>(formatString),
|
||||
utcFlag);
|
||||
}
|
||||
|
||||
std::string cmTimestamp::FileModificationTime(char const* path,
|
||||
std::string const& formatString,
|
||||
cm::string_view formatString,
|
||||
bool utcFlag) const
|
||||
{
|
||||
std::string real_path =
|
||||
@ -89,8 +90,8 @@ std::string cmTimestamp::FileModificationTime(char const* path,
|
||||
}
|
||||
uv_fs_req_cleanup(&req);
|
||||
|
||||
return this->CreateTimestampFromTimeT(mtime, microseconds, formatString,
|
||||
utcFlag);
|
||||
return this->CreateTimestampFromTimeT(
|
||||
mtime, microseconds, static_cast<std::string>(formatString), utcFlag);
|
||||
}
|
||||
|
||||
std::string cmTimestamp::CreateTimestampFromTimeT(time_t timeT,
|
||||
|
||||
@ -8,6 +8,8 @@
|
||||
#include <ctime>
|
||||
#include <string>
|
||||
|
||||
#include <cm/string_view>
|
||||
|
||||
/** \class cmTimestamp
|
||||
* \brief Utility class to generate string representation of a timestamp
|
||||
*
|
||||
@ -15,10 +17,10 @@
|
||||
class cmTimestamp
|
||||
{
|
||||
public:
|
||||
std::string CurrentTime(std::string const& formatString, bool utcFlag) const;
|
||||
std::string CurrentTime(cm::string_view formatString, bool utcFlag) const;
|
||||
|
||||
std::string FileModificationTime(char const* path,
|
||||
std::string const& formatString,
|
||||
cm::string_view formatString,
|
||||
bool utcFlag) const;
|
||||
|
||||
std::string CreateTimestampFromTimeT(time_t timeT, std::string formatString,
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
static std::array<int, 5> const kUuidGroups = { { 4, 2, 2, 2, 6 } };
|
||||
|
||||
std::string cmUuid::FromMd5(std::vector<unsigned char> const& uuidNamespace,
|
||||
std::string const& name) const
|
||||
cm::string_view name) const
|
||||
{
|
||||
std::vector<unsigned char> hashInput;
|
||||
this->CreateHashInput(uuidNamespace, name, hashInput);
|
||||
@ -24,7 +24,7 @@ std::string cmUuid::FromMd5(std::vector<unsigned char> const& uuidNamespace,
|
||||
}
|
||||
|
||||
std::string cmUuid::FromSha1(std::vector<unsigned char> const& uuidNamespace,
|
||||
std::string const& name) const
|
||||
cm::string_view name) const
|
||||
{
|
||||
std::vector<unsigned char> hashInput;
|
||||
this->CreateHashInput(uuidNamespace, name, hashInput);
|
||||
@ -38,7 +38,7 @@ std::string cmUuid::FromSha1(std::vector<unsigned char> const& uuidNamespace,
|
||||
}
|
||||
|
||||
void cmUuid::CreateHashInput(std::vector<unsigned char> const& uuidNamespace,
|
||||
std::string const& name,
|
||||
cm::string_view name,
|
||||
std::vector<unsigned char>& output) const
|
||||
{
|
||||
output = uuidNamespace;
|
||||
@ -46,7 +46,7 @@ void cmUuid::CreateHashInput(std::vector<unsigned char> const& uuidNamespace,
|
||||
if (!name.empty()) {
|
||||
output.resize(output.size() + name.size());
|
||||
|
||||
memcpy(output.data() + uuidNamespace.size(), name.c_str(), name.size());
|
||||
memcpy(output.data() + uuidNamespace.size(), name.data(), name.size());
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,7 +67,7 @@ std::string cmUuid::FromDigest(unsigned char const* digest,
|
||||
return this->BinaryToString(uuid);
|
||||
}
|
||||
|
||||
bool cmUuid::StringToBinary(std::string const& input,
|
||||
bool cmUuid::StringToBinary(cm::string_view input,
|
||||
std::vector<unsigned char>& output) const
|
||||
{
|
||||
output.clear();
|
||||
@ -126,7 +126,7 @@ std::string cmUuid::ByteToHex(unsigned char inputByte) const
|
||||
return result;
|
||||
}
|
||||
|
||||
bool cmUuid::StringToBinaryImpl(std::string const& input,
|
||||
bool cmUuid::StringToBinaryImpl(cm::string_view input,
|
||||
std::vector<unsigned char>& output) const
|
||||
{
|
||||
if (input.size() % 2) {
|
||||
|
||||
@ -7,6 +7,8 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <cm/string_view>
|
||||
|
||||
/** \class cmUuid
|
||||
* \brief Utility class to generate UUIDs as defined by RFC4122
|
||||
*
|
||||
@ -15,25 +17,25 @@ class cmUuid
|
||||
{
|
||||
public:
|
||||
std::string FromMd5(std::vector<unsigned char> const& uuidNamespace,
|
||||
std::string const& name) const;
|
||||
cm::string_view name) const;
|
||||
|
||||
std::string FromSha1(std::vector<unsigned char> const& uuidNamespace,
|
||||
std::string const& name) const;
|
||||
cm::string_view name) const;
|
||||
|
||||
bool StringToBinary(std::string const& input,
|
||||
bool StringToBinary(cm::string_view input,
|
||||
std::vector<unsigned char>& output) const;
|
||||
|
||||
private:
|
||||
std::string ByteToHex(unsigned char byte) const;
|
||||
|
||||
void CreateHashInput(std::vector<unsigned char> const& uuidNamespace,
|
||||
std::string const& name,
|
||||
cm::string_view name,
|
||||
std::vector<unsigned char>& output) const;
|
||||
|
||||
std::string FromDigest(unsigned char const* digest,
|
||||
unsigned char version) const;
|
||||
|
||||
bool StringToBinaryImpl(std::string const& input,
|
||||
bool StringToBinaryImpl(cm::string_view input,
|
||||
std::vector<unsigned char>& output) const;
|
||||
|
||||
std::string BinaryToString(unsigned char const* input) const;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user