/src/wabt/src/filenames.cc
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2016 WebAssembly Community Group participants |
3 | | * |
4 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | | * you may not use this file except in compliance with the License. |
6 | | * You may obtain a copy of the License at |
7 | | * |
8 | | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | | * |
10 | | * Unless required by applicable law or agreed to in writing, software |
11 | | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | | * See the License for the specific language governing permissions and |
14 | | * limitations under the License. |
15 | | */ |
16 | | |
17 | | #include "wabt/filenames.h" |
18 | | |
19 | | namespace wabt { |
20 | | |
21 | | const char* kWasmExtension = ".wasm"; |
22 | | |
23 | | const char* kWatExtension = ".wat"; |
24 | | |
25 | 0 | std::string_view StripExtension(std::string_view filename) { |
26 | 0 | return filename.substr(0, filename.find_last_of('.')); |
27 | 0 | } |
28 | | |
29 | 12.3k | std::string_view GetBasename(std::string_view filename) { |
30 | 12.3k | size_t last_slash = filename.find_last_of('/'); |
31 | 12.3k | size_t last_backslash = filename.find_last_of('\\'); |
32 | 12.3k | if (last_slash == std::string_view::npos && |
33 | 12.3k | last_backslash == std::string_view::npos) { |
34 | 12.3k | return filename; |
35 | 12.3k | } |
36 | | |
37 | 0 | if (last_slash == std::string_view::npos) { |
38 | 0 | if (last_backslash == std::string_view::npos) { |
39 | 0 | return filename; |
40 | 0 | } |
41 | 0 | last_slash = last_backslash; |
42 | 0 | } else if (last_backslash != std::string_view::npos) { |
43 | 0 | last_slash = std::max(last_slash, last_backslash); |
44 | 0 | } |
45 | | |
46 | 0 | return filename.substr(last_slash + 1); |
47 | 0 | } |
48 | | |
49 | 0 | std::string_view GetExtension(std::string_view filename) { |
50 | 0 | size_t pos = filename.find_last_of('.'); |
51 | 0 | if (pos == std::string_view::npos) { |
52 | 0 | return ""; |
53 | 0 | } |
54 | 0 | return filename.substr(pos); |
55 | 0 | } |
56 | | |
57 | | } // namespace wabt |