cmStringAlgorithms: Add cmRemoveQuotes
- Add `cmRemoveQuotes` function to cmStringAlgorithms - Remove unused removeQuotes inline functions
This commit is contained in:
parent
242435a9c8
commit
27090096ef
@ -2270,14 +2270,6 @@ bool cmGlobalGenerator::NameResolvesToFramework(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string removeQuotes(const std::string& s)
|
|
||||||
{
|
|
||||||
if (s.front() == '\"' && s.back() == '\"') {
|
|
||||||
return s.substr(1, s.size() - 2);
|
|
||||||
}
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool cmGlobalGenerator::CheckCMP0037(std::string const& targetName,
|
bool cmGlobalGenerator::CheckCMP0037(std::string const& targetName,
|
||||||
std::string const& reason) const
|
std::string const& reason) const
|
||||||
{
|
{
|
||||||
|
@ -21,6 +21,20 @@ std::string cmTrimWhitespace(cm::string_view str)
|
|||||||
return std::string(start, stop + 1);
|
return std::string(start, stop + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string cmRemoveQuotes(cm::string_view str)
|
||||||
|
{
|
||||||
|
// We process only strings that have two quotes at least.
|
||||||
|
// Also front() and back() are only defined behavior on non empty strings.
|
||||||
|
if (str.size() >= 2 && //
|
||||||
|
str.front() == '"' && //
|
||||||
|
str.back() == '"') {
|
||||||
|
// Remove a quote from the front and back
|
||||||
|
str.remove_prefix(1);
|
||||||
|
str.remove_suffix(1);
|
||||||
|
}
|
||||||
|
return std::string(str);
|
||||||
|
}
|
||||||
|
|
||||||
std::string cmEscapeQuotes(cm::string_view str)
|
std::string cmEscapeQuotes(cm::string_view str)
|
||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
|
@ -41,6 +41,9 @@ inline bool cmIsSpace(char ch)
|
|||||||
/** Returns a string that has whitespace removed from the start and the end. */
|
/** Returns a string that has whitespace removed from the start and the end. */
|
||||||
std::string cmTrimWhitespace(cm::string_view str);
|
std::string cmTrimWhitespace(cm::string_view str);
|
||||||
|
|
||||||
|
/** Returns a string that has quotes removed from the start and the end. */
|
||||||
|
std::string cmRemoveQuotes(cm::string_view str);
|
||||||
|
|
||||||
/** Escape quotes in a string. */
|
/** Escape quotes in a string. */
|
||||||
std::string cmEscapeQuotes(cm::string_view str);
|
std::string cmEscapeQuotes(cm::string_view str);
|
||||||
|
|
||||||
|
@ -2270,14 +2270,6 @@ void cmake::TruncateOutputLog(const char* fname)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string removeQuotes(const std::string& s)
|
|
||||||
{
|
|
||||||
if (s.front() == '\"' && s.back() == '\"') {
|
|
||||||
return s.substr(1, s.size() - 2);
|
|
||||||
}
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
void cmake::MarkCliAsUsed(const std::string& variable)
|
void cmake::MarkCliAsUsed(const std::string& variable)
|
||||||
{
|
{
|
||||||
this->UsedCliVariables[variable] = true;
|
this->UsedCliVariables[variable] = true;
|
||||||
|
@ -50,6 +50,29 @@ int testStringAlgorithms(int /*unused*/, char* /*unused*/ [])
|
|||||||
"cmTrimWhitespace front and back");
|
"cmTrimWhitespace front and back");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
// Test cmRemoveQuotes
|
||||||
|
{
|
||||||
|
auto test = [&assert_string](cm::string_view source,
|
||||||
|
cm::string_view expected,
|
||||||
|
cm::string_view title) {
|
||||||
|
assert_string(cmRemoveQuotes(source), expected, title);
|
||||||
|
};
|
||||||
|
|
||||||
|
test("", "", "cmRemoveQuotes empty");
|
||||||
|
test("\"", "\"", "cmRemoveQuotes single quote");
|
||||||
|
test("\"\"", "", "cmRemoveQuotes double quote");
|
||||||
|
test("\"a", "\"a", "cmRemoveQuotes quote char");
|
||||||
|
test("\"ab", "\"ab", "cmRemoveQuotes quote char char");
|
||||||
|
test("a\"", "a\"", "cmRemoveQuotes char quote");
|
||||||
|
test("ab\"", "ab\"", "cmRemoveQuotes char char quote");
|
||||||
|
test("a", "a", "cmRemoveQuotes single char");
|
||||||
|
test("ab", "ab", "cmRemoveQuotes two chars");
|
||||||
|
test("abc", "abc", "cmRemoveQuotes three chars");
|
||||||
|
test("\"abc\"", "abc", "cmRemoveQuotes quoted chars");
|
||||||
|
test("\"\"abc\"\"", "\"abc\"", "cmRemoveQuotes quoted quoted chars");
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
// Test cmEscapeQuotes
|
// Test cmEscapeQuotes
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user