WvStreams
wvtclstring.h
Go to the documentation of this file.
00001 /* -*- Mode: C++ -*-
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
00004  * 
00005  * FIXME:
00006  *   It would be possible to represent arbitrary binary blobs using this
00007  *   technique, but we'd have to avoid using null-terminated strings in a few
00008  *   places, particularly in the input to wvtcl_escape().
00009  * 
00010  *   We could even make encoded binary blobs printable (although that's not
00011  *   _strictly_ necessary in all cases) by encoding non-printable characters
00012  *   using \x## notation, if wvtcl_escape() or wvtcl_unescape() supported it.
00013  */
00034 #ifndef __WVTCLSTRING_H
00035 #define __WVTCLSTRING_H
00036 
00037 #include "wvbuf.h"
00038 class WvStringMask;
00039 
00040 // the default set of "nasties", ie. characters that need to be escaped if
00041 // they occur somewhere in a string.
00042 #define WVTCL_NASTY_SPACES_STR    " \t\n\r"
00043 extern const WvStringMask WVTCL_NASTY_SPACES;
00044 
00045 // Another default set of nasties, but only splitting on newlines
00046 #define WVTCL_NASTY_NEWLINES_STR  "\n\r"
00047 extern const WvStringMask WVTCL_NASTY_NEWLINES;
00048 
00049 // {, }, \, and " are always considered "nasty."
00050 #define WVTCL_ALWAYS_NASTY_CASE '{': case '}': case '\\': case '"'
00051 
00052 
00053 // the default set of split characters, ie. characters that separate elements
00054 // in a list.  If these characters appear unescaped and not between {} or ""
00055 // in a list, they signify the end of the current element.
00056 #define WVTCL_SPLITCHARS_STR " \t\n\r"
00057 extern const WvStringMask WVTCL_SPLITCHARS;
00058 
00059 
00069 WvString wvtcl_escape(WvStringParm s,
00070                       const WvStringMask &nasties = WVTCL_NASTY_SPACES);
00071 
00072 
00079 WvString wvtcl_unescape(WvStringParm s);
00080 
00081 
00087 WvString wvtcl_encode(WvList<WvString> &l,
00088                       const WvStringMask &nasties = WVTCL_NASTY_SPACES,
00089                       const WvStringMask &splitchars = WVTCL_SPLITCHARS);
00090 
00096 WvString wvtcl_getword(WvBuf &buf,
00097                        const WvStringMask &splitchars = WVTCL_SPLITCHARS,
00098                        bool do_unescape = true);
00099 
00116 void wvtcl_decode(WvList<WvString> &l, WvStringParm _s,
00117                   const WvStringMask &splitchars = WVTCL_SPLITCHARS,
00118                   bool do_unescape = true);
00119 
00120 #endif // __WVTCLSTRING_H