Returns: starting position of root directory or size if not found
| 1020 | |
| 1021 | // Returns: starting position of root directory or size if not found |
| 1022 | size_type find_root_directory_start(const value_type* path, size_type size, size_type& root_name_size) |
| 1023 | { |
| 1024 | root_name_size = 0; |
| 1025 | if (size == 0) |
| 1026 | return 0; |
| 1027 | |
| 1028 | bool parsing_root_name = false; |
| 1029 | size_type pos = 0; |
| 1030 | |
| 1031 | // case "//", possibly followed by more characters |
| 1032 | if (fs::detail::is_directory_separator(path[0])) |
| 1033 | { |
| 1034 | if (size >= 2 && fs::detail::is_directory_separator(path[1])) |
| 1035 | { |
| 1036 | if (size == 2) |
| 1037 | { |
| 1038 | // The whole path is just a pair of separators |
| 1039 | root_name_size = 2; |
| 1040 | return 2; |
| 1041 | } |
| 1042 | #ifdef BOOST_FILESYSTEM_WINDOWS_API |
| 1043 | // https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file |
| 1044 | // cases "\\?\" and "\\.\" |
| 1045 | else if (size >= 4 && (path[2] == questionmark || path[2] == fs::path::dot) && fs::detail::is_directory_separator(path[3])) |
| 1046 | { |
| 1047 | parsing_root_name = true; |
| 1048 | pos += 4; |
| 1049 | } |
| 1050 | #endif |
| 1051 | else if (fs::detail::is_directory_separator(path[2])) |
| 1052 | { |
| 1053 | // The path starts with three directory separators, which is interpreted as a root directory followed by redundant separators |
| 1054 | return 0; |
| 1055 | } |
| 1056 | else |
| 1057 | { |
| 1058 | // case "//net {/}" |
| 1059 | parsing_root_name = true; |
| 1060 | pos += 2; |
| 1061 | goto find_next_separator; |
| 1062 | } |
| 1063 | } |
| 1064 | #ifdef BOOST_FILESYSTEM_WINDOWS_API |
| 1065 | // https://stackoverflow.com/questions/23041983/path-prefixes-and |
| 1066 | // case "\??\" (NT path prefix) |
| 1067 | else if (size >= 4 && path[1] == questionmark && path[2] == questionmark && fs::detail::is_directory_separator(path[3])) |
| 1068 | { |
| 1069 | parsing_root_name = true; |
| 1070 | pos += 4; |
| 1071 | } |
| 1072 | #endif |
| 1073 | else |
| 1074 | { |
| 1075 | // The path starts with a separator, possibly followed by a non-separator character |
| 1076 | return 0; |
| 1077 | } |
| 1078 | } |
| 1079 |
no test coverage detected