diff --git a/src/tag.c b/src/tag.c index 550d01a5..7b4030c8 100644 --- a/src/tag.c +++ b/src/tag.c @@ -15,6 +15,7 @@ // Author: jdtang@google.com (Jonathan Tang) #include "gumbo.h" +#include "util.h" #include #include @@ -60,14 +61,21 @@ void gumbo_tag_from_original_text(GumboStringPiece* text) { } } +/* + * Override the `tolower` implementation in the perfect hash + * to use ours. We need a custom `tolower` that only does ASCII + * characters and is locale-independent to remain truthy to the + * standard + */ +#define tolower(c) gumbo_tolower(c) #include "tag_perf.h" static int case_memcmp(const char *s1, const char *s2, int n) { while (n--) { - unsigned char c1 = tolower(*s1++); - unsigned char c2 = tolower(*s2++); + unsigned char c1 = gumbo_tolower(*s1++); + unsigned char c2 = gumbo_tolower(*s2++); if (c1 != c2) return (int)c1 - (int)c2; } diff --git a/src/util.h b/src/util.h index c3edc27a..00d29907 100644 --- a/src/util.h +++ b/src/util.h @@ -57,6 +57,11 @@ static inline void gumbo_free(void *ptr) gumbo_user_free(ptr); } +static inline int gumbo_tolower(int c) +{ + return c | ((c >= 'A' && c <= 'Z') << 5); +} + // Debug wrapper for printf, to make it easier to turn off debugging info when // required. void gumbo_debug(const char* format, ...);