Add logging for comparison behaviors
[hiphop-php.git] / hphp / util / file.h
blob8c88f9bc9808173a47e95ce34dc56562aa3bb20f
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
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>
22 #include <ctype.h>
24 namespace HPHP { namespace FileUtil {
25 ////////////////////////////////////////////////////////////////////////////////
28 * Check if the given character is a directory separator for the current
29 * platform.
31 inline bool isDirSeparator(char c) {
32 #ifdef _MSC_VER
33 return c == '/' || c == '\\';
34 #else
35 return c == '/';
36 #endif
40 * Get the preferred directory separator for the current platform.
42 inline char getDirSeparator() {
43 #ifdef _MSC_VER
44 return '\\';
45 #else
46 return '/';
47 #endif
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) {
55 #ifdef _MSC_VER
56 auto const len = path.size();
57 if (len < 2) {
58 return false;
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
63 // that would allow.
64 return (isDirSeparator(path[0]) && isDirSeparator(path[1])) ||
65 (isalpha(path[0]) && path[1] == ':');
66 #else
67 return path.size() > 0 && path[0] == '/';
68 #endif
71 ////////////////////////////////////////////////////////////////////////////////
74 #endif