add wstr_clear

This commit is contained in:
xianjimli 2019-01-30 17:32:21 +08:00
parent 3c7bc10bd9
commit 8bb03759f5
2 changed files with 19 additions and 0 deletions

View File

@ -139,6 +139,16 @@ ret_t wstr_set(wstr_t* str, const wchar_t* text) {
return RET_OK;
}
ret_t wstr_clear(wstr_t* str) {
return_value_if_fail(str != NULL, RET_BAD_PARAMS);
str->size = 0;
if (str->str != NULL) {
str->str[0] = '\0';
}
return RET_OK;
}
ret_t wstr_set_utf8(wstr_t* str, const char* text) {
return_value_if_fail(str != NULL && text != NULL, RET_BAD_PARAMS);
return_value_if_fail(wstr_extend(str, strlen(text) + 2) == RET_OK, RET_OOM);

View File

@ -87,6 +87,15 @@ wstr_t* wstr_init(wstr_t* str, uint32_t capacity);
*/
ret_t wstr_set(wstr_t* str, const wchar_t* text);
/**
* @method wstr_clear
*
* @param {wstr_t*} str str对象
*
* @return {ret_t} RET_OK表示成功
*/
ret_t wstr_clear(wstr_t* str);
/**
* @method wstr_set_utf8
* UTF8字符串