Bidi::Level
Embedding Level
Embedding Levels are numbers between 0 and 126 (inclusive), where even values denote a left-to-right (LTR) direction and odd values a right-to-left (RTL) direction.
This struct maintains a valid status for level numbers, meaning that creating a new level, or
mutating an existing level, with the value smaller than 0 (before conversion to u8) or
larger than 125 results in an Error.
Constants
New LTR level with smallest number value (0).
During explicit level resolution, embedding level can go as high as max_depth.
During implicit level resolution, embedding level can go as high as max_depth + 1.
New RTL level with smallest number value (1).
Constructors
Create level from number, raising an exception if invalid.
This is similar to Rust's From<u8> implementation.
Class methods
Create new level, fail if number is larger than max_depth + 1.
Create a new explicit Level with the given number, returning an error if out of range. Explicit levels are limited to MAX_EXPLICIT_DEPTH (125).
Converts a byte slice to a slice of Levels
Does not check if each level is within bounds (<= MAX_IMPLICIT_DEPTH),
which is not a requirement for safety but is a requirement for correctness of the algorithm.
Note: In Crystal, we can't do the same unsafe conversion as Rust, so we'll create a new array. This is less efficient but safe.
If levels has any RTL (odd) level
This information is usually used to skip re-ordering of text when no RTL level is present
Create new level, fail if number is larger than max_depth.
Instance methods
Appends this struct's name and instance variables names and values to the given IO.
struct Point
def initialize(@x : Int32, @y : Int32)
end
end
p1 = Point.new 1, 2
p1.to_s # "Point(@x=1, @y=2)"
p1.inspect # "Point(@x=1, @y=2)"
The next LTR (even) level greater than this, or fail if number is larger than max_depth.
The next RTL (odd) level greater than this, or fail if number is larger than max_depth.
The lowest RTL (odd) level greater than or equal to this, or fail if number is larger than
max_depth + 1.
Raise level by amount, fail if number is larger than max_depth + 1.
Raise level by amount, fail if number is larger than max_depth.