10 #define __WVSTRUTILS_H
12 #include <sys/types.h>
16 #include "wvstringlist.h"
79 void replace_char(
void *
string,
char c1,
char c2,
int length);
91 char *
strlwr(
char *
string);
97 char *
strupr(
char *
string);
102 bool is_word(
const char *
string);
223 ROUND_DOWN_AT_POINT_FIVE,
224 ROUND_UP_AT_POINT_FIVE,
233 WvString sizetoa(
unsigned long long blocks,
unsigned long blocksize = 1,
234 RoundingMethod rounding_method = ROUND_UP_AT_POINT_FIVE);
241 RoundingMethod rounding_method = ROUND_UP_AT_POINT_FIVE);
249 RoundingMethod rounding_method = ROUND_UP_AT_POINT_FIVE);
256 RoundingMethod rounding_method = ROUND_UP_AT_POINT_FIVE);
267 int lookup(
const char *str,
const char *
const *table,
268 bool case_sensitive =
false);
277 template<
class StringCollection>
279 const char *splitchars =
" \t",
int limit = 0)
282 char *sptr = s.
edit(), *eptr, oldc;
288 coll.add(emptyString,
true);
292 bool firstrun =
true;
294 while (sptr && *sptr)
304 sptr += strspn(sptr, splitchars);
309 eptr = sptr + strcspn(sptr, splitchars);
313 eptr = sptr + strlen(sptr);
320 coll.add(newstr,
true);
341 template<
class StringCollection>
343 const char *splitchars =
" \t",
int limit = 0)
346 char *cur = s.
edit();
359 int len = strcspn(cur, splitchars);
366 if (!cur[len])
break;
372 #ifndef _WIN32 // don't have regex on win32
380 template<
class StringCollection>
382 const WvRegex ®ex,
int limit = 0)
385 int match_start, match_end;
388 while ((limit == 0 || count < limit)
393 int len = match_start;
394 substr->setsize(len+1);
395 memcpy(substr->
edit(), &s[start], len);
396 substr->
edit()[len] =
'\0';
397 coll.add(substr,
true);
402 if (limit == 0 || count < limit)
406 coll.add(last,
true);
417 template<
class StringCollection>
419 const char *joinchars =
" \t")
421 size_t joinlen = strlen(joinchars);
423 typename StringCollection::Iter s(
424 const_cast<StringCollection&>(coll));
425 for (s.rewind(); s.next(); )
428 totlen += strlen(s->cstr());
434 total.setsize(totlen);
436 char *te = total.
edit();
439 for (s.rewind(); s.next(); )
444 strcat(te, joinchars);
446 strcat(te, s->cstr());
508 for (
const char *p = str; *p; ++p)
512 n = n * T(10) + T(*p -
'0');
514 else if ((
const char *)str == p
591 static inline bool is_int(
const char *str)
603 if (!isdigit(*str++))
613 #endif // __WVSTRUTILS_H