bidi
The Unicode bidirectional algorithm: the right display order when right to left and left to right text are mixed.
import bidi
Text is stored in memory in the order it was typed, but when right to left and left to right scripts are mixed, the order seen on screen is not that order. Browsers and editors do the rearranging with the Unicode bidirectional algorithm.
If you are drawing text yourself somewhere that does not do this for you, onto an image, in a terminal or on a simple display, the bidi package runs the same algorithm and tells you where every character goes.
Each function takes a paragraph direction: DirAuto infers it from the first strong character in the text, and the other two set it in advance. The "level" of each character is a number: even means left to right and odd means right to left.
Constants and variables
DirAuto
const DirAuto: i32 = 0import bidi
func main:
s := "abc سلام"
println bidi.ParagraphLevel(s, bidi.DirAuto), bidi.ParagraphLevel("سلام abc", bidi.DirAuto)
println bidi.ParagraphLevel(s, bidi.DirRTL), bidi.ParagraphLevel("سلام", bidi.DirLTR)
println bidi.Levels(s, bidi.DirLTR)
println bidi.VisualOrder(s, bidi.DirLTR)
println bidi.Reorder(s, bidi.DirLTR)
endDirLTR
const DirLTR: i32 = 1The example for this item is shown with the ones above: bidi-Reorder.salam
DirRTL
const DirRTL: i32 = 2The example for this item is shown with the ones above: bidi-Reorder.salam
Functions
ParagraphLevel
func ParagraphLevel(s: str, dir: int): intThe example for this item is shown with the ones above: bidi-Reorder.salam
Levels
func Levels(s: str, dir: int): Vector<int>The example for this item is shown with the ones above: bidi-Reorder.salam
VisualOrder
func VisualOrder(s: str, dir: int): Vector<int>i is the index of the character that appears in position i.The example for this item is shown with the ones above: bidi-Reorder.salam
Reorder
func Reorder(s: str, dir: int): strThe example for this item is shown with the ones above: bidi-Reorder.salam