use std::collections::HashMap;
use std::iter::zip;
pub const NOT_ALLOWED_NAMES_WIN11: [&str; 28] = [
"CON", "PRN", "AUX", "NUL",
"COM1", "COM¹", "COM2", "COM²", "COM3", "COM³", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
"LPT1", "LPT¹", "LPT2", "LPT²", "LPT3", "LPT³", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9",
];
pub const NOT_ALLOWED_NAMES: [&str; 30] = [
"CON", "PRN", "AUX", "NUL",
"COM1", "COM¹", "COM2", "COM²", "COM3", "COM³", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
"LPT1", "LPT¹", "LPT2", "LPT²", "LPT3", "LPT³", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9",
"COM0", "LPT0",
];
pub const NOT_ALLOWED_CHARS: [char; 41] = [
'\0', '\u{1}', '\u{2}', '\u{3}', '\u{4}', '\u{5}',
'\u{6}', '\u{7}', '\u{8}', '\t', '\n', '\u{b}',
'\u{c}', '\r', '\u{e}', '\u{f}', '\u{10}', '\u{11}',
'\u{12}', '\u{13}', '\u{14}', '\u{15}', '\u{16}',
'\u{17}', '\u{18}', '\u{19}', '\u{1a}', '\u{1b}',
'\u{1c}', '\u{1d}', '\u{1e}', '\u{1f}',
'\\', '/', ':', '*', '?', '"', '<', '>', '|',
];
#[derive(Debug)]
pub enum ReplaceMethod {
Fullwidth(ReplaceChar),
Replace(ReplaceChar),
Remove,
}
pub struct ReplaceMethodTableConstructor {
pub replace_method: ReplaceMethod,
pub table: HashMap<char, char>,
}
impl ReplaceMethodTableConstructor {
fn new(replace_method: ReplaceMethod) -> Self {
let construct_table = Self::construct_table(&replace_method);
Self {
replace_method,
table: construct_table,
}
}
fn construct_table(replace_method: &ReplaceMethod) -> HashMap<char, char> {
match replace_method {
ReplaceMethod::Fullwidth(replace_char) => {
let mut table = HashMap::new();
for i in 0..32 {
table.insert(char::from(i), replace_char.get_char());
}
for (original, fullwidth_replace) in zip("\\/:*?\"<>|".chars(), "⧵/:*?"<>∣".chars()) {
table.insert(original, fullwidth_replace);
}
table
},
ReplaceMethod::Replace(replace_char) => {
let mut table = HashMap::new();
for i in 0..32 {
table.insert(char::from(i), replace_char.get_char());
}
for original in "\\/:*?\"<>|".chars() {
table.insert(original, replace_char.get_char());
}
table
}
ReplaceMethod::Remove => Self::construct_table(
&ReplaceMethod::Replace(ReplaceChar::Charactor('\0'))
),
}
}
}
impl ReplaceMethod {
pub fn compile(self) -> ReplaceMethodTableConstructor {
ReplaceMethodTableConstructor::new(self)
}
}
pub enum DotHandlingPolicy {
Remove,
Replace(ReplaceChar),
ReplaceWithReplaceMethod,
NotCorrect,
}
#[derive(Debug)]
pub enum ReplaceChar {
Space, DubleQuestionMark, WhiteQuestionMark, RedQuestionMark, Underscore, Charactor(char),
}
impl ReplaceChar {
pub fn get_char(&self) -> char {
match self {
Self::Space => ' ',
Self::DubleQuestionMark => '⁇',
Self::WhiteQuestionMark => '❔',
Self::RedQuestionMark => '❓',
Self::Underscore => '_',
Self::Charactor(charactor) => *charactor,
}
}
}