Escape - Maple Help

StringTools

 Escape
 escape special characters in a string by using a specified escape schema

 Calling Sequence Escape( s, form )

Parameters

 s - string; Maple string form - (optional) symbol or string; keyword describing how to escape characters in the input s

Description

 • The Escape(s, form) command escapes special characters in the input string s, according to rules specified by the optional second argument form.
 • The form argument defaults to xml, which specifies that rules appropriate for including the text of the string s in an XML document are to be used.
 • Alternatively, the form argument can be the symbol html. Escaping rules suitable for HTML text are then used.
 • If the form argument is regexp, then the input is taken to be a regular expression, and is escaped in such a way that RegMatch( Escape( rx, 'regexp' ), rx ) returns true, for any regular expression rx.
 • All of the StringTools package commands treat strings as (null-terminated) sequences of $8$-bit (ASCII) characters.  Thus, there is no support for multibyte character encodings, such as unicode encodings.

Examples

 > $\mathrm{with}\left(\mathrm{StringTools}\right):$
 > $r≔\mathrm{Escape}\left("Some text with \text{'}embedded\text{'} HTML."\right):$$\mathrm{lprint}\left(r\right)$
 "Some text with <b>'embedded' HTML</b>."
 > $r≔\mathrm{Escape}\left("Some text with \text{'}embedded\text{'} HTML.",'\mathrm{xml}'\right):$$\mathrm{lprint}\left(r\right)$
 "Some text with <b>'embedded' HTML</b>."
 > $r≔\mathrm{Escape}\left("Some text with \text{'}embedded\text{'} HTML.",'\mathrm{html}'\right):$$\mathrm{lprint}\left(r\right)$
 "Some text with <b>'embedded' HTML</b>."
 > $\mathrm{rx}≔"0x\left(\left[0-9a-f\right]+|\left[0-9A-F\right]+\right)":$
 > $r≔\mathrm{Escape}\left(\mathrm{rx},'\mathrm{regexp}'\right):$$\mathrm{lprint}\left(r\right)$
 "0x\$$\$0-9a-f\$\\+\\|\$0-9A-F\$\\+\$$\\\$"
 > $\mathrm{RegMatch}\left(r,\mathrm{rx}\right)$
 ${\mathrm{true}}$ (1)