| 57 | } |
| 58 | |
| 59 | StringRef find_first_component(StringRef path, Style style) { |
| 60 | // Look for this first component in the following order. |
| 61 | // * empty (in this case we return an empty string) |
| 62 | // * either C: or {//,\\}net. |
| 63 | // * {/,\} |
| 64 | // * {file,directory}name |
| 65 | |
| 66 | if (path.empty()) |
| 67 | return path; |
| 68 | |
| 69 | if (real_style(style) == Style::windows) { |
| 70 | // C: |
| 71 | if (path.size() >= 2 && |
| 72 | std::isalpha(static_cast<unsigned char>(path[0])) && path[1] == ':') |
| 73 | return path.substr(0, 2); |
| 74 | } |
| 75 | |
| 76 | // //net |
| 77 | if ((path.size() > 2) && is_separator(path[0], style) && |
| 78 | path[0] == path[1] && !is_separator(path[2], style)) { |
| 79 | // Find the next directory separator. |
| 80 | size_t end = path.find_first_of(separators(style), 2); |
| 81 | return path.substr(0, end); |
| 82 | } |
| 83 | |
| 84 | // {/,\} |
| 85 | if (is_separator(path[0], style)) |
| 86 | return path.substr(0, 1); |
| 87 | |
| 88 | // * {file,directory}name |
| 89 | size_t end = path.find_first_of(separators(style)); |
| 90 | return path.substr(0, end); |
| 91 | } |
| 92 | |
| 93 | // Returns the first character of the filename in str. For paths ending in |
| 94 | // '/', it returns the position of the '/'. |
no test coverage detected