|
51 | 51 | _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
|
52 | 52 |
|
53 | 53 | namespace {
|
| 54 | + |
| 55 | +bool isSeparator(path::value_type C) { |
| 56 | + if (C == '/') |
| 57 | + return true; |
| 58 | +#if defined(_LIBCPP_WIN32API) |
| 59 | + if (C == '\\') |
| 60 | + return true; |
| 61 | +#endif |
| 62 | + return false; |
| 63 | +} |
| 64 | + |
54 | 65 | namespace parser {
|
55 | 66 |
|
56 | 67 | using string_view_t = path::__string_view;
|
@@ -271,21 +282,21 @@ struct PathParser {
|
271 | 282 | }
|
272 | 283 |
|
273 | 284 | PosPtr consumeSeparator(PosPtr P, PosPtr End) const noexcept {
|
274 |
| - if (P == End || *P != '/') |
| 285 | + if (P == End || !isSeparator(*P)) |
275 | 286 | return nullptr;
|
276 | 287 | const int Inc = P < End ? 1 : -1;
|
277 | 288 | P += Inc;
|
278 |
| - while (P != End && *P == '/') |
| 289 | + while (P != End && isSeparator(*P)) |
279 | 290 | P += Inc;
|
280 | 291 | return P;
|
281 | 292 | }
|
282 | 293 |
|
283 | 294 | PosPtr consumeName(PosPtr P, PosPtr End) const noexcept {
|
284 |
| - if (P == End || *P == '/') |
| 295 | + if (P == End || isSeparator(*P)) |
285 | 296 | return nullptr;
|
286 | 297 | const int Inc = P < End ? 1 : -1;
|
287 | 298 | P += Inc;
|
288 |
| - while (P != End && *P != '/') |
| 299 | + while (P != End && !isSeparator(*P)) |
289 | 300 | P += Inc;
|
290 | 301 | return P;
|
291 | 302 | }
|
@@ -1393,7 +1404,7 @@ string_view_t path::__root_path_raw() const {
|
1393 | 1404 | auto PP = PathParser::CreateBegin(__pn_);
|
1394 | 1405 | if (PP.State == PathParser::PS_InRootName) {
|
1395 | 1406 | auto NextCh = PP.peek();
|
1396 |
| - if (NextCh && *NextCh == '/') { |
| 1407 | + if (NextCh && isSeparator(*NextCh)) { |
1397 | 1408 | ++PP;
|
1398 | 1409 | return createView(__pn_.data(), &PP.RawEntry.back());
|
1399 | 1410 | }
|
@@ -1491,6 +1502,10 @@ static PathPartKind ClassifyPathPart(string_view_t Part) {
|
1491 | 1502 | return PK_DotDot;
|
1492 | 1503 | if (Part == PS("/"))
|
1493 | 1504 | return PK_RootSep;
|
| 1505 | +#if defined(_LIBCPP_WIN32API) |
| 1506 | + if (Part == PS("\\")) |
| 1507 | + return PK_RootSep; |
| 1508 | +#endif |
1494 | 1509 | return PK_Filename;
|
1495 | 1510 | }
|
1496 | 1511 |
|
|
0 commit comments