cortex
aien-dev/cortex
Brought by drakestapleton
cortex / tests / json / gen / ugen_main.rs
| 1 | // Black-box Unicode table generator: queries rustc's std (str::to_lowercase, char::is_whitespace). |
| 2 | // Output lines: L <cp> <cp1> [<cp2> ...] (lower(c) != c, single-char context) |
| 3 | // K <cp> <class> class C (cased, not case-ignorable) / I (case-ignorable) |
| 4 | // W <cp> char::is_whitespace |
| 5 | // D <cp> <str as Debug> writes \u{hex} for this char |
| 6 | fn lw(s: &str) -> String { s.to_lowercase() } |
| 7 | fn main() { |
| 8 | let sig = 'Σ'; |
| 9 | for u in 0u32..=0x10FFFF { |
| 10 | let c = match char::from_u32(u) { Some(c) => c, None => continue }; |
| 11 | let mut one = String::new(); one.push(c); |
| 12 | let lo = lw(&one); |
| 13 | if lo != one { |
| 14 | let mut line = format!("L {}", u); |
| 15 | for d in lo.chars() { line.push_str(&format!(" {}", d as u32)); } |
| 16 | println!("{}", line); |
| 17 | } |
| 18 | if c.is_whitespace() { println!("W {}", u); } |
| 19 | let dbg = format!("{:?}", one); |
| 20 | let plain = format!("\"{}\"", c); |
| 21 | if !matches!(c, '\0' | '\t' | '\r' | '\n' | '\\' | '"') && dbg != plain { |
| 22 | assert_eq!(dbg, format!("\"\\u{{{:x}}}\"", u), "cp {}", u); |
| 23 | println!("D {}", u); |
| 24 | } |
| 25 | if c == sig { println!("K {} C", u); continue; } |
| 26 | let x1 = lw(&format!("{}{}", c, sig)).ends_with('ς'); |
| 27 | let x2 = lw(&format!("A{}{}", c, sig)).ends_with('ς'); |
| 28 | let y = lw(&format!("A{}{}", sig, c)).starts_with("aς"); |
| 29 | assert_eq!(y, !x1, "cp {}", u); |
| 30 | if x1 { println!("K {} C", u); } else if x2 { println!("K {} I", u); } |
| 31 | } |
| 32 | } |