summaryrefslogtreecommitdiff
path: root/src/support/path.cpp
diff options
context:
space:
mode:
authorThomas Lively <7121787+tlively@users.noreply.github.com>2021-05-25 15:32:39 -0700
committerGitHub <noreply@github.com>2021-05-25 15:32:39 -0700
commit7f31823120ba25075d783df863f6be536543f805 (patch)
tree715631368260ecda006f65c9c07433294aed26d1 /src/support/path.cpp
parent994757a6747793effc8e4bdda13c47ab7337afb8 (diff)
downloadbinaryen-7f31823120ba25075d783df863f6be536543f805.tar.gz
binaryen-7f31823120ba25075d783df863f6be536543f805.tar.bz2
binaryen-7f31823120ba25075d783df863f6be536543f805.zip
[wasm-split] Add an option to emit only the module names (#3901)
Even when other names are stripped, it can be useful for wasm-split to preserve the module name so that the split modules can be differentiated in stack traces. Adding this option to wasm-split requires adding similar options to ModuleWriter and WasmBinaryWriter.
Diffstat (limited to 'src/support/path.cpp')
-rw-r--r--src/support/path.cpp29
1 files changed, 21 insertions, 8 deletions
diff --git a/src/support/path.cpp b/src/support/path.cpp
index 2501c636c..1cf5c736d 100644
--- a/src/support/path.cpp
+++ b/src/support/path.cpp
@@ -34,20 +34,33 @@ char getPathSeparator() {
#endif
}
+static std::string getAllPathSeparators() {
+ // The canonical separator on Windows is `\`, but it also accepts `/`.
+#if defined(WIN32) || defined(_WIN32)
+ return "\\/";
+#else
+ return "/";
+#endif
+}
+
std::string getDirName(const std::string& path) {
- auto sep = path.rfind(getPathSeparator());
- if (sep == std::string::npos) {
- return "";
+ for (char c : getAllPathSeparators()) {
+ auto sep = path.rfind(c);
+ if (sep != std::string::npos) {
+ return path.substr(0, sep);
+ }
}
- return path.substr(0, sep);
+ return "";
}
std::string getBaseName(const std::string& path) {
- auto sep = path.rfind(getPathSeparator());
- if (sep == std::string::npos) {
- return path;
+ for (char c : getAllPathSeparators()) {
+ auto sep = path.rfind(c);
+ if (sep != std::string::npos) {
+ return path.substr(sep + 1);
+ }
}
- return path.substr(sep + 1);
+ return path;
}
std::string getBinaryenRoot() {