WvStreams
wvstringlistex.cc
00001 #include "wvstringlist.h"
00002 #include "wvhashtable.h"
00003 #include <stdio.h>
00004 
00005 int main()
00006 {
00007   WvStringList l;
00008   // WvStringList is essentially a WvHashTable
00009 
00010   WvString s("one"), s2("two"), s3("three"), foo("a : b : c : d");
00011 
00012 
00013   l.append(&s, false);
00014   l.append(&s2, false);
00015   l.append(&s3, false);
00016 
00017   WvStringList::Iter i(l);
00018   // iterator i can go through the list
00019 
00020   for (i.rewind(); i.next();)
00021     printf("The list: %s\n", i().cstr());
00022 
00023   l.zap();
00024   // clean the list
00025 
00026   l.split(foo, ": ");
00027   // split the variable foo with the delimiter ": " and append to the list
00028 
00029   for (i.rewind(); i.next();)
00030      printf("Split foo: %s\n", i().cstr());
00031   //prints:
00032   //Split foo: a
00033   //Split foo: b
00034   //Split foo: c
00035   //Split foo: d
00036 
00037   l.zap();
00038   l.split(foo, ": ", 2);
00039   // split the variable foo with the delimiter ": " and limit = 2
00040   // and append to the list
00041 
00042   for (i.rewind(); i.next();)
00043      printf("Split foo (2): %s\n", i().cstr());
00044   //prints:
00045   //Split foo (2): a
00046   //Split foo (2): b : c : d
00047 
00048 
00049   l.zap();
00050   l.split(foo, ": ", 3);
00051   // split the variable foo with the delimiter ": " and limit = 3
00052   // and append to the list
00053 
00054   for (i.rewind(); i.next();)
00055      printf("Split foo (3): %s\n", i().cstr());
00056   //prints:
00057   //Split foo (3): a
00058   //Split foo (3): b
00059   //Split foo (3): c : d
00060 
00061 
00062   /**************************************************
00063   Up until here, all is the same as WvStringTable
00064    Now we'll use popstr() and fill()
00065   ***************************************************/
00066 
00067   printf("Popping: %s\n", l.popstr().cstr());
00068   //prints:
00069   //Popping: a
00070 
00071   printf("Popping: %s\n", l.popstr().cstr());
00072   //prints:
00073   //Popping: b
00074 
00075   l.zap();
00076 
00077   char const *p = "hello";
00078   char const *p2 = "world";
00079   char const * const array[] = {p, p2, NULL};
00080   l.fill(array);
00081 
00082   printf("After fill: %s\n", l.join(",").cstr());
00083   //prints: After fill: hello
00084 
00085   l.zap();
00086 
00087   l.append(&s, false);
00088   l.append(&s2, false);
00089   l.append(&s3, false);
00090   l.fill(array);
00091 
00092 
00093   printf("After fill: %s\n", l.join(",").cstr());
00094   //prints: After fill: one,two,three,hello,world
00095 
00096 
00097   return 0;
00098 }