src: use generic helper for splitting strings
PR-URL: https://github.com/nodejs/node/pull/25363 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
This commit is contained in:
parent
0c8dedd103
commit
8ec3c350f5
28
src/node.cc
28
src/node.cc
@ -282,9 +282,12 @@ static struct {
|
||||
if (per_process::cli_options->trace_event_categories.empty()) {
|
||||
tracing_file_writer_ = tracing_agent_->DefaultHandle();
|
||||
} else {
|
||||
std::vector<std::string> categories =
|
||||
SplitString(per_process::cli_options->trace_event_categories, ',');
|
||||
|
||||
tracing_file_writer_ = tracing_agent_->AddClient(
|
||||
ParseCommaSeparatedSet(
|
||||
per_process::cli_options->trace_event_categories),
|
||||
std::set<std::string>(std::make_move_iterator(categories.begin()),
|
||||
std::make_move_iterator(categories.end())),
|
||||
std::unique_ptr<tracing::AsyncTraceWriter>(
|
||||
new tracing::NodeTraceWriter(
|
||||
per_process::cli_options->trace_event_file_pattern)),
|
||||
@ -1420,23 +1423,10 @@ void Init(std::vector<std::string>* argv,
|
||||
#if !defined(NODE_WITHOUT_NODE_OPTIONS)
|
||||
std::string node_options;
|
||||
if (credentials::SafeGetenv("NODE_OPTIONS", &node_options)) {
|
||||
std::vector<std::string> env_argv;
|
||||
// [0] is expected to be the program name, fill it in from the real argv.
|
||||
env_argv.push_back(argv->at(0));
|
||||
|
||||
// Split NODE_OPTIONS at each ' ' character.
|
||||
std::string::size_type index = std::string::npos;
|
||||
do {
|
||||
std::string::size_type prev_index = index;
|
||||
index = node_options.find(' ', index + 1);
|
||||
if (index - prev_index == 1) continue;
|
||||
|
||||
const std::string option = node_options.substr(
|
||||
prev_index + 1, index - prev_index - 1);
|
||||
if (!option.empty())
|
||||
env_argv.emplace_back(std::move(option));
|
||||
} while (index != std::string::npos);
|
||||
|
||||
// [0] is expected to be the program name, fill it in from the real argv
|
||||
// and use 'x' as a placeholder while parsing.
|
||||
std::vector<std::string> env_argv = SplitString("x " + node_options, ' ');
|
||||
env_argv[0] = argv->at(0);
|
||||
|
||||
ProcessArgv(&env_argv, nullptr, true);
|
||||
}
|
||||
|
@ -122,15 +122,15 @@ void GetHumanReadableProcessName(char (*name)[1024]) {
|
||||
snprintf(*name, sizeof(*name), "%s[%d]", title, uv_os_getpid());
|
||||
}
|
||||
|
||||
std::set<std::string> ParseCommaSeparatedSet(const std::string& in) {
|
||||
std::set<std::string> out;
|
||||
std::vector<std::string> SplitString(const std::string& in, char delim) {
|
||||
std::vector<std::string> out;
|
||||
if (in.empty())
|
||||
return out;
|
||||
std::istringstream in_stream(in);
|
||||
while (in_stream.good()) {
|
||||
std::string item;
|
||||
getline(in_stream, item, ',');
|
||||
out.emplace(std::move(item));
|
||||
std::getline(in_stream, item, delim);
|
||||
out.emplace_back(std::move(item));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
@ -523,7 +523,7 @@ struct FunctionDeleter {
|
||||
template <typename T, void (*function)(T*)>
|
||||
using DeleteFnPtr = typename FunctionDeleter<T, function>::Pointer;
|
||||
|
||||
std::set<std::string> ParseCommaSeparatedSet(const std::string& in);
|
||||
std::vector<std::string> SplitString(const std::string& in, char delim);
|
||||
|
||||
inline v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
|
||||
const std::string& str,
|
||||
|
Loading…
x
Reference in New Issue
Block a user