2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
19 #include <folly/Range.h>
23 namespace HPHP::FileUtil
{
24 ////////////////////////////////////////////////////////////////////////////////
27 * Check if the given character is a directory separator for the current
30 inline bool isDirSeparator(char c
) {
32 return c
== '/' || c
== '\\';
39 * Get the preferred directory separator for the current platform.
41 inline char getDirSeparator() {
50 * Check if the given path is an absolute path. This does not guarantee that
51 * the path is canonicalized.
53 inline bool isAbsolutePath(folly::StringPiece path
) {
55 auto const len
= path
.size();
59 // NOTE: Boost actually checks if the last character of the first path element
60 // is a colon, rather than if the first character is an alpha followed by a
61 // colon. This is fine for now, as I don't know of any other forms of paths
63 return (isDirSeparator(path
[0]) && isDirSeparator(path
[1])) ||
64 (isalpha(path
[0]) && path
[1] == ':');
66 return path
.size() > 0 && path
[0] == '/';
70 ////////////////////////////////////////////////////////////////////////////////