use url::Url;
#[cfg(not(target_arch = "wasm32"))]
pub fn normalize_uri(uri: &str) -> String {
if let Some(normalized) = crate::classify::normalize_legacy_windows_uri(uri) {
return normalized;
}
let path = std::path::Path::new(uri);
if path.is_absolute()
&& let Ok(uri_string) = crate::fs_path_to_uri(path)
{
return uri_string;
}
if let Ok(url) = Url::parse(uri) {
if url.scheme() == "file"
&& url.host_str() == Some("localhost")
&& let Some(fs_path) = crate::uri_to_fs_path(uri)
&& let Ok(normalized) = crate::fs_path_to_uri(&fs_path)
{
return normalized;
}
return url.to_string();
}
if let Ok(uri_string) = crate::fs_path_to_uri(path) {
return uri_string;
}
if uri.starts_with("file://")
&& let Some(fs_path) = crate::uri_to_fs_path(uri)
&& let Ok(normalized) = crate::fs_path_to_uri(&fs_path)
{
return normalized;
}
uri.to_string()
}
#[cfg(target_arch = "wasm32")]
pub fn normalize_uri(uri: &str) -> String {
if let Some(normalized) = crate::classify::normalize_legacy_windows_uri(uri) {
return normalized;
}
if let Ok(url) = Url::parse(uri) { url.to_string() } else { uri.to_string() }
}