/** Returns the encoding of $codePoint as a byte string
*
* If $codePoint is less than 0 or greater than 1114111, an exception is thrown
*
* If $fatal is true, an exception will be thrown if the code point cannot be encoded into a character; otherwise HTML character references will be substituted
* @param int $codePoint The Unicode code point to encode. If less than 0 or greater than 1114111, an exception is thrown
* @param bool $fatal Whether an exception will be thrown if the code point cannot be encoded into a character; if false HTML character references will be substituted
*/
public static function encode(int $codePoint, bool $fatal = true): string;
/** Constructs a new encoder for the specified $label
*
* @param string $label One of the encoding labels listed in the specification e.g. "utf-8", "Latin1", "shift_JIS"
* @param bool $fatal If true (the default) exceptions will be thrown when a character cannot be represented in the target encoding; if false HTML character references will be substituted instead
public function __construct(string $label, bool $fatal = true) {
$l = Matcher::matchLabel($label);
if (!$l || !$l['encoder']) {
@ -27,6 +34,10 @@ class Encoder {
}
}
/** Encodes a series of code point numbers into a string
*
* @param iterable $codePoints An iterable set of integers representing code points in the Unicode range
*/
public function encode(iterable $codePoints): string {
$out = "";
switch ($this->name) {
@ -220,6 +231,12 @@ class Encoder {
return $out;
}
/** Encodes a single character into a string
*
* When using this method to encode a string, the finalize() method should be called to terminate the string
*
* @param int $codePoint An integer representing the Unicode code point number to encode
*/
public function encodeChar(int $codePoint): string {
switch ($this->name) {
case "UTF-8":
@ -299,6 +316,10 @@ class Encoder {
}
} // @codeCoverageIgnore
/** Finalizes a string, returning any terminal bytes to append to the output
*
* For the ISO-2022-JP encoding, this method must be called fater the last character is encoded to correctly encode a string; for other encodings this is a no-op
/** @var array $modeStack The stack of previous decoding modes and their effective byte positions; the current mode is kept off the stack */
protected $modeStack = [];
/** @var int $mode The current decoding mode, a subset of the possible states defined in the specification */
protected $mode = self::ASCII_STATE;
/** @var int $modeMark The byte position marking theposition where the current mode first applied; it is the position of the first byte AFTER the escape sequence */
protected $modeMark = \PHP_INT_MIN;
protected $modeStack = [];
protected $dirtyEOF = 0;
/** @var bool $trailingEscape Whether the string ends in a valid escape sequence */
protected $trailingEscape = false;
/** @var array $pointerCache A cached result of flipping the pointer-to-code-point table */
protected static $pointerCache;
public function __construct(string $string, bool $fatal = false, bool $allowSurrogates = false) {
/** Returns the encoding of $codePoint as a byte string
*
* If $codePoint is less than 0 or greater than 1114111, an exception is thrown; if $codePoint is null this signals end-of-file
*
* If $fatal is true, an exception will be thrown if the code point cannot be encoded into a character; otherwise HTML character references will be substituted
* @param int $codePoint The Unicode code point to encode. If less than 0 or greater than 1114111, an exception is thrown; if $codePoint is null this signals end-of-file
* @param bool $fatal Whether an exception will be thrown if the code point cannot be encoded into a character; if false HTML character references will be substituted
* @param mixed &$mode A reference keeping track of the current encoder mode. An uninitialized variable should be passed on first invocation, and that variable used for further invocations.
*/
public static function encode(?int $codePoint, bool $fatal = true, &$mode = self::MODE_ASCII): string;
public static function encode(?int $codePoint, bool $fatal = true, &$mode = null): string;