io: cleanup prefix_and_suffix/1 util function (#21562)

This commit is contained in:
Turiiya 2024-05-25 02:46:34 +02:00 committed by GitHub
parent 14018f1c45
commit a7cf1ad7d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -77,18 +77,9 @@ fn random_number() string {
}
fn prefix_and_suffix(pattern string) !(string, string) {
mut pat := pattern
if pat.contains(os.path_separator) {
if pattern.contains(os.path_separator) {
return error('pattern cannot contain path separators (${os.path_separator}).')
}
pos := pat.index_u8_last(`*`)
mut prefix := ''
mut suffix := ''
if pos != -1 {
prefix = pat.substr(0, pos)
suffix = pat.substr(pos + 1, pat.len)
} else {
prefix = pat
}
prefix, suffix := pattern.rsplit_once('*') or { pattern, '' }
return prefix, suffix
}