fix init when value is empty

This commit is contained in:
lixianjing 2021-02-20 12:08:18 +08:00
parent 075f060271
commit 159b7675ce
3 changed files with 21 additions and 2 deletions

View File

@ -2,6 +2,7 @@
2021/02/20
* 完善编译脚本(感谢雨欣提供补丁)
* 修复ini的值为空的问题。
2021/02/19
* fscript支持return语句。

View File

@ -126,10 +126,15 @@ conf_doc_t* conf_doc_load_ini(const char* data) {
break;
}
case STATE_BEFORE_VALUE: {
if (!isspace(c)) {
if (c != ' ' && c != '\t') {
state = STATE_VALUE;
if (c == '\r' || c == '\n') {
str_set(s, "");
p -= 1;
} else {
str_set_with_len(s, &c, 1);
}
}
break;
}

View File

@ -302,6 +302,19 @@ TEST(Ini, last_first) {
conf_doc_destroy(doc);
}
TEST(Ini, empty) {
value_t v;
conf_doc_t* doc = conf_doc_load_ini("[hello]\na=\nb=2\nc=3\n");
ASSERT_EQ(conf_doc_get(doc, "hello.a", &v), RET_OK);
ASSERT_STREQ(value_str(&v), "");
ASSERT_EQ(conf_doc_get(doc, "hello.b", &v), RET_OK);
ASSERT_STREQ(value_str(&v), "2");
ASSERT_EQ(conf_doc_get(doc, "hello.c", &v), RET_OK);
ASSERT_STREQ(value_str(&v), "3");
conf_doc_destroy(doc);
}
TEST(Ini, move_up) {
value_t v;
conf_doc_t* doc = conf_doc_load_ini("[hello]\n[ world ]\n[awtk]\nname=aaa\n");