1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

os: add windows_volume function (#14721)

This commit is contained in:
Ben
2022-06-08 20:26:24 +02:00
committed by GitHub
parent 5ac9b5c9f1
commit c6b1c8d07a
3 changed files with 53 additions and 23 deletions

View File

@@ -0,0 +1,18 @@
module os
// windows_volume returns the volume name from the given `path` on a Windows system.
// An empty string is returned if no Windows volume is present.
// NOTE: An error is returned if the current operating system is not Windows.
// Examples (on a Windows system):
// ```v
// assert os.windows_volume(r'C:\path\to\file.v') == 'C:'
// assert os.windows_volume('D:') == 'D:'
// assert os.windows_volume(r'\\Host\share\files\file.v') == r'\\Host\share'
// ```
pub fn windows_volume(path string) string {
volume_len := win_volume_len(path)
if volume_len == 0 {
return empty_str
}
return path[..volume_len]
}