Fix parsing last line without CRLF/LF.
Check EOF at the end of the buffer.
This commit is contained in:
@@ -381,6 +381,7 @@ bool ModelsList::loadYaml()
|
|||||||
if (bytes_read == 0)
|
if (bytes_read == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
if (f_eof(&file)) yp.set_eof();
|
||||||
if (yp.parse(line, bytes_read) != YamlParser::CONTINUE_PARSING)
|
if (yp.parse(line, bytes_read) != YamlParser::CONTINUE_PARSING)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ const char * readYamlFile(const char* fullpath, const YamlParserCalls* calls, vo
|
|||||||
if (bytes_read == 0)
|
if (bytes_read == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
if (f_eof(&file)) yp.set_eof();
|
||||||
if (yp.parse(buffer, bytes_read) != YamlParser::CONTINUE_PARSING)
|
if (yp.parse(buffer, bytes_read) != YamlParser::CONTINUE_PARSING)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ void YamlParser::init(const YamlParserCalls* parser_calls, void* parser_ctx)
|
|||||||
calls = parser_calls;
|
calls = parser_calls;
|
||||||
ctx = parser_ctx;
|
ctx = parser_ctx;
|
||||||
reset();
|
reset();
|
||||||
|
eof = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void YamlParser::reset()
|
void YamlParser::reset()
|
||||||
@@ -311,6 +312,11 @@ YamlParser::parse(const char* buffer, unsigned int size)
|
|||||||
c++;
|
c++;
|
||||||
} // for each char
|
} // for each char
|
||||||
|
|
||||||
|
if ((state == ps_Val) && eof && node_found) {
|
||||||
|
// TODO: trim spaces at the end?
|
||||||
|
calls->set_attr(ctx, scratch_buf, scratch_len);
|
||||||
|
}
|
||||||
|
|
||||||
return CONTINUE_PARSING;
|
return CONTINUE_PARSING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ class YamlParser
|
|||||||
uint8_t scratch_len;
|
uint8_t scratch_len;
|
||||||
|
|
||||||
bool node_found;
|
bool node_found;
|
||||||
|
bool eof;
|
||||||
|
|
||||||
// tree iterator state
|
// tree iterator state
|
||||||
const YamlParserCalls* calls;
|
const YamlParserCalls* calls;
|
||||||
@@ -98,6 +99,8 @@ public:
|
|||||||
void init(const YamlParserCalls* parser_calls, void* parser_ctx);
|
void init(const YamlParserCalls* parser_calls, void* parser_ctx);
|
||||||
|
|
||||||
YamlResult parse(const char* buffer, unsigned int size);
|
YamlResult parse(const char* buffer, unsigned int size);
|
||||||
|
|
||||||
|
void set_eof() { eof = true; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user