From 0ddf65c934af16f80ea3f6d11d8957811a12f9a2 Mon Sep 17 00:00:00 2001 From: Erin Date: Mon, 2 May 2022 23:40:42 +0200 Subject: [PATCH] T-Dark letter cases implemented --- ablescript/src/parser.rs | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/ablescript/src/parser.rs b/ablescript/src/parser.rs index 0d70def..b2fc828 100644 --- a/ablescript/src/parser.rs +++ b/ablescript/src/parser.rs @@ -596,12 +596,36 @@ impl<'source> Parser<'source> { } /// Perform lang -> script substitution if in T-Dark block - fn tdark_subst(&self, string: String) -> String { + fn tdark_subst(&self, mut string: String) -> String { if self.tdark { - string.replace("lang", "script") - } else { - string + if let Some(pos) = string.to_lowercase().find("lang") { + let range = pos..pos + 4; + let mut count_upper = 0_u8; + string.replace_range( + range.clone(), + &(string[range] + .chars() + .zip("scri".chars()) + .map(|(lc, sc)| { + if lc.is_uppercase() { + count_upper += 1; + sc.to_ascii_uppercase() + } else { + sc.to_ascii_lowercase() + } + }) + .collect::() + + match count_upper { + 0 | 1 => "pt", + 2 if rand::random() => "Pt", + 2 => "pT", + _ => "PT", + }), + ) + } } + + string } }