From 5915dd730f2cc98a47b00e5160da90c923d9ea68 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Mon, 12 Aug 2024 15:45:23 -0700 Subject: [PATCH] redo displayname test --- src/main.rs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 759a219..fe35b06 100644 --- a/src/main.rs +++ b/src/main.rs @@ -530,6 +530,27 @@ impl std::str::FromStr for ScriptActionParseResult { } } +fn is_first_letter_lowercase(s:&str)->bool{ + s.chars().next().map(char::is_lowercase).unwrap_or(false) +} + +fn is_title_case(display_name:&str)->bool{ + display_name.len()!=0 + &&!is_first_letter_lowercase(display_name) + &&{ + let display_name_pattern=lazy_regex::regex!(r"\b\S+"); + display_name_pattern.find_iter(display_name) + .all(|capture|match capture.as_str(){ + "a"=>true, + "an"=>true, + "and"=>true, + "the"=>true, + "of"=>true, + other=>!is_first_letter_lowercase(other), + }) + } +} + fn interactive() -> AResult<()>{ let mut id=get_id()?; //Construct allowed scripts @@ -538,7 +559,6 @@ fn interactive() -> AResult<()>{ let mut replace_map=get_replace_map()?; let mut blocked = get_blocked()?; let model_name_pattern=lazy_regex::regex!(r"^[a-z0-9_]+$"); - let display_name_pattern=lazy_regex::regex!(r"\b[a-z]"); 'map_loop: for entry in std::fs::read_dir("maps/unprocessed")? { let file_thing=entry?; @@ -571,7 +591,7 @@ fn interactive() -> AResult<()>{ //mark file as edited so a new file is generated replace_count+=1; } - if displayname.len()==0||display_name_pattern.is_match(displayname.as_str()){ + if !is_title_case(displayname.as_str()){ //illegal let new_display_name; loop{ @@ -579,7 +599,7 @@ fn interactive() -> AResult<()>{ std::io::Write::flush(&mut std::io::stdout())?; let mut input_string=String::new(); std::io::stdin().read_line(&mut input_string)?; - if displayname.len()!=0||!display_name_pattern.is_match(input_string.trim()){ + if is_title_case(input_string.trim()){ new_display_name=input_string.trim().to_owned(); break; } @@ -665,7 +685,7 @@ fn interactive() -> AResult<()>{ ScriptActionParseResult::Delete => ScriptAction::Delete, } }; - + let location=get_full_name(&dom, script); match source_action{ ScriptAction::Pass => println!("passed source location={}",location),