Skip to main content
Version: v0.0.14

Function: decodeEscapes()

decodeEscapes(leaf, d, onUnknown?, onUnpaired?): string

Decode the four recognized ASTM escape mnemonics in a single already-split leaf (a component string), substituting the active delimiters read from the header. Unrecognized &X& bodies are preserved verbatim and reported through onUnknown (never dropped, never guessed), and an escape character that heads no sequence at all is preserved as a literal and reported through onUnpaired.

This runs after splitting, so a decoded delimiter becomes ordinary literal text and can never introduce a new split boundary.

Parameters

leaf

string

One component string, escape-aware split already applied.

d

Delimiters

The delimiters resolved from the header.

onUnknown?

UnknownEscapeSink

Called once per unrecognized escape body encountered.

onUnpaired?

UnpairedEscapeSink

Called once per escape character that heads no sequence.

Returns

string

The decoded string.

Example

import { decodeEscapes, CANONICAL_DELIMITERS } from "@cosyte/astm";
decodeEscapes("1&S&40", CANONICAL_DELIMITERS); // "1^40"
decodeEscapes("O&Brien", CANONICAL_DELIMITERS); // "O&Brien" (literal, reported)