Skip to content

Commit

Permalink
Replace stdlib calls: isxdigit -> iswxdigit, wcscmp -> memcmp
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbrunsfeld authored and amaanq committed Feb 5, 2024
1 parent cf1f4a0 commit 5ceb923
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions common/scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ static String string_new() {
return (String){.cap = 16, .len = 0, .data = calloc(17, sizeof(wchar_t))};
}

static inline bool string_eq(String *self, String *other) {
if (self->len != other->len) {
return false;
}
return memcmp(self->data, other->data, self->len * sizeof(self->data[0])) == 0;
}

typedef struct {
String word;
bool end_word_indentation_allowed;
Expand Down Expand Up @@ -204,7 +211,7 @@ static inline bool is_escapable_sequence(TSLexer *lexer) {
// Hex
if (letter == 'x') {
advance(lexer);
return isxdigit(lexer->lookahead);
return iswxdigit(lexer->lookahead);
}

// Unicode
Expand Down Expand Up @@ -506,7 +513,7 @@ static bool scan(Scanner *scanner, TSLexer *lexer, const bool *valid_symbols) {
}

String word = scan_heredoc_word(lexer);
if (wcscmp(word.data, heredoc.word.data) != 0) {
if (!string_eq(&word, &heredoc.word)) {
STRING_FREE(word);
return false;
}
Expand Down

0 comments on commit 5ceb923

Please sign in to comment.