add lower-case hash (used by VFS) and revise match_wildcard to accept anything if pattern=0

This was SVN commit r2054.
This commit is contained in:
janwas 2005-03-27 01:31:39 +00:00
parent 2fb2f80aa0
commit ffdc1d8360
2 changed files with 45 additions and 3 deletions

View File

@ -98,6 +98,41 @@ u64 fnv_hash64(const void* buf, const size_t len)
}
// special version for strings: first converts to lowercase
// (useful for comparing mixed-case filenames).
// note: still need <len>, e.g. to support non-0-terminated strings
u32 fnv_lc_hash(const char* str, const size_t len)
{
u32 h = 0x811c9dc5u;
// give distinct values for different length 0 buffers.
// value taken from FNV; it has no special significance.
// expected case: string
if(!len)
{
while(*str)
{
h ^= tolower(*str++);
h *= 0x01000193u;
}
}
else
{
size_t bytes_left = len;
while(bytes_left != 0)
{
h ^= tolower(*str++);
h *= 0x01000193u;
bytes_left--;
}
}
return h;
}
bool is_pow2(const long n)
@ -259,8 +294,12 @@ void base32(const int len, const u8* in, u8* out)
// case-insensitive check if string <s> matches the pattern <w>,
// which may contain '?' or '*' wildcards. if so, return 1, otherwise 0.
// idea from http://www.codeproject.com/string/wildcmp.asp .
// note: NULL wildcard pattern matches everything!
int match_wildcard(const char* s, const char* w)
{
if(!w)
return 1;
// saved position in both strings, used to expand '*':
// s2 is advanced until match.
// initially 0 - we abort on mismatch before the first '*'.

View File

@ -100,7 +100,7 @@ STMT(\
int err__ = (int)((func) & UINT_MAX);\
if(err__ < 0)\
{\
assert(0 && "FYI: CHECK_ERR reports that a function failed."\
assert2(0 && "FYI: CHECK_ERR reports that a function failed."\
"feel free to ignore or suppress this warning.");\
return err__;\
}\
@ -269,14 +269,16 @@ const size_t GiB = 1ul << 30;
// FNV1-A hash - good for strings.
// if len = 0 (default), treat buf as a C-string;
// otherwise, hash <len> bytes of buf.
extern u32 fnv_hash(const void* buf, const size_t len = 0);
extern u64 fnv_hash64(const void* buf, const size_t len = 0);
// special version for strings: first converts to lowercase
// (useful for comparing mixed-case filenames)
extern u32 fnv_lc_hash(const char* str, const size_t len = 0);
// hash (currently FNV) of a filename
typedef u32 FnHash;
@ -306,6 +308,7 @@ extern void base32(const int len, const u8* in, u8* out);
// case-insensitive check if string <s> matches the pattern <w>,
// which may contain '?' or '*' wildcards. if so, return 1, otherwise 0.
// note: NULL wildcard pattern matches everything!
extern int match_wildcard(const char* s, const char* w);