EPIC Enhanced Programmable IRC-II Client

stripcrap

Synopsis

$stripcrap(<mangle-types> <text>)

Technical

Processes <text> using the selected mangling rules. The first function word supplies <mangle-types>; the remaining argument is text, including literal quotation marks. Separate options with commas, for example ANSI,COLOR. Quote grouping of the first function word depends on the dword function parsing mode; comma-separated options avoid that dependency.

Options are case-insensitive and cumulative from left to right, starting with no flags. Prefix an individual option with - to turn it off. ALL, -ALL, and NONE replace the previous selection. Unknown options are silently ignored. The parser accepts some fixed prefixes; use the full names below to avoid ambiguous matches.

Options

Option Effect
ANSI, NORMALIZE Interpret recognized ANSI sequences and serialize supported attributes as IRC controls; normalize IRC colors and render ordinary control characters visibly.
COLOR Remove parsed IRC foreground/background colors, including extended ^X colors. Combine with ANSI to remove colors from recognized ANSI sequences.
BOLD Suppress bold (^B).
BLINK Suppress blink (^F).
REVERSE Suppress reverse (^V).
UNDERLINE Suppress underline (^_).
ALT_CHAR Suppress alternate-character formatting (^E).
ALL_OFF Ignore reset controls (^O), allowing previously active attributes to continue.
ND_SPACE Remove non-destructive space controls (^S), including those generated by recognized ANSI cursor-right sequences.
ESCAPE Replace each ESC byte with a reverse-formatted [, leaving its suffix as text. Takes priority over ANSI.
UNPRINTABLE Remove control bytes classified as unprintable, formatting introducers, and bells. Does not parse color parameters after removing their introducer.
OTHER Remove ordinary printable text, tabs, and non-destructive spaces.
ALL Enable normalization and all attribute-removal flags, including italic. Leave ESCAPE, OTHER, and UNPRINTABLE disabled.
NONE, -ALL Clear all flags.

-ANSI and -NORMALIZE both disable normalization. There is no ROM_CHAR option or individually selectable ITALIC option in the current parser. Italic is removed by ALL.

Practical

Use this function to select which display attributes to retain, such as removing colors before writing a log. stripc is equivalent to stripcrap(COLOR ...), and stripansicodes is equivalent to stripcrap(ANSI ...).

Returns

The processed string. Missing options or missing text returns the empty string. No settings are changed, and no server connection is required.

Even NONE is not a byte-preserving operation: the shared processor expands tabs at eight-column stops, drops Unicode C1 controls, renders carriage returns visibly in reverse, and may skip invalid UTF-8 bytes. IRC attributes are serialized from their effective state, so retained control bytes can be rewritten. Newlines remain even with ALL or UNPRINTABLE; OTHER removes them.

Restrictions

Normalization recognizes a limited set of ANSI sequences; unsupported or malformed sequences may leave suffix text. Supported ANSI display attributes become IRC formatting, rather than necessarily disappearing. Explicit cursor-right counts generate non-destructive spaces, capped at 256; other cursor operations do not reconstruct a terminal screen.

UNPRINTABLE takes priority over parsing IRC color sequences and attributes. For ESC bytes, the priority is ESCAPE, then ANSI, then UNPRINTABLE. Removing a control introducer alone can leave its parameters behind. ALL is therefore not a guarantee of plain text with every control character removed.

Examples

$stripcrap(ALL $*)             Normalize recognized ANSI sequences and suppress IRC attributes.
$stripcrap(ALL,-COLOR $*)      As above, but retain colors.
$stripcrap(COLOR $*)           Remove IRC colors; leave ANSI escape sequences unchanged.
$stripcrap(ANSI,COLOR $*)      Normalize recognized ANSI sequences and remove their colors too.
$stripcrap(NONE plain text)    Returns plain text.

Source

Handler: source/functions.c. Options: parse_mangle. Processing and escape parsing: source/screen.c, read_esc_seq. Flag and IRC control definitions: include/ircaux.h, include/irc.h.