diff options
Diffstat (limited to 'src/lex.cpp')
-rw-r--r-- | src/lex.cpp | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/src/lex.cpp b/src/lex.cpp index 38d138c..63549c9 100644 --- a/src/lex.cpp +++ b/src/lex.cpp @@ -234,10 +234,10 @@ int lex_t::lex_keyword(parser_value_t *value) { break; } - char *token = get_token(); - const keyword_t key = { .keyword = token, .token = 0 }; + std::string *token = get_token(); + const keyword_t key = { .keyword = token->c_str(), .token = 0 }; const keyword_t *ret = static_cast<const keyword_t*>(bsearch(&key, keywords, array_size(keywords), sizeof(keyword_t), compare_keywords)); - free(token); + delete token; if (!ret) return syntax_error(value); @@ -262,15 +262,13 @@ int lex_t::lex_block(parser_value_t *value) { bool str = false; bool pp = false; - size_t pos = 0; - size_t len = 1024; - char *buf = static_cast<char*>(std::malloc(len)); + std::string *buf = new std::string; char prev = 0; while (true) { if (!next(true)) { - std::free(buf); + delete buf; return unterminated_block(value); } @@ -316,17 +314,11 @@ int lex_t::lex_block(parser_value_t *value) { } } - if (pos >= len) { - len *= 2; - buf = static_cast<char*>(std::realloc(buf, len)); - } - - buf[pos++] = cur; + *buf += cur; prev = cur; } - value->str = strndup(buf, pos); - std::free(buf); + value->str = buf; next(true); consume(true); |