#![allow(clippy::needless_doctest_main)]
#![doc = include_str!("../README.md")]
#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(feature = "std")]
mod path;
#[cfg(test)]
mod tests;
#[cfg(feature = "std")]
pub use path::{PathBufExt, PathExt};
#[cfg(all(not(feature = "std"), feature = "alloc"))]
extern crate alloc;
#[cfg(all(not(feature = "std"), feature = "alloc"))]
use alloc::string::String;
pub const BANNED: &[char] = &generate_banned();
const fn generate_banned() -> [char; 41] {
let mut banned = ['\0'; 41];
let mut i = 0;
while i <= 31 {
banned[i as usize] = char::from_u32(i).unwrap();
i += 1;
}
let mut i = 0;
let reserved = &['<', '>', ':', '"', '/', '\\', '|', '?', '*'];
while i < reserved.len() {
banned[i + 32] = reserved[i];
i += 1;
}
banned
}
#[doc(alias = "sanitize")]
#[must_use]
#[cfg(feature = "alloc")]
pub fn sanitise(input: impl AsRef<str>, to: &str) -> String { input.as_ref().replace(BANNED, to) }
#[must_use]
pub fn is_dirty(input: impl AsRef<str>) -> bool { input.as_ref().contains(BANNED) }
#[must_use]
pub fn is_clean(input: impl AsRef<str>) -> bool { !is_dirty(input) }