diff options
-rw-r--r-- | src/token.cc | 19 |
1 files changed, 3 insertions, 16 deletions
diff --git a/src/token.cc b/src/token.cc index 6e6a3a8..ff59123 100644 --- a/src/token.cc +++ b/src/token.cc @@ -15,23 +15,10 @@ Token::init(token_type_e type, char *lexeme, unsigned int line) char * Token::to_string(void) { - unsigned int line_length = snprintf(NULL, 0, "%ul", m_line) - 1; - unsigned int token_type_length = strlen(TOKEN_STRING[m_type]); + if (m_string == NULL) + asprintf(&m_string, "%d: %s - %s", m_line, TOKEN_STRING[m_type], m_lexeme); - unsigned int final_size - = line_length + 2 + token_type_length + 3 + strlen(m_lexeme) + 1; - - char *result = (char *) calloc(1, final_size); - snprintf(result, - final_size, - "%d: %s - %s", - m_line, - TOKEN_STRING[m_type], - m_lexeme); - - m_string = result; - - return result; + return m_string; } void |