Table of contents
Namespace: Com\Tecnick\Unicode
class Bidi
Source: src/Bidi.php:51
Unicode Bidirectional Algorithm (UAX #9): reorders each paragraph of the input from logical to visual order and applies the Arabic shaping. The shaped logical order with the resolved levels is also available, to reorder each line after line breaking. https://www.unicode.org/reports/tr9/
Constants
CONTAINS_ARABIC
The input contains Arabic characters (bidi class AL or AN)
public const CONTAINS_ARABIC = 2
Source: src/Bidi.php:61
CONTAINS_FORMATTING
The input contains explicit formatting characters (LRE, RLE, PDF, LRO, RLO, LRI, RLI, FSI, PDI)
public const CONTAINS_FORMATTING = 4
Source: src/Bidi.php:67
CONTAINS_REMOVED
The input contains characters of bidi class BN, which rule X9 removes (ZWJ, ZWNJ, ZWNBSP, SOFT HYPHEN and most of the control characters)
public const CONTAINS_REMOVED = 8
Source: src/Bidi.php:73
CONTAINS_RTL
The input contains strong right-to-left characters (bidi class R, AL or AN)
public const CONTAINS_RTL = 1
Source: src/Bidi.php:56
LINE_BREAK_CONTROLS
Characters of bidi class BN that control line breaking and that are kept in the logical output when the constructor is called with $keepbreaks set to true: SOFT HYPHEN, ZERO WIDTH SPACE, WORD JOINER and ZERO WIDTH NO-BREAK SPACE.
public const LINE_BREAK_CONTROLS = [0xad => true, 0x200b => true, 0x2060 => true, 0xfeff => true]
Source: src/Bidi.php:82
Methods
__construct()
Process the input with the Bidirectional Algorithm
public __construct(
?string $str = null,
?string[] $chrarr = null,
?int[] $ordarr = null,
string|TextDirection $forcedir = '',
bool $shaping = true,
bool $keepbreaks = false
)
Parameters:
$str(?string): String to convert (if null it will be generated from $chrarr or $ordarr)$chrarr(?string[]): Array of UTF-8 chars (if empty it will be generated from $str or $ordarr)$ordarr(?int[]): Array of UTF-8 codepoints (if empty it will be generated from $str or $chrarr)$forcedir(string|TextDirection): If ‘R’ forces RTL, if ‘L’ forces LTR (’’ auto), or a TextDirection case$shaping(bool): If true enable the shaping algorithm$keepbreaks(bool): If true the LINE_BREAK_CONTROLS characters are kept in the logical output (getLogicalOrdArray()), each with the level of the character before it, or the paragraph level at the start. They take no part in the resolution of the levels.
Throws:
Source: src/Bidi.php:172
getCharKeys()
Returns an array with processed chars as keys
public getCharKeys(): array<int,true>
Returns: array<int,true>
Source: src/Bidi.php:421
getChrArray()
Returns the processed array of UTF-8 chars
public getChrArray(): string[]
Returns: string[]
Throws:
Source: src/Bidi.php:383
getLogicalLevels()
Returns the resolved embedding level of each entry of getLogicalOrdArray().
public getLogicalLevels(): int[]
Returns: int[]
Source: src/Bidi.php:312
getLogicalOrdArray()
Returns the codepoints in logical order, without the characters removed by rule X9 and with the Arabic shaping applied (rules L1 to L4 not applied).
public getLogicalOrdArray(): int[]
Returns: int[]
Source: src/Bidi.php:302
getLogicalParagraphLevels()
Returns the paragraph embedding level of each entry of getLogicalOrdArray().
public getLogicalParagraphLevels(): int[]
Returns: int[]
Source: src/Bidi.php:322
getNumChars()
Returns the number of characters in the processed string
public getNumChars(): int
Returns: int
Throws:
Source: src/Bidi.php:397
getOrdArray()
Returns the processed array of UTF-8 codepoints
public getOrdArray(): int[]
Returns: int[]
Source: src/Bidi.php:291
getString()
Returns the processed string
public getString(): string
Returns: string
Throws:
Source: src/Bidi.php:407
reorderLine()
Reorders one line of one paragraph from logical to visual order (rules L1, L2 and L4).
public static reorderLine(int[] $ordarr, int[] $levels, int $pel): int[]
Parameters:
$ordarr(int[]): Codepoints of the line in logical order$levels(int[]): Resolved embedding level of each codepoint$pel(int): Paragraph embedding level
Returns: int[]: Codepoints in visual order
Throws:
Source: src/Bidi.php:338