diff options
| author | Lzu Tao <taolzu@gmail.com> | 2020-07-10 15:59:25 +0000 |
|---|---|---|
| committer | Lzu Tao <taolzu@gmail.com> | 2020-07-12 14:51:04 +0000 |
| commit | 90a7d2470a7ae29c529ae2a3684c47839c57d763 (patch) | |
| tree | 710cda1e4fe14d8eca830f5055444584611be13b | |
| parent | 0ff820cb62f0b21d422440353b8def10c05ed735 (diff) | |
| download | rust-90a7d2470a7ae29c529ae2a3684c47839c57d763.tar.gz rust-90a7d2470a7ae29c529ae2a3684c47839c57d763.zip | |
Make is_valid_drive_letter function
| -rw-r--r-- | src/libstd/sys/windows/path.rs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/libstd/sys/windows/path.rs b/src/libstd/sys/windows/path.rs index e70ddce3aa5..e2b48a22dcd 100644 --- a/src/libstd/sys/windows/path.rs +++ b/src/libstd/sys/windows/path.rs @@ -22,6 +22,12 @@ pub fn is_verbatim_sep(b: u8) -> bool { b == b'\\' } +// In most DOS systems, it is not possible to have more than 26 drive letters. +// See <https://en.wikipedia.org/wiki/Drive_letter_assignment#Common_assignments>. +pub fn is_valid_drive_letter(disk: u8) -> bool { + disk.is_ascii_alphabetic() +} + pub fn parse_prefix(path: &OsStr) -> Option<Prefix<'_>> { use crate::path::Prefix::*; unsafe { @@ -52,7 +58,7 @@ pub fn parse_prefix(path: &OsStr) -> Option<Prefix<'_>> { let idx = path.iter().position(|&b| b == b'\\'); if idx == Some(2) && path[1] == b':' { let c = path[0]; - if c.is_ascii() && (c as char).is_alphabetic() { + if is_valid_drive_letter(c) { // \\?\C:\ path return Some(VerbatimDisk(c.to_ascii_uppercase())); } @@ -77,7 +83,7 @@ pub fn parse_prefix(path: &OsStr) -> Option<Prefix<'_>> { } else if path.get(1) == Some(&b':') { // C: let c = path[0]; - if c.is_ascii() && (c as char).is_alphabetic() { + if is_valid_drive_letter(c) { return Some(Disk(c.to_ascii_uppercase())); } } |
