use alloc::format;
use alloc::string::{String, ToString};
use alloc::vec::Vec;
use crate::runtime::{Runtime, RuntimeError};
pub(crate) fn the_files_of_the_pattern(
rt: &mut Runtime<'_>,
pattern: &str,
line: u32,
) -> Result<Vec<String>, RuntimeError> {
let folder = rt
.desktop()
.working_directory()
.map_err(|reason| RuntimeError {
message: reason,
line,
})?;
rt.desktop()
.list_files(&folder, pattern, "")
.map_err(|reason| RuntimeError {
message: reason,
line,
})
}
pub(crate) fn is_a_pattern(path: &str) -> bool {
path.contains('*') || path.contains('?')
}
pub(crate) fn the_name_of_the_file(path: &str) -> &str {
match path.rfind(['/', '\\']) {
Some(index) => &path[index + 1..],
None => path,
}
}
pub(crate) fn the_path_in_the_folder(folder: &str, name: &str) -> String {
if folder.is_empty() {
return name.to_string();
}
if folder.ends_with('/') || folder.ends_with('\\') {
return format!("{folder}{name}");
}
format!("{folder}/{name}")
}