summaryrefslogtreecommitdiff
path: root/src/file.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2015-03-12 20:39:34 +0000
committerMaxime Coste <frrrwww@gmail.com>2015-03-12 20:39:34 +0000
commitb4f6b50dbb06202deb906cd0c34fca00f46c219e (patch)
tree9838e5a4b406e7bb6f6ad5ce511767f579121c8e /src/file.cc
parent2f20399d03277b1a2d4c92ad97ed751c12e2c6a8 (diff)
Make split_path public
Diffstat (limited to 'src/file.cc')
-rw-r--r--src/file.cc18
1 files changed, 5 insertions, 13 deletions
diff --git a/src/file.cc b/src/file.cc
index ec409df8..268cd47d 100644
--- a/src/file.cc
+++ b/src/file.cc
@@ -56,19 +56,11 @@ String parse_filename(StringView filename)
std::pair<StringView, StringView> split_path(StringView path)
{
- StringView dir, file = path;
- ByteCount dir_end = -1;
- for (ByteCount i = 0; i < path.length(); ++i)
- {
- if (path[i] == '/')
- dir_end = i;
- }
- if (dir_end != -1)
- {
- dir = path.substr(0, dir_end + 1);
- file = path.substr(dir_end + 1);
- }
- return { dir, file };
+ auto it = find(reversed(path), '/');
+ if (it == path.rend())
+ return { {}, path };
+ const char* slash = it.base()-1;
+ return { {path.begin(), slash}, {slash+1, path.end()} };
}
String real_path(StringView filename)