Skip to content

Commit 3b5c4fb

Browse files
tniessentargos
authored andcommitted
src: replace goto with lambda in options parser
PR-URL: #32635 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 17b2526 commit 3b5c4fb

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/node_options-inl.h

+11-5
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,10 @@ void OptionsParser<Options>::Parse(
315315
if (equals_index != std::string::npos)
316316
original_name += '=';
317317

318+
auto missing_argument = [&]() {
319+
errors->push_back(RequiresArgumentErr(original_name));
320+
};
321+
318322
// Normalize by replacing `_` with `-` in options.
319323
for (std::string::size_type i = 2; i < name.size(); ++i) {
320324
if (name[i] == '_')
@@ -381,18 +385,20 @@ void OptionsParser<Options>::Parse(
381385
if (equals_index != std::string::npos) {
382386
value = arg.substr(equals_index + 1);
383387
if (value.empty()) {
384-
missing_argument:
385-
errors->push_back(RequiresArgumentErr(original_name));
388+
missing_argument();
386389
break;
387390
}
388391
} else {
389-
if (args.empty())
390-
goto missing_argument;
392+
if (args.empty()) {
393+
missing_argument();
394+
break;
395+
}
391396

392397
value = args.pop_first();
393398

394399
if (!value.empty() && value[0] == '-') {
395-
goto missing_argument;
400+
missing_argument();
401+
break;
396402
} else {
397403
if (!value.empty() && value[0] == '\\' && value[1] == '-')
398404
value = value.substr(1); // Treat \- as escaping an -.

0 commit comments

Comments
 (0)