From 35d8367a0c16aaec8b42da88c8b25531ef476a3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Fri, 3 Apr 2020 09:37:50 +0000 Subject: [PATCH] src: replace goto with lambda in options parser --- src/node_options-inl.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/node_options-inl.h b/src/node_options-inl.h index 885cb849744205..682a1c6c47d020 100644 --- a/src/node_options-inl.h +++ b/src/node_options-inl.h @@ -315,6 +315,10 @@ void OptionsParser::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] == '_') @@ -381,18 +385,20 @@ void OptionsParser::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 -.