Skip to content
This repository has been archived by the owner on Feb 15, 2023. It is now read-only.

Commit

Permalink
tags: Use an ASCII-only tolower function
Browse files Browse the repository at this point in the history
  • Loading branch information
vmg committed Feb 17, 2015
1 parent a87add3 commit 06e797e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// Author: jdtang@google.com (Jonathan Tang)

#include "gumbo.h"
#include "util.h"

#include <assert.h>
#include <ctype.h>
Expand Down Expand Up @@ -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;
}
Expand Down
5 changes: 5 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...);
Expand Down

0 comments on commit 06e797e

Please sign in to comment.