Skip to content

Commit 90a7d24

Browse files
committed
Make is_valid_drive_letter function
1 parent 0ff820c commit 90a7d24

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/libstd/sys/windows/path.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ pub fn is_verbatim_sep(b: u8) -> bool {
2222
b == b'\\'
2323
}
2424

25+
// In most DOS systems, it is not possible to have more than 26 drive letters.
26+
// See <https://en.wikipedia.org/wiki/Drive_letter_assignment#Common_assignments>.
27+
pub fn is_valid_drive_letter(disk: u8) -> bool {
28+
disk.is_ascii_alphabetic()
29+
}
30+
2531
pub fn parse_prefix(path: &OsStr) -> Option<Prefix<'_>> {
2632
use crate::path::Prefix::*;
2733
unsafe {
@@ -52,7 +58,7 @@ pub fn parse_prefix(path: &OsStr) -> Option<Prefix<'_>> {
5258
let idx = path.iter().position(|&b| b == b'\\');
5359
if idx == Some(2) && path[1] == b':' {
5460
let c = path[0];
55-
if c.is_ascii() && (c as char).is_alphabetic() {
61+
if is_valid_drive_letter(c) {
5662
// \\?\C:\ path
5763
return Some(VerbatimDisk(c.to_ascii_uppercase()));
5864
}
@@ -77,7 +83,7 @@ pub fn parse_prefix(path: &OsStr) -> Option<Prefix<'_>> {
7783
} else if path.get(1) == Some(&b':') {
7884
// C:
7985
let c = path[0];
80-
if c.is_ascii() && (c as char).is_alphabetic() {
86+
if is_valid_drive_letter(c) {
8187
return Some(Disk(c.to_ascii_uppercase()));
8288
}
8389
}

0 commit comments

Comments
 (0)