stdlib: Fix Lth_Hash_* not masking characters, breaking unicode.
parent
f69a1e8412
commit
0592eca67f
|
@ -43,6 +43,6 @@ void Lth_PrintString(char const *s);
|
||||||
|
|
||||||
// Hash
|
// Hash
|
||||||
size_t Lth_Hash_char(char const *s);
|
size_t Lth_Hash_char(char const *s);
|
||||||
size_t Lth_Hash_str(__str s);
|
size_t Lth_Hash_str(char __str_ars const *s);
|
||||||
|
|
||||||
#endif//lithos3__Lth_stdlib_h
|
#endif//lithos3__Lth_stdlib_h
|
||||||
|
|
|
@ -183,7 +183,7 @@ static void ManifestGetInitializer(ManifestState *repr, size_t key)
|
||||||
break;
|
break;
|
||||||
case Lth_TOK_Identi:
|
case Lth_TOK_Identi:
|
||||||
__with(char const *str = Lth_TokenStreamBump(repr->stream)->str;)
|
__with(char const *str = Lth_TokenStreamBump(repr->stream)->str;)
|
||||||
if(strcmp(str, "true") == 0) GenValueGetter(Integ, integ, 1);
|
if(strcmp(str, "true") == 0) GenValueGetter(Integ, integ, 1);
|
||||||
else if(strcmp(str, "false") == 0) GenValueGetter(Integ, integ, 0);
|
else if(strcmp(str, "false") == 0) GenValueGetter(Integ, integ, 0);
|
||||||
default:
|
default:
|
||||||
ManifestError(repr, "expected initializer");
|
ManifestError(repr, "expected initializer");
|
||||||
|
|
|
@ -17,6 +17,16 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define GenStrHash() \
|
||||||
|
if(s == NULL) return 0; \
|
||||||
|
\
|
||||||
|
size_t ret = 0; \
|
||||||
|
\
|
||||||
|
while(*s) \
|
||||||
|
ret = ret * 101 + ((unsigned char)(*s++) & 0xff); \
|
||||||
|
\
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
// Extern Functions ----------------------------------------------------------|
|
// Extern Functions ----------------------------------------------------------|
|
||||||
|
|
||||||
|
@ -132,30 +142,15 @@ void Lth_PrintString(char const *s)
|
||||||
//
|
//
|
||||||
size_t Lth_Hash_char(char const *s)
|
size_t Lth_Hash_char(char const *s)
|
||||||
{
|
{
|
||||||
if(s == NULL) return 0;
|
GenStrHash();
|
||||||
|
|
||||||
size_t ret = 0;
|
|
||||||
|
|
||||||
while(*s)
|
|
||||||
ret = ret * 101 + (unsigned char)(*s++);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Lth_Hash_str
|
// Lth_Hash_str
|
||||||
//
|
//
|
||||||
size_t Lth_Hash_str(__str s)
|
size_t Lth_Hash_str(char __str_ars const *s)
|
||||||
{
|
{
|
||||||
if(s == NULL) return 0;
|
GenStrHash();
|
||||||
|
|
||||||
size_t ret = 0;
|
|
||||||
size_t len = ACS_StrLen(s);
|
|
||||||
|
|
||||||
for(size_t i = 0; i < len; i++)
|
|
||||||
ret = ret * 101 + (unsigned char)(s[i]);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// EOF
|
// EOF
|
||||||
|
|
Loading…
Reference in New Issue