Skip to content

Commit a7f22f2

Browse files
committed
Add 'is_absolute_path()' function
1 parent bd36a11 commit a7f22f2

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

base/fs.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ const std::string::value_type* path_separators = "\\/";
3535
const std::string::value_type* path_separators = "/";
3636
#endif
3737

38+
bool is_absolute_path(const std::string& path)
39+
{
40+
#ifdef LAF_WINDOWS
41+
return (path.size() > 2 && path[1] == ':' && path[2] == path_separator) ||
42+
// Absolute network path
43+
(path.size() > 1 && path[0] == path_separator && path[1] == path_separator);
44+
#else
45+
return !path.empty() && path[0] == path_separator;
46+
#endif
47+
}
48+
3849
void make_all_directories(const std::string& path)
3950
{
4051
std::vector<std::string> parts;

base/fs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// LAF Base Library
2-
// Copyright (c) 2020-2024 Igara Studio S.A.
2+
// Copyright (c) 2020-2025 Igara Studio S.A.
33
// Copyright (c) 2001-2018 David Capello
44
//
55
// This file is released under the terms of the MIT license.
@@ -28,6 +28,7 @@ extern const std::string::value_type* path_separators;
2828

2929
bool is_file(const std::string& path);
3030
bool is_directory(const std::string& path);
31+
bool is_absolute_path(const std::string& path);
3132

3233
size_t file_size(const std::string& path);
3334

0 commit comments

Comments
 (0)