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 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_UTIL_FILE_H_
18 #define incl_HPHP_UTIL_FILE_H_
20 #include <folly/Range.h>
24 namespace HPHP
{ namespace FileUtil
{
25 ////////////////////////////////////////////////////////////////////////////////
28 * Check if the given character is a directory separator for the current
31 inline bool isDirSeparator(char c
) {
33 return c
== '/' || c
== '\\';
40 * Get the preferred directory separator for the current platform.
42 inline char getDirSeparator() {
51 * Check if the given path is an absolute path. This does not guarantee that
52 * the path is canonicalized.
54 inline bool isAbsolutePath(folly::StringPiece path
) {
56 auto const len
= path
.size();
60 // NOTE: Boost actually checks if the last character of the first path element
61 // is a colon, rather than if the first character is an alpha followed by a
62 // colon. This is fine for now, as I don't know of any other forms of paths
64 return (isDirSeparator(path
[0]) && isDirSeparator(path
[1])) ||
65 (isalpha(path
[0]) && path
[1] == ':');
67 return path
.size() > 0 && path
[0] == '/';
71 ////////////////////////////////////////////////////////////////////////////////