move getMapIdByValue to FieldMask.h
[hiphop-php.git] / hphp / util / file.h
blobc5d6388f5fb4876eec88f84b02a341099e78a3dc
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 #pragma once
19 #include <folly/Range.h>
21 #include <ctype.h>
23 namespace HPHP::FileUtil {
24 ////////////////////////////////////////////////////////////////////////////////
27 * Check if the given character is a directory separator for the current
28 * platform.
30 inline bool isDirSeparator(char c) {
31 #ifdef _MSC_VER
32 return c == '/' || c == '\\';
33 #else
34 return c == '/';
35 #endif
39 * Get the preferred directory separator for the current platform.
41 inline char getDirSeparator() {
42 #ifdef _MSC_VER
43 return '\\';
44 #else
45 return '/';
46 #endif
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) {
54 #ifdef _MSC_VER
55 auto const len = path.size();
56 if (len < 2) {
57 return false;
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
62 // that would allow.
63 return (isDirSeparator(path[0]) && isDirSeparator(path[1])) ||
64 (isalpha(path[0]) && path[1] == ':');
65 #else
66 return path.size() > 0 && path[0] == '/';
67 #endif
70 ////////////////////////////////////////////////////////////////////////////////