forked from github/server
bugfix non-case-sensitive ct_find
This commit is contained in:
parent
7ced18cfef
commit
4349ce9456
|
@ -46,6 +46,7 @@
|
|||
#include <limits.h>
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <ctype.h>
|
||||
|
||||
/* spells includes */
|
||||
#include <spells/regioncurse.h>
|
||||
|
@ -228,10 +229,22 @@ typedef struct cursetype_list {
|
|||
#define CMAXHASH 63
|
||||
cursetype_list * cursetypes[CMAXHASH];
|
||||
|
||||
static char *
|
||||
strlower(const char * str)
|
||||
{
|
||||
static char result[128];
|
||||
char * pos = result;
|
||||
while (*str) {
|
||||
*pos++ = (char)tolower(*(unsigned char*)str++);
|
||||
}
|
||||
*pos=0;
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
ct_register(const curse_type * ct)
|
||||
{
|
||||
unsigned int hash = hashstring(ct->cname) % CMAXHASH;
|
||||
unsigned int hash = hashstring(strlower(ct->cname)) % CMAXHASH;
|
||||
cursetype_list ** ctlp = &cursetypes[hash];
|
||||
while (*ctlp) {
|
||||
cursetype_list * ctl = *ctlp;
|
||||
|
@ -245,7 +258,8 @@ ct_register(const curse_type * ct)
|
|||
const curse_type *
|
||||
ct_find(const char *c)
|
||||
{
|
||||
unsigned int hash = hashstring(c) % CMAXHASH;
|
||||
char * lower = strlower(c);
|
||||
unsigned int hash = hashstring(lower) % CMAXHASH;
|
||||
cursetype_list * ctl = cursetypes[hash];
|
||||
while (ctl) {
|
||||
int k = min(strlen(c), strlen(ctl->type->cname));
|
||||
|
|
Loading…
Reference in New Issue