Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2020-04-12 19:55:03 +0300
committerRuben Bridgewater <ruben@bridgewater.de>2020-04-28 14:15:01 +0300
commit5b01772282e0872b72d430486e4753c5e8b86163 (patch)
tree7ac6663fec4770746c3a49fb5827d313ca48d26c /src/node_file.cc
parent3b590d4f171eeb5533b36422dae1d621783da2ef (diff)
src: use basename(argv0) for --trace-uncaught suggestion
Refs: https://github.com/nodejs/node/pull/32797#discussion_r407222290 PR-URL: https://github.com/nodejs/node/pull/32798 Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Diffstat (limited to 'src/node_file.cc')
-rw-r--r--src/node_file.cc16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/node_file.cc b/src/node_file.cc
index 0ce86287bb8..a1cb5cadd2f 100644
--- a/src/node_file.cc
+++ b/src/node_file.cc
@@ -82,6 +82,22 @@ constexpr char kPathSeparator = '/';
const char* const kPathSeparator = "\\/";
#endif
+std::string Basename(const std::string& str, const std::string& extension) {
+ std::string ret = str;
+
+ // Remove everything leading up to and including the final path separator.
+ std::string::size_type pos = ret.find_last_of(kPathSeparator);
+ if (pos != std::string::npos) ret = ret.substr(pos + 1);
+
+ // Strip away the extension, if any.
+ if (ret.size() >= extension.size() &&
+ ret.substr(ret.size() - extension.size()) == extension) {
+ ret = ret.substr(0, ret.size() - extension.size());
+ }
+
+ return ret;
+}
+
inline int64_t GetOffset(Local<Value> value) {
return IsSafeJsInt(value) ? value.As<Integer>()->Value() : -1;
}