WvStreams
wvtclstring.h
Go to the documentation of this file.
1 /* -*- Mode: C++ -*-
2  * Worldvisions Weaver Software:
3  * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4  *
5  * FIXME:
6  * It would be possible to represent arbitrary binary blobs using this
7  * technique, but we'd have to avoid using null-terminated strings in a few
8  * places, particularly in the input to wvtcl_escape().
9  *
10  * We could even make encoded binary blobs printable (although that's not
11  * _strictly_ necessary in all cases) by encoding non-printable characters
12  * using \x## notation, if wvtcl_escape() or wvtcl_unescape() supported it.
13  */
34 #ifndef __WVTCLSTRING_H
35 #define __WVTCLSTRING_H
36 
37 #include "wvbuf.h"
38 class WvStringMask;
39 
40 // the default set of "nasties", ie. characters that need to be escaped if
41 // they occur somewhere in a string.
42 #define WVTCL_NASTY_SPACES_STR " \t\n\r"
43 extern const WvStringMask WVTCL_NASTY_SPACES;
44 
45 // Another default set of nasties, but only splitting on newlines
46 #define WVTCL_NASTY_NEWLINES_STR "\n\r"
47 extern const WvStringMask WVTCL_NASTY_NEWLINES;
48 
49 // {, }, \, and " are always considered "nasty."
50 #define WVTCL_ALWAYS_NASTY_CASE '{': case '}': case '\\': case '"'
51 
52 
53 // the default set of split characters, ie. characters that separate elements
54 // in a list. If these characters appear unescaped and not between {} or ""
55 // in a list, they signify the end of the current element.
56 #define WVTCL_SPLITCHARS_STR " \t\n\r"
57 extern const WvStringMask WVTCL_SPLITCHARS;
58 
59 
69 WvString wvtcl_escape(WvStringParm s,
70  const WvStringMask &nasties = WVTCL_NASTY_SPACES);
71 
72 
79 WvString wvtcl_unescape(WvStringParm s);
80 
81 
88  const WvStringMask &nasties = WVTCL_NASTY_SPACES,
89  const WvStringMask &splitchars = WVTCL_SPLITCHARS);
90 
97  const WvStringMask &splitchars = WVTCL_SPLITCHARS,
98  bool do_unescape = true);
99 
116 void wvtcl_decode(WvList<WvString> &l, WvStringParm _s,
117  const WvStringMask &splitchars = WVTCL_SPLITCHARS,
118  bool do_unescape = true);
119 
120 #endif // __WVTCLSTRING_H
WvStringMask
A class used to provide a masked lookup for characters in a string.
Definition: wvstringmask.h:18
wvtcl_getword
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.
Definition: wvtclstring.cc:359
wvtcl_unescape
WvString wvtcl_unescape(WvStringParm s)
tcl-unescape a string.
Definition: wvtclstring.cc:204
WvString
WvString is an implementation of a simple and efficient printable-string class.
Definition: wvstring.h:329
wvtcl_escape
WvString wvtcl_escape(WvStringParm s, const WvStringMask &nasties=WVTCL_NASTY_SPACES)
tcl-escape a string.
Definition: wvtclstring.cc:128
wvtcl_encode
WvString wvtcl_encode(WvList< WvString > &l, const WvStringMask &nasties=WVTCL_NASTY_SPACES, const WvStringMask &splitchars=WVTCL_SPLITCHARS)
encode a tcl-style list.
Definition: wvtclstring.cc:221
WvBufBase< unsigned char >
Specialization of WvBufBase for unsigned char type buffers intended for use with raw memory buffers.
Definition: wvbuf.h:22
wvtcl_decode
void wvtcl_decode(WvList< WvString > &l, WvStringParm _s, const WvStringMask &splitchars=WVTCL_SPLITCHARS, bool do_unescape=true)
split a tcl-style list.
Definition: wvtclstring.cc:386
WvList
A linked list container class.
Definition: wvlinklist.h:197