Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

strutils.cc File Reference

#include "strutils.h"
#include "wvbuf.h"
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <netdb.h>
#include <unistd.h>

Go to the source code of this file.

Functions

char * terminate_string (char *string, char c)
 Add character c to the end of a string after removing terminating carriage returns/linefeeds if any.

char * trim_string (char *string)
 Trims whitespace from the beginning and end of the character string, including carriage return / linefeed characters.

char * trim_string (char *string, char c)
 Similar to above, but trims the string starting at the first occurrence of c.

char * non_breaking (char *string)
 Replaces all whitespace characters in the string with non-breaking spaces ( ) for use with web stuff.

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'.

char * snip_string (char *haystack, char *needle)
 Snip off the first part of 'haystack' if it consists of 'needle'.

char * strlwr (char *string)
 In-place modify a character string so that all contained letters are in lower case.

char * strupr (char *string)
 In-place modify a character string so that all contained letters are in upper case.

bool is_word (const char *p)
 Returns true if all characters in 'string' are isalnum() (alphanumeric).

WvString hexdump_buffer (const void *_buf, size_t len, bool charRep)
 Produce a hexadecimal dump of the data buffer in 'buf' of length 'len'.

bool isnewline (char c)
 Returns true if 'c' is a newline or carriage return character.

WvString web_unescape (const char *str)
 Converts escaped characters (things like 20 etc.) from web URLS into their normal ASCII representations.

WvString url_encode (WvStringParm stuff)
 Converts all those pesky spaces, colons, and other nasties into nice unreadable Quasi-Unicode codes.

WvString rfc822_date (time_t when)
 Returns an RFC822-compatible date made out of _when, or, if _when < 0, out of the current time.

WvString backslash_escape (WvStringParm s1)
 Returns a string with a backslash in front of every non alphanumeric character in s1.

int strcount (WvStringParm s, const char c)
 How many times does 'c' occur in "s"?

WvString encode_hostname_as_DN (WvStringParm hostname)
 Example: encode_hostname_as_DN("www.fizzle.com") will result in dc=www,dc=fizzle,dc=com,cn=www.fizzle.com.

WvString nice_hostname (WvStringParm name)
 Given a hostname, turn it into a "nice" one.

WvString getfilename (WvStringParm fullname)
 Take a full path/file name and splits it up into respective pathname and filename.

WvString getdirname (WvStringParm fullname)
WvString sizetoa (long long blocks, int blocksize)
 Given a number of blocks and a blocksize (default==1 byte), return a WvString containing a human-readable representation of blocks*blocksize.

WvString strreplace (WvStringParm s, WvStringParm a, WvStringParm b)
 Replace any instances of "a" with "b" in "s".

WvString undupe (WvStringParm s, char c)
 Replace any consecutive instances of character c with a single one.

WvString rfc1123_date (time_t t)
 Returns an RFC1123-compatible date made out of _when.

int lookup (const char *str, const char *const *table, bool case_sensitive)
 Finds a string in an array and returns its index.

WvString hostname ()
WvString fqdomainname ()
WvString metriculate (const off_t i)
 Inserts SI-style spacing into a number (eg passing 9876543210 returns "9 876 543 210").


Function Documentation

WvString backslash_escape WvStringParm  s1  ) 
 

Returns a string with a backslash in front of every non alphanumeric character in s1.

Definition at line 314 of file strutils.cc.

References WvString::edit(), WvFastString::len(), WvFastString::setsize(), and WvStringParm.

WvString encode_hostname_as_DN WvStringParm  hostname  ) 
 

Example: encode_hostname_as_DN("www.fizzle.com") will result in dc=www,dc=fizzle,dc=com,cn=www.fizzle.com.

Definition at line 348 of file strutils.cc.

References WvString::append(), hostname(), WvStringList::split(), and WvStringParm.

Referenced by main().

WvString fqdomainname  ) 
 

Definition at line 568 of file strutils.cc.

References hostname().

Referenced by main().

WvString getdirname WvStringParm  fullname  ) 
 

Definition at line 427 of file strutils.cc.

References WvString::edit(), and WvStringParm.

Referenced by WvFtpStream::execute(), WvDirIter::next(), and WvLockFile::readpid().

WvString getfilename WvStringParm  fullname  ) 
 

Take a full path/file name and splits it up into respective pathname and filename.

This can also be useful for splitting the toplevel directory off a path.

Definition at line 410 of file strutils.cc.

References WvString::edit(), and WvStringParm.

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'.

It is formatted with 16 bytes per line; each line has an address offset, hex representation, and printable representation.

This is used mostly for debugging purposes. You can send the returned WvString object directly to a WvLog or any other WvStream for output.

Definition at line 181 of file strutils.cc.

References WvString::edit(), and WvFastString::setsize().

Referenced by WvDiffieHellman::create_secret().

WvString hostname  ) 
 

Definition at line 545 of file strutils.cc.

References hostname().

Referenced by WvResolver::clearhost(), encode_hostname_as_DN(), fqdomainname(), hostname(), WvResolver::pre_select(), and WvTCPConn::WvTCPConn().

bool is_word const char *  p  ) 
 

Returns true if all characters in 'string' are isalnum() (alphanumeric).

Definition at line 166 of file strutils.cc.

bool isnewline char  c  ) 
 

