Escapes
in package
Shared escape decoding/encoding for DXN's `string`/`char`/quoted -`keyword` bodies (`dxn/DXN.md` ยง1.1's `escape` production) -- one implementation so no caller duplicates it.
Decode accepts more named shortcuts (\0 \a \b \f \v, alongside
\" \\ \n \t \r and \x{...}) than encode ever produces -- encode
only ever emits \" \\ \n \t \r as named escapes, falling back to
\x{...} for every other C0 control character, mirroring the JS
port's own asymmetric choice: a decoder must accept every input
form; a printer need not exercise all of them to stay round-trip
-safe.
Table of Contents
Constants
- DECODE_SIMPLE : mixed = ['"' => '"', '\\' => '\\', 'n' => "\n", 't' =>...
- ENCODE_NAMED : mixed = ['"' => '"', '\\' => '\\', "\n" => 'n', "\t" =>...
Methods
- decodeEscape() : array{0: string, 1: int}
- Decodes exactly one escape sequence starting right after the leading backslash (`$body[$start]` is the escape's first byte, not the backslash itself).
- decodeString() : string
- Decodes a full string/keyword body -- the text between the opening and closing `"`, quotes already stripped.
- encodeChar() : string
- encodeString() : string
- Encodes a string body for `.dxn` text output -- the reverse of {@see self::decodeString()}. Escapes only what round-tripping requires (`"`, `\`, and the C0 control-character range), leaving every other codepoint, including non-ASCII text, untouched.
- __construct() : mixed
Constants
DECODE_SIMPLE
private
mixed
DECODE_SIMPLE
= ['"' => '"', '\\' => '\\', 'n' => "\n", 't' => "\t", 'r' => "\r", '0' => "\x00", 'a' => "\x07", 'b' => "\x08", 'f' => "\f", 'v' => "\v"]
ENCODE_NAMED
private
mixed
ENCODE_NAMED
= ['"' => '"', '\\' => '\\', "\n" => 'n', "\t" => 't', "\r" => 'r']
Methods
decodeEscape()
Decodes exactly one escape sequence starting right after the leading backslash (`$body[$start]` is the escape's first byte, not the backslash itself).
public
static decodeEscape(string $body, int $start) : array{0: string, 1: int}
Parameters
- $body : string
- $start : int
Return values
array{0: string, 1: int} —the decoded text and the byte offset right after the consumed escape.
decodeString()
Decodes a full string/keyword body -- the text between the opening and closing `"`, quotes already stripped.
public
static decodeString(string $body) : string
Parameters
- $body : string
Tags
Return values
stringencodeChar()
public
static encodeChar(int $codepoint) : string
Parameters
- $codepoint : int
Return values
stringencodeString()
Encodes a string body for `.dxn` text output -- the reverse of {@see self::decodeString()}. Escapes only what round-tripping requires (`"`, `\`, and the C0 control-character range), leaving every other codepoint, including non-ASCII text, untouched.
public
static encodeString(string $s) : string
Parameters
- $s : string
Return values
string__construct()
private
__construct() : mixed