summaryrefslogtreecommitdiffstats
path: root/src/lex.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lex.cpp')
-rw-r--r--src/lex.cpp24
1 files changed, 7 insertions, 17 deletions
diff --git a/src/lex.cpp b/src/lex.cpp
index c5ae330..3746c91 100644
--- a/src/lex.cpp
+++ b/src/lex.cpp
@@ -135,7 +135,6 @@ int lex_t::consume_comment(parse_token_value_t *value) {
return -1;
}
-/*
int lex_t::unterminated_string(parse_token_value_t *value) {
if (ferror(file))
return io_error(value);
@@ -145,18 +144,14 @@ int lex_t::unterminated_string(parse_token_value_t *value) {
}
int lex_t::lex_string(parse_token_value_t *value) {
- char *buf = NULL;
- size_t len = 1024;
- size_t pos = 0;
-
if (needspace)
return syntax_error(value);
- buf = static_cast<char*>(std::malloc(len));
+ std::string *buf = new std::string;
while (true) {
if (!next(true)) {
- std::free(buf);
+ delete buf;
return unterminated_string(value);
}
@@ -177,16 +172,10 @@ int lex_t::lex_string(parse_token_value_t *value) {
continue;
}
- if (pos >= len) {
- len *= 2;
- buf = static_cast<char*>(std::realloc(buf, len));
- }
-
- buf[pos++] = cur;
+ *buf += cur;
}
- value->str = strndup(buf, pos);
- std::free(buf);
+ value->str = buf;
next(true);
consume(true);
@@ -194,6 +183,7 @@ int lex_t::lex_string(parse_token_value_t *value) {
return TOK_STRING;
}
+/*
int lex_t::lex_number(parse_token_value_t *value) {
if (needspace)
return syntax_error(value);
@@ -431,8 +421,8 @@ int lex_t::lex(parse_token_value_t *value) {
case '{':
return lex_block(value);
- //case '"':
- //return lex_string(value);
+ case '"':
+ return lex_string(value);
//case '0' ... '9':
//return lex_number(value);