WvStreams
wvstringlistex.cc
1#include "wvstringlist.h"
2#include "wvhashtable.h"
3#include <stdio.h>
4
5int main()
6{
8 // WvStringList is essentially a WvHashTable
9
10 WvString s("one"), s2("two"), s3("three"), foo("a : b : c : d");
11
12
13 l.append(&s, false);
14 l.append(&s2, false);
15 l.append(&s3, false);
16
17 WvStringList::Iter i(l);
18 // iterator i can go through the list
19
20 for (i.rewind(); i.next();)
21 printf("The list: %s\n", i().cstr());
22
23 l.zap();
24 // clean the list
25
26 l.split(foo, ": ");
27 // split the variable foo with the delimiter ": " and append to the list
28
29 for (i.rewind(); i.next();)
30 printf("Split foo: %s\n", i().cstr());
31 //prints:
32 //Split foo: a
33 //Split foo: b
34 //Split foo: c
35 //Split foo: d
36
37 l.zap();
38 l.split(foo, ": ", 2);
39 // split the variable foo with the delimiter ": " and limit = 2
40 // and append to the list
41
42 for (i.rewind(); i.next();)
43 printf("Split foo (2): %s\n", i().cstr());
44 //prints:
45 //Split foo (2): a
46 //Split foo (2): b : c : d
47
48
49 l.zap();
50 l.split(foo, ": ", 3);
51 // split the variable foo with the delimiter ": " and limit = 3
52 // and append to the list
53
54 for (i.rewind(); i.next();)
55 printf("Split foo (3): %s\n", i().cstr());
56 //prints:
57 //Split foo (3): a
58 //Split foo (3): b
59 //Split foo (3): c : d
60
61
62 /**************************************************
63 Up until here, all is the same as WvStringTable
64 Now we'll use popstr() and fill()
65 ***************************************************/
66
67 printf("Popping: %s\n", l.popstr().cstr());
68 //prints:
69 //Popping: a
70
71 printf("Popping: %s\n", l.popstr().cstr());
72 //prints:
73 //Popping: b
74
75 l.zap();
76
77 char const *p = "hello";
78 char const *p2 = "world";
79 char const * const array[] = {p, p2, NULL};
80 l.fill(array);
81
82 printf("After fill: %s\n", l.join(",").cstr());
83 //prints: After fill: hello
84
85 l.zap();
86
87 l.append(&s, false);
88 l.append(&s2, false);
89 l.append(&s3, false);
90 l.fill(array);
91
92
93 printf("After fill: %s\n", l.join(",").cstr());
94 //prints: After fill: one,two,three,hello,world
95
96
97 return 0;
98}
const char * cstr() const
return a (const char *) for this string.
Definition wvstring.h:267
This is a WvList of WvStrings, and is a really handy way to parse strings.
WvString join(const char *joinchars=" ") const
concatenates all elements of the list seperating on joinchars
void split(WvStringParm s, const char *splitchars=" \t\r\n", int limit=0)
split s and form a list ignoring splitchars (except at beginning and end) ie.
WvString popstr()
get the first string in the list, or an empty string if the list is empty.
WvString is an implementation of a simple and efficient printable-string class.
Definition wvstring.h:330