16#include "wvstringlist.h"
79void replace_char(
void *
string,
char c1,
char c2,
int length);
102bool is_word(
const char *
string);
223 ROUND_DOWN_AT_POINT_FIVE,
224 ROUND_UP_AT_POINT_FIVE,
233WvString 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);
267int lookup(
const char *str,
const char *
const *table,
268 bool case_sensitive =
false);
277template<
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);
341template<
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;
380template<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;
402 if (limit == 0 || count < limit)
406 coll.add(last,
true);
417template<
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
591static inline bool is_int(
const char *str)
603 if (!isdigit(*str++))
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
WvRegex – Unified support for regular expressions.
bool continuable_match(WvStringParm string, int &match_start, int &match_end, WVREGEX_REGS_DECL) const
Match a given string against the compiled regular expression, capturing the start and end positions o...
WvString is an implementation of a simple and efficient printable-string class.
WvString & unique()
make the buf and str pointers owned only by this WvString.
char * edit()
make the string editable, and return a non-const (char*)
Hex functions for compatibility with older code.
bool cstr_unescape(WvStringParm cstr, void *data, size_t max_size, size_t &size, const CStrExtraEscape extra_escapes[]=NULL)
Converts a C-style string constant into data.
bool isnewline(char c)
Returns true if 'c' is a newline or carriage return character.
WvString beforestr(WvStringParm line, WvStringParm a)
Returns everything in line (exclusively) before 'a'.
char * terminate_string(char *string, char c)
Add character c to the end of a string after removing terminating carriage returns/linefeeds if any.
WvString fqdomainname()
Get the fqdn of the local host, using gethostbyname() and gethostname()
WvString encode_hostname_as_DN(WvStringParm hostname)
Example: encode_hostname_as_DN("www.fizzle.com") will result in dc=www,dc=fizzle,dc=com,...
WvString strreplace(WvStringParm s, WvStringParm a, WvStringParm b)
Replace any instances of "a" with "b" in "s".
WvString backslash_escape(WvStringParm s1)
Returns a string with a backslash in front of every non alphanumeric character in s1.
WvString url_encode(WvStringParm str, WvStringParm unsafe="")
Converts all those pesky spaces, colons, and other nasties into nice unreadable Quasi-Unicode codes.
WvString getfilename(WvStringParm fullname)
Take a full path/file name and splits it up into respective pathname and filename.
WvString rfc822_date(time_t _when=-1)
Returns an RFC822-compatible date made out of _when, or, if _when < 0, out of the current time.
WvString hexdump_buffer(const void *buf, size_t len, bool charRep=true)
Produce a hexadecimal dump of the data buffer in 'buf' of length 'len'.
WvString passwd_md5(const char *str)
Similar to crypt(), but this randomly selects its own salt.
WvString ptr2str(void *ptr)
Converts a pointer into a string, like glibc's p formatter would do.
WvString sizetoa(unsigned long long blocks, unsigned long blocksize=1, RoundingMethod rounding_method=ROUND_UP_AT_POINT_FIVE)
Given a number of blocks and a blocksize (default==1 byte), return a WvString containing a human-read...
int lookup(const char *str, const char *const *table, bool case_sensitive=false)
Finds a string in an array and returns its index.
WvString local_date(time_t _when=-1)
Return the local date (TZ applied) out of _when.
WvString strcoll_join(const StringCollection &coll, const char *joinchars=" \t")
Concatenates all strings in a collection and returns the result.
WvString nice_hostname(WvStringParm name)
Given a hostname, turn it into a "nice" one.
bool is_word(const char *string)
Returns true if all characters in 'string' are isalnum() (alphanumeric).
int strcount(WvStringParm s, const char c)
How many times does 'c' occur in "s"?
WvString sizeitoa(unsigned long long blocks, unsigned long blocksize=1, RoundingMethod rounding_method=ROUND_UP_AT_POINT_FIVE)
Given a number of blocks and a blocksize (default==1 byte), return a WvString containing a human-read...
WvString intl_date(time_t _when=-1)
Return the local date (in format of ISO 8601) out of _when.
WvString rfc1123_date(time_t _when)
Returns an RFC1123-compatible date made out of _when.
WvString sizektoa(unsigned long long kbytes, RoundingMethod rounding_method=ROUND_UP_AT_POINT_FIVE)
Given a size in kilobyes, return a human readable size.
WvString diff_dates(time_t t1, time_t t2)
Returns the difference between to dates in a human readable format.
WvString hostname()
Do gethostname() without a fixed-length buffer.
WvString metriculate(const off_t i)
Inserts SI-style spacing into a number (eg passing 9876543210 returns "9 876 543 210")
WvString secondstoa(unsigned int total_seconds)
Given a number of seconds, returns a formatted human-readable string saying how long the period is.
char * non_breaking(const char *string)
Replaces all whitespace characters in the string with non-breaking spaces ( ) for use with web stuff...
WvString sizekitoa(unsigned long long kbytes, RoundingMethod rounding_method=ROUND_UP_AT_POINT_FIVE)
Given a size in kilobytes, return a human readable size.
char * trim_string(char *string)
Trims whitespace from the beginning and end of the character string, including carriage return / line...
time_t intl_gmtoff(time_t t)
Return the number of seconds by which localtime (at the given timestamp) is offset from GMT.
WvString substr(WvString line, unsigned int pos, unsigned int len)
Returns the string of length len starting at pos in line.
WvString url_decode(WvStringParm str, bool no_space=false)
Converts escaped characters (things like %20 etc.) from web URLS into their normal ASCII representati...
WvString afterstr(WvStringParm line, WvStringParm a)
Returns everything in line (exclusively) after a.
void replace_char(void *string, char c1, char c2, int length)
Replace all instances of c1 with c2 for the first 'length' characters in 'string'.
WvString passwd_crypt(const char *str)
Similar to crypt(), but this randomly selects its own salt.
WvString intl_datetime(time_t _when=-1)
Return the local date and time (in format of ISO 8601) out of _when.
WvString cstr_escape(const void *data, size_t size, const CStrExtraEscape extra_escapes[]=NULL)
Converts data into a C-style string constant.
char * strlwr(char *string)
In-place modify a character string so that all contained letters are in lower case.
void strcoll_split(StringCollection &coll, WvStringParm _s, const char *splitchars=" \t", int limit=0)
Splits a string and adds each substring to a collection.
char * snip_string(char *haystack, char *needle)
Snip off the first part of 'haystack' if it consists of 'needle'.
void strcoll_splitstrict(StringCollection &coll, WvStringParm _s, const char *splitchars=" \t", int limit=0)
Splits a string and adds each substring to a collection.
WvString depunctuate(WvStringParm line)
Removes any trailing punctuation ('.
char * strupr(char *string)
In-place modify a character string so that all contained letters are in upper case.
WvString spacecat(WvStringParm a, WvStringParm b, char sep=' ', bool onesep=false)
return the string formed by concatenating string 'a' and string 'b' with the 'sep' character between ...
WvString undupe(WvStringParm s, char c)
Replace any consecutive instances of character c with a single one.
WvString wvgetcwd()
Get the current working directory without a fixed-length buffer.
WvString intl_time(time_t _when=-1)
Return the local time (in format of ISO 8601) out of _when.