forked from AbleScript/ablescript
Merge pull request 'T-Dark letter cases implemented' (#10) from feature/tdark-cases into master
Reviewed-on: https://git.ablecorp.us:443/AbleScript/able-script/pulls/10
This commit is contained in:
commit
fd97655e04
|
@ -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::<String>()
|
||||
+ match count_upper {
|
||||
0 | 1 => "pt",
|
||||
2 if rand::random() => "Pt",
|
||||
2 => "pT",
|
||||
_ => "PT",
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
string
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue