pub fn detect_base_direction(text: &str) -> TextDirectionExpand description
Detects the base direction of text using the first strong directional character.
This follows the Unicode Bidirectional Algorithm (UBA) rule P2/P3:
- Find the first character with a strong directional type (L, R, or AL)
- If it’s L, the paragraph direction is LTR
- If it’s R or AL, the paragraph direction is RTL
- If no strong character is found, defaults to LTR
§Examples
use gpuikit::input::detect_base_direction;
// English text is LTR
assert!(detect_base_direction("Hello world").is_ltr());
// Arabic text is RTL
assert!(detect_base_direction("مرحبا").is_rtl());
// Hebrew text is RTL
assert!(detect_base_direction("שלום").is_rtl());
// Mixed text uses first strong character
assert!(detect_base_direction("Hello مرحبا").is_ltr());
assert!(detect_base_direction("مرحبا Hello").is_rtl());
// Empty or neutral-only text defaults to LTR
assert!(detect_base_direction("").is_ltr());
assert!(detect_base_direction("123").is_ltr());