Skip to content

Replace stdlib calls: isxdigit -> iswxdigit, wcscmp -> memcmp #220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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