API / Minn\Html / TokenMap

TokenMap final class

Minn\Html\TokenMap · public/minn/src/Minn/Html/TokenMap.php · 87 lines

A map from words to replacements that reads the longest word at a place in a text (as character reference names are read): words shorter than the key length stand alone, the others are grouped by their first bytes, longest first.

Uses 1

Constants and properties

privatearray $small
privatearray $groups
privatereadonly int $keyLength

Promoted from the constructor.

Public

new__construct(array $mappings, int $keyLength)#
$mappingsarray<string, string>
methodkeyLength(): int#

How many leading bytes group the words.

methodcontains(string $word, string $caseSensitivity): bool#

Whether the word is in the map ("case-sensitive" or "ascii-case-insensitive").

methodread(string $text, int $offset, string $caseSensitivity): ?array#

The replacement for the longest word at $offset, and the word's length; null when none starts there.

@return array{0: string, 1: int}|null
methodtoArray(): array#

Every word and its replacement: the short words first, then each group longest first.

@return array<string, string>

Internals 1

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privatesame(string $a, string $b, string $caseSensitivity): bool#