unicode

Branch: main

Switch branches or tags

Branch: main
Go to file t

413 files indexed

History
Code

bidi/paragraph.mbt
1///|2/// P1-P3: Paragraph Level Determination3///4/// P1: Split the text into separate paragraphs.5/// P2: In each paragraph, find the first character of type L, AL, or R6///     while skipping over any characters between an isolate initiator7///     and its matching PDI or, if it has no matching PDI, the end of the8///     paragraph.9/// P3: If a character is found in P2 and it is of type AL or R, then set10///     the paragraph embedding level to one; otherwise, set it to zero.1112///|13/// Determine the paragraph embedding level for text14/// P2-P3: Find first strong character not in isolate, return its level15fn determine_paragraph_level(text : String, default_level~ : Int32) -> Int32 {16  let mut isolate_count = 017  for c in text {18    let bc = lookup_bidi_class(c)1920    // Skip characters inside isolates21    if bc.is_isolate_initiator() {22      isolate_count += 123      continue24    }25    if bc is PDI {26      if isolate_count > 0 {27        isolate_count -= 128      }29      continue30    }3132    // Only look at characters outside isolates33    if isolate_count == 0 {34      match bc {35        // P3: If AL or R, paragraph level is 1 (RTL)36        AL | R => return 137        // P3: If L, paragraph level is 0 (LTR)38        L => return 039        _ => ()40      }41    }42  }4344  // P3: If no strong character found, use default45  default_level46}47