[Support] Use StringRef::consume_front (NFC)

This commit is contained in:
Kazu Hirata 2024-01-13 18:18:49 -08:00
parent 96f14ea618
commit b5d6ea4d8b
3 changed files with 5 additions and 12 deletions

View File

@ -1630,10 +1630,8 @@ bool CommandLineParser::ParseCommandLineOptions(int argc,
// otherwise feed it to the eating positional.
ArgName = StringRef(argv[i] + 1);
// Eat second dash.
if (!ArgName.empty() && ArgName[0] == '-') {
if (ArgName.consume_front("-"))
HaveDoubleDash = true;
ArgName = ArgName.substr(1);
}
Handler = LookupLongOption(*ChosenSubCommand, ArgName, Value,
LongOptionsUseDoubleDash, HaveDoubleDash);
@ -1644,10 +1642,8 @@ bool CommandLineParser::ParseCommandLineOptions(int argc,
} else { // We start with a '-', must be an argument.
ArgName = StringRef(argv[i] + 1);
// Eat second dash.
if (!ArgName.empty() && ArgName[0] == '-') {
if (ArgName.consume_front("-"))
HaveDoubleDash = true;
ArgName = ArgName.substr(1);
}
Handler = LookupLongOption(*ChosenSubCommand, ArgName, Value,
LongOptionsUseDoubleDash, HaveDoubleDash);

View File

@ -72,8 +72,7 @@ formatv_object_base::parseReplacementItem(StringRef Spec) {
return ReplacementItem{};
}
RepString = RepString.trim();
if (!RepString.empty() && RepString.front() == ',') {
RepString = RepString.drop_front();
if (RepString.consume_front(",")) {
if (!consumeFieldLayout(RepString, Where, Align, Pad))
assert(false && "Invalid replacement field layout specification!");
}

View File

@ -85,9 +85,8 @@ bool VersionTuple::tryParse(StringRef input) {
}
// If we're not done, parse the micro version, \.[0-9]+
if (input[0] != '.')
if (!input.consume_front("."))
return true;
input = input.substr(1);
if (parseInt(input, micro))
return true;
@ -97,9 +96,8 @@ bool VersionTuple::tryParse(StringRef input) {
}
// If we're not done, parse the micro version, \.[0-9]+
if (input[0] != '.')
if (!input.consume_front("."))
return true;
input = input.substr(1);
if (parseInt(input, build))
return true;