wvtclstring.h File Reference


Detailed Description

Functions to handle "tcl-style" strings and lists.

Using wvtcl_encode(), you can encode _any_ list of strings into a single string, then reliably split the single string back into the list using wvtcl_decode().

You can create recursive lists of lists by simply running wvtcl_encode() on a list of strings returned from wvtcl_encode().

Example list encodings (all of the following lists have exactly 3 elements): foo blah weasels e1 elem2 {element 3} x1 {} "element 3" w x y\ z

Example list of lists: foo\ blah\ weasels {e1 elem2 {element 3}} {w x y\ z}

Definition in file wvtclstring.h.

#include "wvbuf.h"

Include dependency graph for wvtclstring.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define WVTCL_NASTY_SPACES_STR   " \t\n\r"
#define WVTCL_NASTY_NEWLINES_STR   "\n\r"
#define WVTCL_ALWAYS_NASTY_CASE   '{': case '}': case '\\': case '"'
#define WVTCL_SPLITCHARS_STR   " \t\n\r"

Functions

WvString wvtcl_escape (WvStringParm s, const WvStringMask &nasties=WVTCL_NASTY_SPACES)
 tcl-escape a string.
WvString wvtcl_unescape (WvStringParm s)
 tcl-unescape a string.
WvString wvtcl_encode (WvList< WvString > &l, const WvStringMask &nasties=WVTCL_NASTY_SPACES, const WvStringMask &splitchars=WVTCL_SPLITCHARS)
 encode a tcl-style list.
WvString wvtcl_getword (WvBuf &buf, const WvStringMask &splitchars=WVTCL_SPLITCHARS, bool do_unescape=true)
 Get a single tcl word from an input buffer, and return the rest of the buffer untouched.
void wvtcl_decode (WvList< WvString > &l, WvStringParm _s, const WvStringMask &splitchars=WVTCL_SPLITCHARS, bool do_unescape=true)
 split a tcl-style list.

Variables

const WvStringMask WVTCL_NASTY_SPACES
const WvStringMask WVTCL_NASTY_NEWLINES
const WvStringMask WVTCL_SPLITCHARS


Function Documentation

WvString wvtcl_escape ( WvStringParm  s,
const WvStringMask nasties = WVTCL_NASTY_SPACES 
)

tcl-escape a string.

There are three ways to do this: 1) Strings that need no escaping are unchanged. 2) Strings containing characters in 'nasties' are usually encoded just by enclosing the unmodified string in braces. (For example, "foo blah" becomes "{foo blah}") 3) Strings containing nasties _and_ unmatched braces are encoded using backslash notation. (For example, " foo} " becomes "\ foo\}\ "

Definition at line 127 of file wvtclstring.cc.

References WvString::edit(), WvFastString::len(), WvFastString::setsize(), and wvtcl_escape().

Referenced by UniClientGen::get(), UniClientGen::haschildren(), UniClientGen::set(), UniClientGen::setv(), UniClientConn::writeonevalue(), UniClientConn::writetext(), UniClientConn::writevalue(), wvtcl_encode(), and wvtcl_escape().

WvString wvtcl_unescape ( WvStringParm  s  ) 

tcl-unescape a string.

This is generally the reverse of wvtcl_escape, except we can reverse any backslashified or embraced string, even if it doesn't follow the "simplest encoding" rules used by wvtcl_escape. We can also handle strings in double-quotes, ie. '"foo"' becomes 'foo'.

Definition at line 203 of file wvtclstring.cc.

References WvString::edit(), WvFastString::len(), WvFastString::setsize(), and wvtcl_unescape().

Referenced by UniIniGen::refresh(), and wvtcl_unescape().

WvString wvtcl_encode ( WvList< WvString > &  l,
const WvStringMask nasties = WVTCL_NASTY_SPACES,
const WvStringMask splitchars = WVTCL_SPLITCHARS 
)

encode a tcl-style list.

This is easily done by tcl-escaping each string in 'l', then appending the escaped strings together, separated by the first char in splitchars.

Definition at line 220 of file wvtclstring.cc.

References WvString::edit(), WvStringMask::first(), WvFastString::setsize(), wvtcl_encode(), and wvtcl_escape().

Referenced by wvtcl_encode().

WvString wvtcl_getword ( WvBuf buf,
const WvStringMask splitchars = WVTCL_SPLITCHARS,
bool  do_unescape = true 
)

Get a single tcl word from an input buffer, and return the rest of the buffer untouched.

If no word can be created from the buffer, return a null string and leave the buffer unmodified.

Definition at line 358 of file wvtclstring.cc.

References WvString::edit(), WvBufBaseCommonImpl< T >::get(), WvFastString::setsize(), WvBufBaseCommonImpl< T >::unget(), WvBufBaseCommonImpl< T >::used(), and wvtcl_getword().

Referenced by UniClientConn::readarg(), UniIniGen::refresh(), wvtcl_decode(), and wvtcl_getword().

void wvtcl_decode ( WvList< WvString > &  l,
WvStringParm  _s,
const WvStringMask splitchars = WVTCL_SPLITCHARS,
bool  do_unescape = true 
)

split a tcl-style list.

There are some special "convenience" features here, which allow users to create lists more flexibly than wvtcl_encode would do.

Elements of the list are separated by any number of any characters from the 'splitchars' list.

Quotes are allowed around elements: '"foo"' becomes 'foo'. These work mostly like braces, except the string is assumed to be backslashified. That is, '"\ "' becomes ' ', whereas '{\ }' becomes '\ ' (ie. the backslash wouldn't be removed).

Zero-length elements must be represented by {}

Definition at line 385 of file wvtclstring.cc.

References WvList< T >::append(), WvString::edit(), WvFastString::len(), WvFastString::setsize(), wvtcl_decode(), and wvtcl_getword().

Referenced by wvtcl_decode().


Generated on Sat Feb 7 13:37:18 2009 for WvStreams by  doxygen 1.5.6