NAME

String::Escape - Registry of string functions, including backslash escapes

SYNOPSIS

use String::Escape qw( printable unprintable );

$output = printable($value);

$value = unprintable($input);

use String::Escape qw( escape );

$escape_name = $use_quotes ? 'qprintable' : 'printable';

@escaped = escape($escape_name, @values);

DESCRIPTION

This module provides a flexible calling interface to some frequently-performed string conversion functions, including applying and removing C/Unix-style backslash escapes. For example, to inspect the line feeds and high-bit characters in a file you could use String::Escape's printable function:

> perl -MString::Escape=printable -n -e 'print printable($_)."\n"' < ~/.cshrc
unset auto-logout\t\t# minimal shell setup\n

The escape() function provides for dynamic selection of operations by using a package hash variable to map escape specification strings to the functions which implement them. The lookup imposes a bit of a performance penalty, but allows for some useful late-binding behaviour. Compound specifications (ex. 'quoted uppercase') are expanded to a list of functions to be applied in order. (Other modules may also register their functions here for later general use.)

REFERENCE

Escaping And Unescaping Functions

Each of these functions takes a single simple scalar argument and returns its escaped (or unescaped) equivalent.

quote($value) : $escaped

Add double quote characters to each end of the string.

quote_non_words($value) : $escaped

As above, but only quotes empty, punctuated, and multiword values.

unquote($value) : $escaped

If the string both begins and ends with double quote characters, they are removed, otherwise the string is returned unchanged.

printable($value) : $escaped
unprintable($value) : $escaped

These functions convert return, newline, tab, backslash and unprintable characters to their backslash-escaped equivalents and back again.

qprintable($value) : $escaped
unqprintable($value) : $escaped

The qprintable function applies printable escaping and then wraps the results with quote_non_words, while unqprintable applies unquote and then unprintable. (Note that this is not MIME quoted-printable encoding.)

Escape By-Name

These functions provide for the registration of string-escape specification names and corresponding functions, and then allow the invocation of one or several of these functions on one or several source string values.

escape($escapes, $value) : $escaped_value
escape($escapes, @values) : @escaped_values

Returns an altered copy of the provided values by looking up the escapes string in a registry of string-modification functions.

If called in a scalar context, operates on the single value passed in; if called in a list contact, operates identically on each of the provided values.

Valid escape specifications are:

one of the keys defined in %Escapes

The coresponding specification will be looked up and used.

a sequence of names separated by whitespace,

Each name will be looked up, and each of the associated functions will be applied successively, from left to right.

a reference to a function

The provided function will be called on with each value in turn.

a reference to an array

Each item in the array will be expanded as provided above.

A fatal error will be generated if you pass an unsupported escape specification, or if the function is called with multiple values in a scalar context.

String::Escape::names() : @defined_escapes

Returns a list of defined escape specification strings.

String::Escape::add( $escape_name, \&escape_function );

Add a new escape specification and corresponding function.

%Escapes : $name, $operation, ...

By default, the %Escapes hash is initialized to contain the following mappings:

quote, unquote, or quote_non_words
printable, unprintable, qprintable, or unqprintable,

Run the above-described functions of the same names.

uppercase, lowercase, or initialcase

Alters the case of letters in the string to upper or lower case, or for initialcase, sets the first letter to upper case and all others to lower.

none

Return an unchanged copy of the original value.

EXAMPLES

print printable( "\tNow is the time\nfor all good folks\n" );

\tNow is the time\nfor all good folks\n

print escape('qprintable', "\tNow is the time\nfor all good folks\n" );

"\tNow is the time\nfor all good folks\n"

print escape('uppercase qprintable', "\tNow is the time\nfor all good folks\n" );

"\tNOW IS THE TIME\nFOR ALL GOOD FOLKS\n"

print join '--', escape('printable', "\tNow is the time\n", "for all good folks\n" );

\tNow is the time\n--for all good folks\n

PREREQUISITES AND INSTALLATION

This package should run on any standard Perl 5 installation.

You may retrieve this package from the below URL: http://www.evoscript.com/dist/String-Escape-1998.0919.tar.gz

To install this package, download and unpack the distribution archive, then:

  • perl Makefile.PL

  • make test

  • make install

  • perldoc String::Escape

STATUS AND SUPPORT

This release of String::Escape is intended for public review and feedback. It has been tested in several environments and no major problems have been discovered, but it should be considered "alpha" pending that feedback.

Name            DSLI  Description
--------------  ----  ---------------------------------------------
String::
::Escape        adpf  Escape by-name registry and useful functions

Further information and support for this module is available at <www.evoscript.com>.

Please report bugs or other problems to <bugs@evoscript.com>.

AUTHORS AND COPYRIGHT

Copyright 1997, 1998 Evolution Online Systems, Inc. <www.evolution.com>

You may use this software for free under the terms of the Artistic License.

Contributors: M. Simon Cavalletto <simonm@evolution.com>, Jeremy G. Bishop <jeremy@evolution.com>