harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 3dcddd8019a5a6230e68b8c74defad5ea82d9017
parent b5cfc7cacdf8dbd022ca022a7094c489fbd7ae8c
Author: Sebastian <sebastian@sebsite.pw>
Date:   Sat,  9 Apr 2022 15:00:01 -0400

utf8: s/character/codepoint/g

This also changes the names of some utf8 functions to be more accurate.

Signed-off-by: Sebastian <sebastian@sebsite.pw>

Diffstat:
Minclude/utf8.h | 14+++++++-------
Msrc/lex.c | 6+++---
Msrc/utf8.c | 4++--
3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/include/utf8.h b/include/utf8.h @@ -8,28 +8,28 @@ #define UTF8_INVALID 0x80 /** - * Grabs the next UTF-8 character and advances the string pointer + * Grabs the next UTF-8 codepoint and advances the string pointer */ uint32_t utf8_decode(const char **str); /** - * Encodes a character as UTF-8 and returns the length of that character. + * Encodes a codepoint as UTF-8 and returns the length of that codepoint. */ size_t utf8_encode(char *str, uint32_t ch); /** - * Returns the size of the next UTF-8 character + * Returns the size of the next UTF-8 codepoint */ int utf8_size(const char *str); /** - * Returns the size of a UTF-8 character + * Returns the size of a UTF-8 codepoint */ -size_t utf8_chsize(uint32_t ch); +size_t utf8_cpsize(uint32_t ch); /** - * Reads and returns the next character from the file. + * Reads and returns the next codepoint from the file. */ -uint32_t utf8_fgetch(FILE *f); +uint32_t utf8_get(FILE *f); #endif diff --git a/src/lex.c b/src/lex.c @@ -179,7 +179,7 @@ next(struct lexer *lexer, struct location *loc, bool buffer) lexer->c[0] = lexer->c[1]; lexer->c[1] = UINT32_MAX; } else { - c = utf8_fgetch(lexer->in); + c = utf8_get(lexer->in); update_lineno(&lexer->loc, c); } if (loc != NULL) { @@ -193,7 +193,7 @@ next(struct lexer *lexer, struct location *loc, bool buffer) if (c == UTF8_INVALID || !buffer) { return c; } - if (lexer->buflen + utf8_chsize(c) >= lexer->bufsz) { + if (lexer->buflen + utf8_cpsize(c) >= lexer->bufsz) { lexer->bufsz *= 2; lexer->buf = xrealloc(lexer->buf, lexer->bufsz); } @@ -1062,7 +1062,7 @@ rune_unparse(uint32_t c) } else if (!isprint(c)) { snprintf(buf, sizeof(buf), "\\x%02x", c); } else { - assert(utf8_chsize(c) < sizeof(buf)); + assert(utf8_cpsize(c) < sizeof(buf)); buf[utf8_encode(buf, c)] = '\0'; } break; diff --git a/src/utf8.c b/src/utf8.c @@ -26,7 +26,7 @@ struct { }; size_t -utf8_chsize(uint32_t ch) +utf8_cpsize(uint32_t ch) { if (ch < 0x80) { return 1; @@ -108,7 +108,7 @@ utf8_size(const char *s) } uint32_t -utf8_fgetch(FILE *f) +utf8_get(FILE *f) { char buffer[UTF8_MAX_SIZE]; int c = fgetc(f);