/src/jsonnet/core/path_utils.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | Copyright 2024 Google Inc. All rights reserved. |
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 "path_utils.h" |
18 | | #include <string> |
19 | | |
20 | | namespace jsonnet::internal { |
21 | | |
22 | | // C++17 adds <filesystem> |
23 | | // We could consider using that instead. |
24 | | |
25 | | #if _WIN32 |
26 | | static const char DIR_SEPARATORS[] = "\\/"; |
27 | | #else |
28 | | static const char DIR_SEPARATORS[] = "/"; |
29 | | #endif |
30 | | |
31 | 33 | std::string path_dir_with_trailing_separator(const std::string &path) { |
32 | 33 | size_t last_slash = path.find_last_of(DIR_SEPARATORS); |
33 | 33 | if (last_slash != std::string::npos) { |
34 | 0 | return path.substr(0, last_slash + 1); |
35 | 0 | } |
36 | 33 | return ""; |
37 | 33 | } |
38 | | |
39 | | } // namespace jsonnet::internal |