Returns true if 'c' is a newline or carriage return character.

Increases code readability a bit.

Definition at line 234 of file strutils.cc.

int lookup const char *  str,
const char *const *  table,
bool  case_sensitive = false
 

Finds a string in an array and returns its index.

Returns -1 if not found.

Definition at line 525 of file strutils.cc.

Referenced by WvX509Mgr::signedbyCAinfile(), string_to_ver(), and WvProtoStream::tokanal().

WvString metriculate const off_t  i  ) 
 

Inserts SI-style spacing into a number (eg passing 9876543210 returns "9 876 543 210").

Definition at line 580 of file strutils.cc.

References WvString::edit(), and WvFastString::setsize().

WvString nice_hostname WvStringParm  name  ) 
 

Given a hostname, turn it into a "nice" one.

It has to start with a letter/number, END with a letter/number, have underscores converted to hyphens, and have no more than one hyphen in a row. If we can't do this and have any sort of answer, return "UNKNOWN".

Definition at line 364 of file strutils.cc.

References WvString::edit(), WvFastString::len(), WvFastString::setsize(), and WvStringParm.

char* non_breaking char *  string  ) 
 

Replaces all whitespace characters in the string with non-breaking spaces ( ) for use with web stuff.

Definition at line 93 of file strutils.cc.

References WvString::edit(), and WvDynBuf.

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'.

Ignores terminating NULL, so make sure you set 'length' correctly.

Definition at line 116 of file strutils.cc.

WvString rfc1123_date time_t  t  ) 
 

Returns an RFC1123-compatible date made out of _when.

Definition at line 513 of file strutils.cc.

References WvString::edit(), and WvFastString::setsize().

WvString rfc822_date time_t  when  ) 
 

Returns an RFC822-compatible date made out of _when, or, if _when < 0, out of the current time.

Definition at line 299 of file strutils.cc.

References WvString::edit(), and WvFastString::setsize().

WvString sizetoa long long  blocks,
int  blocksize
 

Given a number of blocks and a blocksize (default==1 byte), return a WvString containing a human-readable representation of blocks*blocksize.

Definition at line 447 of file strutils.cc.

char* snip_string char *  haystack,
char *  needle
 

Snip off the first part of 'haystack' if it consists of 'needle'.

Definition at line 125 of file strutils.cc.

int strcount WvStringParm  s,
const char  c
 

How many times does 'c' occur in "s"?

Definition at line 337 of file strutils.cc.

References WvStringParm.

char* strlwr char *  string  ) 
 

In-place modify a character string so that all contained letters are in lower case.

Returns 'string'.

Definition at line 139 of file strutils.cc.

Referenced by WvLogRcv::log(), main(), WvLogRcv::set_custom_levels(), and set_name_entry().

WvString strreplace WvStringParm  s,
WvStringParm  a,
WvStringParm  b
 

Replace any instances of "a" with "b" in "s".

Kind of like sed, only much dumber.

Definition at line 472 of file strutils.cc.

References WvBufBaseCommonImpl< T >::put(), WvDynBuf, and WvStringParm.

char* strupr char *  string  ) 
 

In-place modify a character string so that all contained letters are in upper case.

Returns 'string'.

Definition at line 152 of file strutils.cc.

char* terminate_string char *  string,
char  c
 

Add character c to the end of a string after removing terminating carriage returns/linefeeds if any.

You need a buffer that's at least one character bigger than the current length of the string, including the terminating NULL.

Definition at line 26 of file strutils.cc.

char* trim_string char *  string,
char  c
 

Similar to above, but trims the string starting at the first occurrence of c.

Definition at line 71 of file strutils.cc.

Referenced by WvHttpStream::execute(), WvConf::load_file(), WvLockDev::lock(), parse_wvconf_request(), WvConf::parse_wvconf_request(), WvConfigSection::quick_set(), UniIniGen::refresh(), WvConfigSection::set(), WvLogRcv::set_custom_levels(), set_name_entry(), WvProtoStream::token_remaining(), WvProtoStream::tokline(), WvHTTPStream::uread(), web_unescape(), and WvUrl::WvUrl().

char* trim_string char *  string  ) 
 

Trims whitespace from the beginning and end of the character string, including carriage return / linefeed characters.

Modifies the string in place. Returns the new first character of the string, which points either at 'string' itself or some character contained therein.

string is allowed to be NULL; returns NULL in that case.

Definition at line 48 of file strutils.cc.

WvString undupe WvStringParm  s,
char  c
 

Replace any consecutive instances of character c with a single one.

Definition at line 489 of file strutils.cc.

References WvDynBuf, and WvStringParm.

WvString url_encode WvStringParm  stuff  ) 
 

Converts all those pesky spaces, colons, and other nasties into nice unreadable Quasi-Unicode codes.

Definition at line 277 of file strutils.cc.

References WvFastString::len(), WvBufBaseCommonImpl< T >::put(), WvDynBuf, and WvStringParm.

WvString web_unescape const char *  str  ) 
 

Converts escaped characters (things like 20 etc.) from web URLS into their normal ASCII representations.

Definition at line 240 of file strutils.cc.

References WvString::edit(), WvFastString::setsize(), and trim_string().


Generated on Sat Feb 21 21:05:36 2004 for WvStreams by doxygen 1.3.5