qse/ase/stx/misc.c

60 lines
1.0 KiB
C
Raw Normal View History

2005-05-15 18:37:00 +00:00
/*
2005-06-30 15:11:00 +00:00
* $Id: misc.c,v 1.6 2005-06-30 15:11:00 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_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;
}
2005-06-30 12:07:02 +00:00
xp_char_t* xp_stx_strword (
2005-06-30 15:11:00 +00:00
const xp_char_t* str, const xp_char_t* word, xp_word_t* word_index)
2005-06-30 12:07:02 +00:00
{
xp_char_t* p = (xp_char_t*)str;
xp_char_t* tok;
xp_size_t len;
xp_word_t index = 0;
while (p != XP_NULL) {
p = xp_strtok (p, XP_TEXT(""), &tok, &len);
if (xp_strxcmp (tok, len, word) == 0) {
*word_index = index;
return tok;
}
index++;
}
2005-06-30 15:11:00 +00:00
*word_index = index;
2005-06-30 12:07:02 +00:00
return XP_NULL;
}