Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: replace goto with lambda in options parser #32635

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/node_options-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ void OptionsParser<Options>::Parse(
if (equals_index != std::string::npos)
original_name += '=';

auto missing_argument = [&]() {
errors->push_back(RequiresArgumentErr(original_name));
};

// Normalize by replacing `_` with `-` in options.
for (std::string::size_type i = 2; i < name.size(); ++i) {
if (name[i] == '_')
Expand Down Expand Up @@ -381,18 +385,20 @@ void OptionsParser<Options>::Parse(
if (equals_index != std::string::npos) {
value = arg.substr(equals_index + 1);
if (value.empty()) {
missing_argument:
errors->push_back(RequiresArgumentErr(original_name));
missing_argument();
break;
}
} else {
if (args.empty())
goto missing_argument;
if (args.empty()) {
missing_argument();
break;
}

value = args.pop_first();

if (!value.empty() && value[0] == '-') {
goto missing_argument;
missing_argument();
break;
} else {
if (!value.empty() && value[0] == '\\' && value[1] == '-')
value = value.substr(1); // Treat \- as escaping an -.
Expand Down