18#include "wvstringlist.h"
81void replace_char(
void *
string,
char c1,
char c2,
int length);
104bool is_word(
const char *
string);
225 ROUND_DOWN_AT_POINT_FIVE,
226 ROUND_UP_AT_POINT_FIVE,
235WvString sizetoa(
unsigned long long blocks,
unsigned long blocksize = 1,
236 RoundingMethod rounding_method = ROUND_UP_AT_POINT_FIVE);
243 RoundingMethod rounding_method = ROUND_UP_AT_POINT_FIVE);
251 RoundingMethod rounding_method = ROUND_UP_AT_POINT_FIVE);
258 RoundingMethod rounding_method = ROUND_UP_AT_POINT_FIVE);
269int lookup(
const char *str,
const char *
const *table,
270 bool case_sensitive =
false);
279template<
class StringCollection>
281 const char *splitchars =
" \t",
int limit = 0)
284 char *sptr = s.
edit(), *eptr, oldc;
290 coll.add(emptyString,
true);
294 bool firstrun =
true;
296 while (sptr && *sptr)
306 sptr += strspn(sptr, splitchars);
311 eptr = sptr + strcspn(sptr, splitchars);
315 eptr = sptr + strlen(sptr);
322 coll.add(newstr,
true);
343template<
class StringCollection>
345 const char *splitchars =
" \t",
int limit = 0)
348 char *cur = s.
edit();
361 int len = strcspn(cur, splitchars);
368 if (!cur[len])
break;
382template<class StringCollection>
384 const WvRegex ®ex,
int limit = 0)
387 int match_start, match_end;
390 while ((limit == 0 || count < limit)
395 int len = match_start;
404 if (limit == 0 || count < limit)
408 coll.add(last,
true);
419template<
class StringCollection>
421 const char *joinchars =
" \t")
423 size_t joinlen = strlen(joinchars);
425 typename StringCollection::Iter s(
426 const_cast<StringCollection&
>(coll));
427 for (s.rewind(); s.next(); )
430 totlen += strlen(s->cstr());
436 total.setsize(totlen);
438 char *te = total.
edit();
441 for (s.rewind(); s.next(); )
446 strcat(te, joinchars);
448 strcat(te, s->cstr());
510 for (
const char *p = str; *p; ++p)
514 n = n * T(10) + T(*p -
'0');
516 else if ((
const char *)str == p
593static inline bool is_int(
const char *str)
605 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.