Skip to content
Permalink
Browse files

src: use generic helper for splitting strings

PR-URL: nodejs#25363
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
  • Loading branch information...
addaleax authored and BridgeAR committed Jan 6, 2019
1 parent 243f902 commit 8e6175e001a16939ced16a01a900d6bb9a8afc86
Showing with 14 additions and 24 deletions.
  1. +9 −19 src/node.cc
  2. +4 −4 src/util.cc
  3. +1 −1 src/util.h
@@ -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)),
@@ -1424,23 +1427,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,

0 comments on commit 8e6175e

Please sign in to comment.
You can’t perform that action at this time.