4.10 Wrap and UnWrap

Wrap

The wrap function wraps a string in quotes or other enclosing characters. By default the enclosing characters are double quotes (" ").

Syntax:

wrap(str[, pair])

where:

str
The string.
pair
A single character or a pair of characters used to enclose the string.


Returns:

The enclosed string.

Remarks:

If only one enclosing character is supplied this is used for both ends of the string.

If two characters are supplied, they are wrapped around the string.

Example:

put wrap("abc")        // "abc"
put wrap("abc", "()")  // (abc)
put wrap("abc", '~|')  // ~abc|
put wrap("abc", '~')   // ~abc~

Implementation Status

LynPlex Interpreter
Fully implemented
LynPlexC Compiler
Not yet implemented
LynPlexS Compiler
Not yet implemented

Notes:

UnWrap

The unwrap extracts a substring from a string where the substring is enclosed by a pair of characters. By default the enclosing characters are double quotes (" ").

Syntax:

unwrap(str[, pairs[, ignore-pairs]])

where:

str
The string.
pairs
One or more pairs of characters used to delimit the substring.
ignore-pairs
One or more pairs of characters that will be ignored during the extraction process.


Returns:

The extracted string.

Remarks:

By default it checks the first non-blank character. If it is one of the characters in the table, the following characters are extracted up to the corresponding closing character.

If the first non-blank character is not one of the special characters, a search is made for a quote (") and the quoted string starting at that point is extracted.

Characters outside the wrap characters are ignored. Only the characters within the wrapped string are returned.

Anything enclosed within the 'ignore' characters is not used to check for the end of the string. This means that one or more terminating characters can be included in the resulting string provided that they are within the ignored part of the string.

Alternatively other enclosing and ignore pairs can be specified.

Default pairs and ignore pairs
First non white-space character Check Ignore
" "" ' '
' ' ' ""
( () "" ' '
[ [] "" ' '
{ {} "" ' '
< <> "" ' '
Otherwise:
" "" ' '

Example:

Example:

put unwrap('abc (abc)', "()")            // abc
put unwrap('abc (a(bc))', "()")          // a(bc)
put unwrap("abc (a='(bc)')", "()", "''") // a='(bc)'
put unwrap("a='(bc)'", "()", "''")       // empty string 

Implementation Status

LynPlex Interpreter
Fully implemented
LynPlexC Compiler
Not yet implemented
LynPlexS Compiler
Not yet implemented
The external function XstParse can be used to extract a delimited string.

Notes:


lynplex/lp0410.txt · Last modified: 2014/05/28 07:35 (external edit)