From 53ff9339624e7cd903d3e7e6bb1ef6730cbef8ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20K=C3=A4chele?= Date: Tue, 4 Nov 2025 12:47:48 +0100 Subject: [PATCH] Return hb_string in token_to_string function --- src/herb.c | 6 +++--- src/include/token.h | 3 ++- src/token.c | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/herb.c b/src/herb.c index a48a56f3a..4c6238a52 100644 --- a/src/herb.c +++ b/src/herb.c @@ -61,9 +61,9 @@ void herb_lex_to_buffer(const char* source, hb_buffer_T* output) { for (size_t i = 0; i < hb_array_size(tokens); i++) { token_T* token = hb_array_get(tokens, i); - char* type = token_to_string(token); - hb_buffer_append(output, type); - free(type); + hb_string_T type = token_to_string(token); + hb_buffer_append_string(output, type); + free(type.data); hb_buffer_append(output, "\n"); } diff --git a/src/include/token.h b/src/include/token.h index a91345865..0e7133afd 100644 --- a/src/include/token.h +++ b/src/include/token.h @@ -4,9 +4,10 @@ #include "lexer_struct.h" #include "position.h" #include "token_struct.h" +#include "util/hb_string.h" token_T* token_init(const char* value, token_type_T type, lexer_T* lexer); -char* token_to_string(const token_T* token); +hb_string_T token_to_string(const token_T* token); const char* token_type_to_string(token_type_T type); token_T* token_copy(token_T* token); diff --git a/src/token.c b/src/token.c index dd7b9a76f..157e64e04 100644 --- a/src/token.c +++ b/src/token.c @@ -83,7 +83,7 @@ const char* token_type_to_string(const token_type_T type) { return "Unknown token_type_T"; } -char* token_to_string(const token_T* token) { +hb_string_T token_to_string(const token_T* token) { const char* type_string = token_type_to_string(token->type); const char* template = "#"; @@ -112,7 +112,7 @@ char* token_to_string(const token_T* token) { free(escaped.data); - return string; + return hb_string(string); } token_T* token_copy(token_T* token) {