00001
00002
00003
00004
00005
00006
00007
00008
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