Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

wvstringlist.cc

Go to the documentation of this file.
00001 /*
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
00004  *
00005  * Some helper functions for WvStringList.
00006  * 
00007  * This is blatantly block-copied from WvStringTable, but I don't care!  Hah!
00008  * (I just know I'm going to regret this someday...)
00009  */
00010 #include "wvstringlist.h"
00011 #include "strutils.h"
00012 
00013 
00014 WvString WvStringList::join(const char *joinchars) const
00015 {
00016     WvStringList::Iter s(*this);
00017     size_t totlen;
00018     WvString total;
00019     char *te;
00020     int x;
00021     
00022     totlen = 1;
00023     for (s.rewind(); s.next(); )
00024         totlen += strlen(s()) + strlen(joinchars);
00025     
00026     total.setsize(totlen);
00027     te = total.edit();
00028     
00029     te[0] = 0;
00030     x = 0;
00031     for (s.rewind(); s.next(); )
00032     {
00033         if (x++)
00034             strcat(te, joinchars);
00035         strcat(te, s());
00036     }
00037     
00038     if (te[0])
00039         trim_string(te);
00040     
00041     return total;
00042 }
00043 
00044 
00045 void WvStringList::split(const WvString &_s, const char *splitchars)
00046 {
00047     WvString s(_s);
00048     char *sptr = s.edit(), *eptr, oldc;
00049     
00050     while (sptr && *sptr)
00051     {
00052         sptr += strspn(sptr, splitchars);
00053         eptr = sptr + strcspn(sptr, splitchars);
00054         
00055         oldc = *eptr;
00056         *eptr = 0;
00057         
00058         WvString *newstr = new WvString(sptr);
00059         newstr->unique();
00060         append(newstr, true);
00061         
00062         *eptr = oldc;
00063         sptr = eptr;
00064     }
00065 }
00066 

Generated on Sun Mar 16 01:01:12 2003 for WvStreams by doxygen1.3-rc3