qse/ase/stx/misc.c

66 lines
1.3 KiB
C
Raw Normal View History

2005-05-15 18:37:00 +00:00
/*
2005-06-08 16:00:51 +00:00
* $Id: misc.c,v 1.3 2005-06-08 16:00:51 bacon Exp $
2005-05-15 18:37:00 +00:00
*/
#include <xp/stx/misc.h>
2005-06-08 16:00:51 +00:00
xp_word_t xp_stx_strlen (const xp_char_t* str)
2005-05-15 18:37:00 +00:00
{
2005-06-08 16:00:51 +00:00
const xp_char_t* p = str;
while (*p != XP_CHAR('\0')) p++;
2005-05-15 18:37:00 +00:00
return p - str;
}
2005-06-08 16:00:51 +00:00
int xp_stx_strcmp (const xp_char_t* s1, const xp_char_t* s2)
2005-05-15 18:37:00 +00:00
{
2005-06-08 16:00:51 +00:00
while (*s1 == *s2 && *s2 != XP_CHAR('\0')) s1++, s2++;
2005-05-15 18:37:00 +00:00
if (*s1 > *s2) return 1;
else if (*s1 < *s2) return -1;
return 0;
}
int xp_stx_strxcmp (
2005-06-08 16:00:51 +00:00
const xp_char_t* s1, xp_word_t len, const xp_char_t* s2)
2005-05-15 18:37:00 +00:00
{
2005-06-08 16:00:51 +00:00
const xp_char_t* end = s1 + len;
while (s1 < end && *s2 != XP_CHAR('\0') && *s1 == *s2) {
2005-05-15 18:37:00 +00:00
s1++; s2++;
}
2005-06-08 16:00:51 +00:00
if (s1 == end && *s2 == XP_CHAR('\0')) return 0;
2005-05-15 18:37:00 +00:00
if (*s1 == *s2) return (s1 < end)? 1: -1;
return (*s1 > *s2)? 1: -1;
}
2005-06-08 16:00:51 +00:00
xp_word_t xp_stx_strhash (const xp_char_t* str)
2005-05-15 18:37:00 +00:00
{
2005-06-08 16:00:51 +00:00
xp_word_t h = 0;
xp_byte_t* bp, * be;
const xp_char_t* p = str;
2005-05-15 18:37:00 +00:00
2005-06-08 16:00:51 +00:00
while (*p != XP_CHAR('\0')) {
bp = (xp_byte_t*)p;
be = bp + xp_sizeof(xp_char_t);
2005-05-15 18:37:00 +00:00
while (bp < be) h = h * 31 + *bp++;
p++;
}
return h;
}
2005-06-08 16:00:51 +00:00
xp_word_t xp_stx_strxhash (const xp_char_t* str, xp_word_t len)
2005-05-15 18:37:00 +00:00
{
2005-06-08 16:00:51 +00:00
xp_word_t h = 0;
xp_byte_t* bp, * be;
const xp_char_t* p = str, * end = str + len;
2005-05-15 18:37:00 +00:00
while (p < end) {
2005-06-08 16:00:51 +00:00
bp = (xp_byte_t*)p;
be = bp + xp_sizeof(xp_char_t);
2005-05-15 18:37:00 +00:00
while (bp < be) h = h * 31 + *bp++;
p++;
}
return h;
}