Skip to content
This repository was archived by the owner on Jan 21, 2026. It is now read-only.

Commit 06e797e

Browse files
author
Vicent Marti
committed
tags: Use an ASCII-only tolower function
1 parent a87add3 commit 06e797e

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

src/tag.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// Author: jdtang@google.com (Jonathan Tang)
1616

1717
#include "gumbo.h"
18+
#include "util.h"
1819

1920
#include <assert.h>
2021
#include <ctype.h>
@@ -60,14 +61,21 @@ void gumbo_tag_from_original_text(GumboStringPiece* text) {
6061
}
6162
}
6263

64+
/*
65+
* Override the `tolower` implementation in the perfect hash
66+
* to use ours. We need a custom `tolower` that only does ASCII
67+
* characters and is locale-independent to remain truthy to the
68+
* standard
69+
*/
70+
#define tolower(c) gumbo_tolower(c)
6371
#include "tag_perf.h"
6472

6573
static int
6674
case_memcmp(const char *s1, const char *s2, int n)
6775
{
6876
while (n--) {
69-
unsigned char c1 = tolower(*s1++);
70-
unsigned char c2 = tolower(*s2++);
77+
unsigned char c1 = gumbo_tolower(*s1++);
78+
unsigned char c2 = gumbo_tolower(*s2++);
7179
if (c1 != c2)
7280
return (int)c1 - (int)c2;
7381
}

src/util.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ static inline void gumbo_free(void *ptr)
5757
gumbo_user_free(ptr);
5858
}
5959

60+
static inline int gumbo_tolower(int c)
61+
{
62+
return c | ((c >= 'A' && c <= 'Z') << 5);
63+
}
64+
6065
// Debug wrapper for printf, to make it easier to turn off debugging info when
6166
// required.
6267
void gumbo_debug(const char* format, ...);

0 commit comments

Comments
 (0)