Skip to main content

detect_script

Function detect_script 

Source
pub fn detect_script(text: &str) -> Script
Expand description

Detect the dominant script of a run.

Counts every letter and takes the majority rather than trusting the first one. Both simpler rules break on real books: “first letter wins” calls a Bengali chapter Latin because it opens with “Chapter”, and “first non-Latin wins” calls an English paragraph Greek because it quotes one Greek word.

Kana and hangul are decisive regardless of count - they appear in exactly one language each, and Japanese prose interleaves kana with Han, so the Han belongs to whichever of the two is present.