/// Dense-script detection for the chunk limit (`docs/TRANSLATION_OUTPUT.md` ยง3). /// /// The limit is script-based, not language-based: one CJK, Arabic, Thai or Indic character is /// enough to select the smaller limit. Latin, Cyrillic and Greek stay on the larger limit. public enum TextScript { private static let denseRanges: [ClosedRange] = [ 0x0590 ... 0x05FF, // Hebrew 0x0600 ... 0x06FF, // Arabic 0x0750 ... 0x077F, // Arabic Supplement 0x0900 ... 0x097F, // Devanagari 0x0980 ... 0x09FF, // Bengali 0x0A00 ... 0x0A7F, // Gurmukhi 0x0A80 ... 0x0AFF, // Gujarati 0x0B00 ... 0x0B7F, // Oriya 0x0B80 ... 0x0BFF, // Tamil 0x0C00 ... 0x0C7F, // Telugu 0x0C80 ... 0x0CFF, // Kannada 0x0D00 ... 0x0D7F, // Malayalam 0x0D80 ... 0x0DFF, // Sinhala 0x0E00 ... 0x0E7F, // Thai 0x0E80 ... 0x0EFF, // Lao 0x0F00 ... 0x0FFF, // Tibetan 0x1000 ... 0x109F, // Myanmar 0x1200 ... 0x137F, // Ethiopic 0x1780 ... 0x17FF, // Khmer 0x1800 ... 0x18AF, // Mongolian 0x2E80 ... 0x9FFF, // CJK, Hiragana, Katakana and Hangul compatibility 0xA960 ... 0xA97F, // Hangul Jamo Extended-A 0xAC00 ... 0xD7AF, // Hangul syllables 0xF900 ... 0xFAFF, // CJK compatibility ideographs 0xFE30 ... 0xFE4F, // CJK compatibility forms 0xFF66 ... 0xFFDC, // Half-width Katakana and Hangul ] /// True when `text` contains at least one dense-script scalar. public static func isDense(_ text: String) -> Bool { text.unicodeScalars.contains { scalar in denseRanges.contains { $0.contains(scalar.value) } } } }