Skip to content

Commit ca2606f

Browse files
committed
Use constants
1 parent e27eb78 commit ca2606f

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/filepath.gleam

+18-2
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,28 @@ pub fn split_windows(path: String) -> List(String) {
135135
}
136136
}
137137

138+
const codepoint_slash = 47
139+
140+
const codepoint_backslash = 92
141+
142+
const codepoint_colon = 58
143+
144+
const codepoint_a = 65
145+
146+
const codepoint_z = 90
147+
148+
const codepoint_a_up = 97
149+
150+
const codepoint_z_up = 122
151+
138152
fn pop_windows_drive_specifier(path: String) -> #(Option(String), String) {
139153
let start = string.slice(from: path, at_index: 0, length: 3)
140154
let codepoints = string.to_utf_codepoints(start)
141155
case list.map(codepoints, string.utf_codepoint_to_int) {
142-
[drive, colon, slash] if { slash == 47 || slash == 92 } && colon == 58 && {
143-
drive >= 65 && drive <= 90 || drive >= 97 && drive <= 122
156+
[drive, colon, slash] if {
157+
slash == codepoint_slash || slash == codepoint_backslash
158+
} && colon == codepoint_colon && {
159+
drive >= codepoint_a && drive <= codepoint_z || drive >= codepoint_a_up && drive <= codepoint_z_up
144160
} -> {
145161
let drive_letter = string.slice(from: path, at_index: 0, length: 1)
146162
let drive = string.lowercase(drive_letter) <> ":/"

0 commit comments

Comments
 (0)