src/site/php/mb ascii.php

Functions

cfw_mb_ascii()

cfw_mb_ascii(mixed  $s) : bool

True when no byte is >= 0x80, so the single-byte string functions are exact.

Parameters

mixed $s

The value to test.

Returns

bool —

cfw_mb_final_sigma()

cfw_mb_final_sigma(string  $lo) : string|null

Applies Unicode SpecialCasing final-sigma to an ALREADY-lowercased string.

Not applied to mb_strtoupper: there is no uppercase counterpart and running it there would corrupt correct output. The strpos() guard is the common case -- a string with no sigma in it cannot need this.

Parameters

string $lo

The lowercased text.

Returns

string|null —

The text with final sigmas applied, or NULL when the pattern failed.

cfw_mb_utf8()

cfw_mb_utf8(string|null  $encoding) : bool

The case tables are keyed by utf-8, so a caller naming another encoding must not reach them.

Parameters

string|null $encoding

The encoding the caller named.

Returns

bool —

cfw_mb_title_regexp()

cfw_mb_title_regexp() : string|null

The word-boundary pattern for titlecasing, built from the polyfill's Case_Ignorable data.

The 6,201-byte character class is READ from the package rather than copied, so upstream keeps owning the Unicode half; the two-line grammar around it is replaced, because upstream's lookbehind-then-two-letter-groups is wrong in both directions. It blocks a match on the letter after an ignorable and then RE-ENTERS on the letter after that, so "abc<SHY>def" comes out "Abc<SHY>dEf" where mbstring gives "Abc<SHY>def". Consuming ignorables in the word TAIL fixes it: a character inside a match is never offered a second start.

null means the package moved and every caller falls back to the polyfill's own title path.

Returns

string|null —

The pattern, or NULL when the polyfill's data file is not where it was.

cfw_mb_title_word()

cfw_mb_title_word(array  $m) : string

One word: its first character titlecased, the rest lowercased.

The polyfill UPPERCASES the first character, which is a different operation for the 31 Lt digraphs and for every ligature that expands (native titlecases U+FB01 to "Fi", the polyfill uppercases it to "FI").

Parameters

array $m

The match: the whole word, its first character, and its tail.

Returns

string —

cfw_mb_encode_subst()

cfw_mb_encode_subst(string  $s, string  $to) : string

Replaces every character the TARGET encoding cannot represent with "?", which is what native mb_convert_encoding does and what the polyfill does not.

The polyfill converts with //IGNORE, so an unmappable character is DROPPED: a Cyrillic sentence converted to ISO-8859-1 comes back as its spaces. One whole-string probe decides -- iconv without //IGNORE answers false only when something is unmappable -- so the per-character loop is paid by the strings that actually need it.

Parameters

string $s

Well-formed UTF-8.

string $to

The target charset.

Returns

string —

cfw_mb_iconv_label()

cfw_mb_iconv_label(mixed  $enc) : mixed

Spells a charset the way symfony/polyfill-iconv's alias table spells it.

THE CHARMAPS ARE PRESENT AND THE NAMES ARE NOT. Measured against the polyfill rather than against the real extension: SJIS, GBK, BIG5 and EUC-KR are all REFUSED outright, while Shift_JIS, CP936, CP950 and CP949 decode -- out of the same 55 from.*.php files. So the gap that looked like missing capability is six alias entries.

CP950 and CP949 are SUPERSETS of Big5 and EUC-KR, so those two decode every assigned byte correctly and additionally decode bytes the narrower charset leaves unassigned, where mbstring substitutes. That is a real difference and it is why they are named here rather than presented as exact. EUC-JP and ISO-2022-JP ship no charmap at all and stay refused.

Parameters

mixed $enc

The charset the caller named.

Returns

mixed —

The polyfill's spelling, or the input when it is not a string or needs no alias.

cfw_mb_decode_subst()

cfw_mb_decode_subst(string  $s, string  $from) : ?string

The same substitution in the DECODE direction: a source byte the charmap does not know becomes "?" instead of vanishing.

Walks the source the way the polyfill's own mapToUtf8 does -- a two-byte key first, then a one-byte key -- so it is right for SJIS and Big5 as well as for the single-byte charsets. The pair was used exactly when its answer is not the two singles concatenated; where those agree, either choice produces the same bytes.

Returns null when it does not apply, which leaves the polyfill's answer alone: an unknown charset (no charmap ships for EUC-JP) and a source with nothing unmappable both take that path, and the second is the common one.

Parameters

string $s

Source bytes in the named charset.

string $from

The charset the bytes are in.

Returns

?string —

cfw_mb_isubpart()

cfw_mb_isubpart(string  $haystack, int|false  $pos, bool  $before, string|null  $encoding) : string|false

Case-insensitive search on the ORIGINAL haystack.

The polyfill returns a slice of its own lowercased copy, so a haystack containing a character that lowercases to two comes back with different bytes than went in.

Parameters

string $haystack

The original text.

int|false $pos

Where the needle was found, or FALSE.

bool $before

Return the part before the match rather than from it.

string|null $encoding

The encoding the caller named.

Returns

string|false —