improve fscript iformat

This commit is contained in:
lixianjing 2024-05-08 16:37:17 +08:00
parent c0f028f9b2
commit 02ca43bf84
4 changed files with 11 additions and 1 deletions

View File

@ -1,4 +1,7 @@
# 最新动态
2024/05/8
* 完善value_uint32(感谢华健提供补丁)
* 完善fscript iformat(感谢华健提供补丁)
2024/05/7
* 修复触摸点击edit子控件button弹出软键盘问题(感谢颖健提供补丁)

View File

@ -2677,7 +2677,8 @@ static ret_t func_iformat(fscript_t* fscript, fscript_args_t* args, value_t* res
format = value_str(args->args);
FSCRIPT_FUNC_CHECK(format != NULL, RET_BAD_PARAMS);
tk_snprintf(str->str, str->capacity - 1, format, value_int(args->args + 1));
tk_snprintf(str->str, str->capacity > FSCRIPT_STR_CAPACITY ? FSCRIPT_STR_CAPACITY - 1 : str->capacity - 1, format, value_int(args->args + 1));
value_dup_str(result, str->str);
return RET_OK;

View File

@ -158,6 +158,8 @@ uint32_t value_uint32(const value_t* v) {
if (v->type == VALUE_TYPE_UINT32) {
return v->value.u32;
} else if (v->type == VALUE_TYPE_STRING) {
return (uint32_t)tk_atoul(v->value.str);
} else {
return (uint32_t)value_int(v);
}

View File

@ -335,6 +335,10 @@ TEST(FScript, iformat) {
fscript_eval(obj, "iformat(\"hello:%d\", 123) + str(456)", &v);
ASSERT_STREQ(value_str(&v), "hello:123456");
value_reset(&v);
fscript_eval(obj, "iformat(\"aaaaabbbhello1234567890hello1234567890hello1234567890123456789012345:%d\",2147483647)", &v);
ASSERT_STREQ(value_str(&v), "aaaaabbbhello1234567890hello1234567890hello1234567890123456789");
value_reset(&v);
TK_OBJECT_UNREF(obj);
}