2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
5 #include "wvtclstring.h"
6 #include "wvstringlist.h"
7 #include "wvstringmask.h"
9 int main(int argc
, char **argv
)
11 WvStringMask
nasties(WVTCL_NASTY_SPACES
);
12 WvStringMask
splitchars(WVTCL_SPLITCHARS
);
16 // correct output (all on one line):
17 // 'chicken hammer {} {banana split} {shameless{frog}parts}
18 // big\}monkey\ \{potatoes {hammer\}time} {"quotable quote"}'
19 static const char *strarray
[] = {
25 "shameless{frog}parts",
26 "big}monkey {potatoes",
34 WvString
ls(wvtcl_encode(l
, nasties
, splitchars
));
35 printf(" List: '%s'\n", ls
.cstr());
36 printf("Unescaped: '%s'\n", wvtcl_unescape(ls
).cstr());
38 // wvtcl_encode (like the real tcl list encoder) will never put things
39 // in quotes by itself. However, the list decoder needs to be able to
40 // handle them, in case the user provides them by hand. So we'll just
41 // tack some quoted strings onto the end.
43 // We also take this opportunity to test handling of whitespace.
45 ls
.append(" \n \t \"unquotable quote\"\r\n");
46 ls
.append(" \"{embraced\\nunquotable}\" \"quote\"whacker");
48 // add the expected new strings to the end of the main list, for comparison
50 l
.append(new WvString("unquotable quote"), true);
51 l
.append(new WvString("{embraced\nunquotable}"), true);
52 l
.append(new WvString("quote"), true);
53 l
.append(new WvString("whacker"), true);
55 printf("\nList split results:\n");
57 wvtcl_decode(l2
, ls
, splitchars
);
59 WvStringList::Iter
i(l
), i2(l2
);
60 for (i
.rewind(), i2
.rewind(); i
.next(), i2
.next(), true; )
62 if (!i
.cur() && !i2
.cur())
67 printf("Extra element in list 2: '%s'\n", i2
->cstr());
74 printf("Extra element in list 1: '%s'\n", i
->cstr());
79 printf(" '%s'\n", i2
->cstr());
83 printf(" --> should be '%s'\n", i
->cstr());
89 printf("Lists don't match!\n");
91 printf("Lists match.\n");