File:  [Public] / libwww / Library / src / HTString.html
Revision 2.38: download - view: text, annotated - select for diffs
Sat Jul 31 01:27:55 1999 UTC (24 years, 10 months ago) by raff
Branches: MAIN
CVS tags: repeat-requests, before_webdav, Release-5-4-0, Release-5-3-1, HEAD, Amaya-6-3, Amaya-6-1, Amaya-5-2, Amaya-4-3-2, Amaya-4-3-1, Amaya-4-3, Amaya-4-1-2, Amaya-4-1-0, Amaya-4-0-0, Amaya-3-2-1, Amaya-3-2, Amaya
added tail string comparison functions to be used for Cookie support
(for checking domain names)

<HTML>
<HEAD>
  <!-- Changed by: Henrik Frystyk Nielsen,  6-Apr-1996 -->
  <TITLE>W3C Sample Code Library libwww Generic String Management</TITLE>
</HEAD>
<BODY>
<H1>
  Generic String Management
</H1>
<PRE>
/*
**	(c) COPYRIGHT MIT 1995.
**	Please first read the full copyright statement in the file COPYRIGH.
*/
</PRE>
<P>
These functions provide functionality for case-independent string comparison
and allocations with copies etc.
<P>
This module is implemented by <A HREF="HTString.c">HTString.c</A>, and it
is a part of the <A NAME="z10" HREF="http://www.w3.org/Library/">W3C
Sample Code Library</A>.
<PRE>
#ifndef HTSTRING_H
#define HTSTRING_H
</PRE>
<H2>
  <A NAME="dyn">Dynamic String Manipulation</A>
</H2>
<P>
These two functions are dynamic versions of <CODE>strcpy</CODE> and
<CODE>strcat</CODE>. They use <CODE>malloc</CODE> for allocating space for
the string. If <CODE>StrAllocCopy</CODE> is called with a non-NULL dest,
then this is freed before the new value is assigned so that only the
<EM>last</EM> string created has to be freed by the user. If
<CODE>StrAllocCat</CODE> is called with a NULL pointer as destination then
it is equivalent to <CODE>StrAllocCopy</CODE>. <A NAME="HTSACopy"></A>
<PRE>
#define StrAllocCopy(dest, src) HTSACopy (&amp;(dest), src)
#define StrAllocCat(dest, src)  HTSACat  (&amp;(dest), src)

extern char * HTSACopy (char **dest, const char *src);
extern char * HTSACat  (char **dest, const char *src);
</PRE>
<P>
The next two functions take a variable number of strings and cats them together
using dynamic memory. This is basically like a simple form for sprintf where
the only argument is <CODE>char *</CODE>. One day we should turn this into
a real dynamic <CODE>sprintf()</CODE>.
<PRE>
extern char * StrAllocMCopy (char ** dest, ...);
extern char * StrAllocMCat (char ** dest, ...);
</PRE>
<P>
The last argument MUST be NULL as we otherwise don't know when the argument
list stops.
<H2>
  <A NAME="utils">Case-insensitive String Comparison</A>
</H2>
<P>
The usual routines (comp instead of cmp) had some problem.
<PRE>
extern int strcasecomp  (const char *a, const char *b);
extern int strncasecomp (const char *a, const char *b, int n);
</PRE>
<H2>
  <A NAME="cookies">Tail String Comparison</A>
</H2>
<P>
Like strcmp, but match the tail of s2 (used for cookie domain comparison)
<PRE>
extern int tailcomp(const char * s1, const char * s2);
extern int tailcasecomp(const char * s1, const char * s2);
</PRE>
<H2>
  String Comparison with Wild Card Match
</H2>
<P>
String comparison function for file names with one wildcard * in the template.
Arguments are:
<DL>
  <DT>
    tmpl
  <DD>
    is a template string to match the name against. agaist, may contain a single
    wildcard character * which matches zero or more arbitrary characters.
  <DT>
    name
  <DD>
    is the name to be matched agaist the template.
</DL>
<P>
Returns empty string ("") if perfect match, pointer to part matched by wildcard
if any, or NULL if no match. This is basically the same as YES if match,
else NO.
<PRE>
extern char * HTStrMatch	(const char * tmpl, const char * name);
extern char * HTStrCaseMatch	(const char * tmpl, const char * name);
</PRE>
<H2>
  Case-insensitive strstr
</H2>
<P>
This works like <CODE>strstr()</CODE> but is not case-sensitive.
<PRE>
extern char * HTStrCaseStr (char * s1, char * s2);
</PRE>
<H2>
  Strip white space off a string
</H2>
<P>
Return value points to first non-white character, or to '/0' if none. All
trailing white space is OVERWRITTEN with zero.
<PRE>
extern char * HTStrip (char * s);
</PRE>
<PRE>
#endif /* !HTSTRING_H */
</PRE>
<P>
  <HR>
<ADDRESS>
  @(#) $Id: HTString.html,v 2.38 1999/07/31 01:27:55 raff Exp $
</ADDRESS>
</BODY></HTML>

Webmaster