String Management
/*
** (c) COPYRIGHT MIT 1995.
** Please first read the full copyright statement in the file COPYRIGH.
*/
These functions provide functionality for case-independent string
comparison and allocations with copies etc.
This module is implemented by HTString.c, and
it is a part of the
W3C Reference Library.
#ifndef HTSTRING_H
#define HTSTRING_H
extern CONST char * HTLibraryVersion; /* String for help screen etc */
These two functions are dynamic versions of strcpy
and
strcat
. They use malloc
for allocating space
for the string. If StrAllocCopy
is called with a non-NULL
dest, then this is freed before the new value is assigned so that only
the last string created has to be freed by the user. If
StrAllocCat
is called with a NULL pointer as destination
then it is equivalent to StrAllocCopy
.
#define StrAllocCopy(dest, src) HTSACopy (&(dest), src)
#define StrAllocCat(dest, src) HTSACat (&(dest), src)
extern char * HTSACopy (char **dest, CONST char *src);
extern char * HTSACat (char **dest, CONST char *src);
The usual routines (comp instead of cmp) had some problem.
extern int strcasecomp (CONST char *a, CONST char *b);
extern int strncasecomp (CONST char *a, CONST char *b, int n);
String Comparison with Wild Card Match
String comparison function for file names with one wildcard * in the
template. Arguments are:
- tmpl
- is a template string to match the name against. agaist, may
contain a single wildcard character * which matches zero or more
arbitrary characters.
- name
- is the name to be matched agaist the template.
returns YES, if filename matches the template, else NO
extern BOOL HTStringMatch (CONST char * tmpl, CONST char * name);
extern BOOL HTStringCaseMatch (CONST char * tmpl, CONST char * name);
Case-insensitive strstr
This works like strstr()
but is not case-sensitive.
extern char * strcasestr (char * s1, char * s2);
Strip white space off a string
Return value points to first non-white character, or to '/0' if
none. All trailing white space is OVERWRITTEN with zero.
extern char * HTStrip (char * s);
Next word or quoted string
This function returns a RFC822 word separated by space, comma, or
semi-colons.
extern char * HTNextField (char** pstr);
RFC1123 Date/Time Stamp String
Returns a pointer to a static area!
extern CONST char *HTDateTimeStr (time_t *calendar, BOOL local);
Date used for directory listings
extern BOOL HTDateDirStr (time_t * time, char * str, int len);
Timezone Offset
Calculates the offset from GMT in seconds. This is called from HTLibInit().
extern long HTGetTimeZoneOffset (void);
Parse a Date/Time String
Converts a string representation in GMT to a local representation of
localtime time_t
.
extern time_t HTParseTime (CONST char * str);
Unique Message-ID String
extern CONST char *HTMessageIdStr (void);
#endif
Converts an Integer to a String using Prefix
In computer-world 1K is 1024 bytes and 1M is 1024K -- however,
sprintf() still formats in base-10. Therefore I output only until
999, and then start using the next unit. This doesn't work wrong,
it's just a feature. The conversion is done in "str" which must be
large enough to contain the result.
extern void HTNumToStr (unsigned long n, char *str, int len);
Conversion between URLs and Local File Names
These are two functions that separate the URL naming syntax from
platform dependent file naming schemes. If you are porting the code to
a new platform, you probably have to do some translation here.
Convert file URLs into a local representation
The URL has already been translated through the rules in get_physical
in HTAccess.c and all we need to do now is to map the path to a local
representation, for example if must translate '/' to the ones that
turn the wrong way ;-) Returns local file (that must be freed by
caller) if OK, else NULL.
extern char * HTWWWToLocal (CONST char * url, CONST char * base);
Convert a local file name into a URL
Generates a WWW URL name from a local file name or NULL if error.
Returns URL (that must be freed by caller) if OK, else NULL.
extern char * HTLocalToWWW (CONST char * local);
End of declaration module