Added function to copy tokens

This essentially just copies the internal string of the token into a
new buffer.
This commit is contained in:
2023-11-29 15:38:57 +00:00
parent 1cba5ccd8d
commit ac70d4031c
2 changed files with 11 additions and 0 deletions

View File

@@ -130,6 +130,15 @@ const char *lerr_as_cstr(lerr_t lerr)
return "";
}
token_t token_copy(token_t t)
{
token_t new = t;
new.str = malloc(t.str_size + 1);
memcpy(new.str, t.str, t.str_size);
new.str[t.str_size] = '\0';
return new;
}
size_t space_left(buffer_t *buffer)
{
if (buffer->available == buffer->used)

View File

@@ -71,6 +71,8 @@ typedef struct
size_t str_size;
} token_t;
token_t token_copy(token_t);
typedef enum
{
LERR_OK = 0,