struct

Bidi::Level

Inherits Struct < Value < Object

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.

http://www.unicode.org/reports/tr9/#BD2

Constants

LTR_LEVEL = Level.new(0_u8)

New LTR level with smallest number value (0).

MAX_EXPLICIT_DEPTH = MAX_DEPTH

During explicit level resolution, embedding level can go as high as max_depth.

MAX_IMPLICIT_DEPTH = MAX_DEPTH + 1_u8

During implicit level resolution, embedding level can go as high as max_depth + 1.

RTL_LEVEL = Level.new(1_u8)

New RTL level with smallest number value (1).

Constructors

from(number : UInt8) : Level

Create level from number, raising an exception if invalid. This is similar to Rust's From<u8> implementation.

Source
ltr

New LTR level with smallest number value (0).

Source
max(a : Level, b : Level) : Level

Returns the greater of two levels

Source
new(value : UInt8)

Constructor

Source
rtl

New RTL level with smallest number value (1).

Source

Class methods

create(number : UInt8) : Level | Error

Create new level, fail if number is larger than max_depth + 1.

Source
create_explicit(number : UInt8) : Level | Error

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).

Source
from_slice_unchecked(v : Array(UInt8)) : Array(Level)

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.

Source
has_rtl?(levels : Array(Level)) : Bool

If levels has any RTL (odd) level

This information is usually used to skip re-ordering of text when no RTL level is present

Source
max_explicit_depth

Maximum depth of the directional status stack during explicit resolutions.

Source
max_implicit_depth

Maximum depth of the directional status stack during implicit resolutions.

Source
new_explicit(number : UInt8) : Level | Error

Create new level, fail if number is larger than max_depth.

Source
vec(v : Array(UInt8)) : Array(Level)

Convert array of bytes to array of Levels

Source

Instance methods

<(other : Level) : Bool
Source
<=(other : Level) : Bool
Source
<=>(other : Level) : Int32
Source
==(other : Level) : Bool
Source
==(s : String) : Bool

Used for matching levels in conformance tests

Source
>(other : Level) : Bool
Source
>=(other : Level) : Bool
Source
bidi_class

Generate a character type based on a level (as specified in steps X10 and N2).

Source
inspect(io : IO) : Nil

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)"
Source
lower(amount : UInt8) : Nil | Error

Lower level by amount, fail if number goes below zero.

Source
ltr?

If this level is left-to-right.

Source
new_explicit_next_ltr

The next LTR (even) level greater than this, or fail if number is larger than max_depth.

Source
new_explicit_next_rtl

The next RTL (odd) level greater than this, or fail if number is larger than max_depth.

Source
new_lowest_ge_rtl

The lowest RTL (odd) level greater than or equal to this, or fail if number is larger than max_depth + 1.

Source
number

The level number.

Source
raise(amount : UInt8) : Nil | Error

Raise level by amount, fail if number is larger than max_depth + 1.

Source
raise_explicit(amount : UInt8) : Nil | Error

Raise level by amount, fail if number is larger than max_depth.

Source
rtl?

If this level is right-to-left.

Source
to_s(io : IO) : Nil

String representation

Source
to_u8

Convert to the level number

Source
value
Source
value=(value : UInt8)
Source

Nested types