all repos — hex @ aa6d983f87b0602a80fbcc530917b2c8572073fe

A tiny, minimalist, slightly-esoteric concatenative programming lannguage.

Improved string handling.
h3rald h3rald@h3rald.com
Wed, 20 Nov 2024 16:58:56 +0100
commit

aa6d983f87b0602a80fbcc530917b2c8572073fe

parent

3cea92f9abf820e9d35830782ea2e02854c20b63

1 files changed, 9 insertions(+), 3 deletions(-)

jump to
M hex.chex.c

@@ -289,14 +289,14 @@ HEX_StackElement element = {.type = HEX_TYPE_INTEGER, .data.intValue = value};

return hex_push(element); } -int hex_push_string(const char *value) +char *hex_process_string(const char *value) { size_t len = strlen(value); char *processedStr = (char *)malloc(len + 1); if (!processedStr) { hex_error("Memory allocation failed"); - return 1; + return (char *)value; } char *dst = processedStr;

@@ -345,7 +345,12 @@ }

src++; } *dst = '\0'; + return processedStr; +} +int hex_push_string(const char *value) +{ + char *processedStr = hex_process_string(value); HEX_StackElement element = {.type = HEX_TYPE_STRING, .data.strValue = processedStr}; return hex_push(element); }

@@ -717,8 +722,9 @@ element->data.intValue = (int)strtol(token->value, NULL, 16);

} else if (token->type == HEX_TOKEN_STRING) { + char *processedStr = hex_process_string(token->value); element->type = HEX_TYPE_STRING; - element->data.strValue = strdup(token->value); + element->data.strValue = strdup(processedStr); } else if (token->type == HEX_TOKEN_SYMBOL) {