stringutil.c
stringutil.c · 1.1 KB
From the archive pernmush-1.17.01.tar.gz
Download the archive « Back to the archive contents
/* stringutil.c */
/* String utilities */
#include <ctype.h>
#include <string.h>
#include "copyright.h"
#include "interface.h"
#include "globals.h"
int string_compare(s1, s2)
const char *s1;
const char *s2;
{
while (*s1 && *s2 && DOWNCASE(*s1) == DOWNCASE(*s2))
s1++, s2++;
return (DOWNCASE(*s1) - DOWNCASE(*s2));
}
int string_prefix(string, prefix)
const char *string;
const char *prefix;
{
if (!string || !prefix) return 0;
while (*string && *prefix && DOWNCASE(*string) == DOWNCASE(*prefix))
string++, prefix++;
return *prefix == '\0';
}
/* accepts only nonempty matches starting at the beginning of a word */
const char *string_match(src, sub)
const char *src;
const char *sub;
{
if (*sub != '\0') {
while (*src) {
if (string_prefix(src, sub))
return src;
/* else scan to beginning of next word */
while (*src && isalnum(*src))
src++;
while (*src && !isalnum(*src))
src++;
}
}
return 0;
}
char *strupper(s)
const char *s;
{
static char buf1[BUFFER_LEN];
char *p;
strcpy(buf1, s);
for(p = buf1; *p; p++)
*p = UPCASE(*p);
return buf1;
}