diff --git a/docs/changes.md b/docs/changes.md index 0e78b197b..4a7384cb0 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -1,4 +1,7 @@ # 最新动态 +2024/05/8 + * 完善value_uint32(感谢华健提供补丁) + * 完善fscript iformat(感谢华健提供补丁) 2024/05/7 * 修复触摸点击edit子控件button弹出软键盘问题(感谢颖健提供补丁) diff --git a/src/tkc/fscript.c b/src/tkc/fscript.c index f404e8ebf..b7a4dd610 100644 --- a/src/tkc/fscript.c +++ b/src/tkc/fscript.c @@ -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; diff --git a/src/tkc/value.c b/src/tkc/value.c index 487fbb186..ff58cf20c 100644 --- a/src/tkc/value.c +++ b/src/tkc/value.c @@ -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); } diff --git a/tests/fscript_test.cc b/tests/fscript_test.cc index 712709f51..da8d92fe0 100644 --- a/tests/fscript_test.cc +++ b/tests/fscript_test.cc @@ -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); }