Skip to content

Commit

Permalink
fixup! src: refactor SplitString in util
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Jun 22, 2023
1 parent b53ae22 commit 27d1a87
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
17 changes: 9 additions & 8 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
#endif

#include <errno.h>
#include <sstream>
#include <limits>
#include <algorithm>
#include <cstdlib> // strtoul, errno
#include <limits>
#include <sstream>
#include <string_view>

using namespace std::string_view_literals;

using v8::Boolean;
using v8::Context;
Expand Down Expand Up @@ -50,16 +53,14 @@ void DebugOptions::CheckOptions(std::vector<std::string>* errors,
"`node --inspect-brk` instead.");
}

std::vector<std::string_view> destinations =
SplitString(std::string_view(inspect_publish_uid_string.c_str(),
inspect_publish_uid_string.size()),
",");
const std::vector<std::string_view> destinations =
SplitString(inspect_publish_uid_string, ","sv);
inspect_publish_uid.console = false;
inspect_publish_uid.http = false;
for (const std::string_view destination : destinations) {
if (destination == "stderr") {
if (destination == "stderr"sv) {
inspect_publish_uid.console = true;
} else if (destination == "http") {
} else if (destination == "http"sv) {
inspect_publish_uid.http = true;
} else {
errors->push_back("--inspect-publish-uid destination can be "
Expand Down
19 changes: 14 additions & 5 deletions src/node_v8_platform-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#include <memory>
#include <string_view>

#include "env-inl.h"
#include "node.h"
Expand All @@ -15,6 +16,8 @@
#include "tracing/traced_value.h"
#include "util.h"

using namespace std::string_view_literals;

namespace node {

// Ensures that __metadata trace events are only emitted
Expand Down Expand Up @@ -126,16 +129,22 @@ struct V8Platform {
}

inline void StartTracingAgent() {
constexpr auto convert_to_set =
[](std::vector<std::string_view> categories) -> std::set<std::string> {
std::set<std::string> out;
for (const auto s : categories) {
out.emplace(s);
}
return out;
};
// Attach a new NodeTraceWriter only if this function hasn't been called
// before.
if (tracing_file_writer_.IsDefaultHandle()) {
auto out = per_process::cli_options->trace_event_categories;
std::vector<std::string_view> categories =
SplitString(std::string_view(out.c_str(), out.size()), ",");
const std::vector<std::string_view> categories =
SplitString(per_process::cli_options->trace_event_categories, ","sv);

tracing_file_writer_ = tracing_agent_->AddClient(
std::set<std::string>(std::make_move_iterator(categories.begin()),
std::make_move_iterator(categories.end())),
convert_to_set(categories),
std::unique_ptr<tracing::AsyncTraceWriter>(
new tracing::NodeTraceWriter(
per_process::cli_options->trace_event_file_pattern)),
Expand Down
8 changes: 5 additions & 3 deletions src/permission/fs_permission.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
#include <algorithm>
#include <filesystem>
#include <string>
#include <string_view>
#include <vector>

using namespace std::string_view_literals;

namespace {

std::string WildcardIfDir(const std::string& res) noexcept {
Expand Down Expand Up @@ -74,9 +77,8 @@ namespace permission {
// allow = '*'
// allow = '/tmp/,/home/example.js'
void FSPermission::Apply(const std::string& allow, PermissionScope scope) {
for (const auto res :
SplitString(std::string_view(allow.c_str(), allow.size()), ",")) {
if (res == "*") {
for (const std::string_view res : SplitString(allow, ","sv)) {
if (res == "*"sv) {
if (scope == PermissionScope::kFileSystemRead) {
deny_all_in_ = false;
allow_all_in_ = true;
Expand Down

0 comments on commit 27d1a87

Please sign in to comment.