From b8ec6977527e27b33ffa79f04ad3556859cf1c43 Mon Sep 17 00:00:00 2001 From: StunxFS Date: Tue, 14 Nov 2023 19:45:16 -0400 Subject: [PATCH] use constant --- lib/std/src/fs/Path.ri | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/std/src/fs/Path.ri b/lib/std/src/fs/Path.ri index 3312126de..52f3e96e6 100644 --- a/lib/std/src/fs/Path.ri +++ b/lib/std/src/fs/Path.ri @@ -17,7 +17,7 @@ public struct Path { /// Returns `true` if the given byte is a valid path separator #[inline] public func is_separator(byte: uint8) -> bool { - return byte == b'/' #if _WINDOWS_ or byte == b'\\' #endif; + return byte == SEPARATOR; } /// Returns `true` if `path` (file or directory) exists. @@ -81,13 +81,13 @@ public struct Path { /// If the path is a file in the current directory (no directory component) /// then returns `.`. /// If the path is the root directory, returns `/`. - public func dir_name(path: string) -> ?string { + public func dirname(path: string) -> ?string { if path.is_empty() { return none; } if pos := path.last_index_of_byte(SEPARATOR) { - if pos == 0 and SEPARATOR == b'/' { - return "/"; + if pos == 0 and SEPARATOR == SEPARATOR { + return separatorStr; } return path[..pos]; } @@ -99,14 +99,14 @@ public struct Path { return ""; } mut end_index: uint := path.len - 1; - while path[end_index] == b'/' : end_index -= 1 { + while path[end_index] == SEPARATOR : end_index -= 1 { if end_index == 0 { return ""; } } mut start_index: uint := end_index; end_index += 1; - while path[start_index] != b'/' : start_index -= 1 { + while path[start_index] != SEPARATOR : start_index -= 1 { if start_index == 0 { return path[0..end_index]; } @@ -114,6 +114,8 @@ public struct Path { return path[start_index + 1 .. end_index]; } + /// Return alls characters found after the last occurrence of `separatorStr`. + /// File extension is included. public func file_name(path: string) -> string { return path.all_after_of_last(separatorStr); } @@ -123,8 +125,6 @@ public struct Path { /// return the text after the `.`. /// Files that end with `.`, or that start with `.` and have no other `.` in their /// name, are considered to have no extension. - /// The returned slice is guaranteed to have its pointer within the start and end - /// pointer address range of `path`, even if it is length zero. public func extension(path: string) -> string { filename := Self.file_name(path); index := filename.last_index_of_byte(b'.') ?? return "";