add tk_int_is_in_array

This commit is contained in:
lixianjing 2024-05-24 11:25:46 +08:00
parent 8be70db48d
commit f7a1749144
4 changed files with 43 additions and 1 deletions

View File

@ -1,5 +1,9 @@
# 最新动态
2024/05/24
* 修复awtk-web编译错误。
* 增加函数tk\_int\_is\_in\_array
2024/05/17
* 修复拼写错误(感谢兆坤提供补丁)
* 修正查找下一个焦点控件时获取坐标的逻辑(感谢颖健提供补丁)

View File

@ -1283,6 +1283,19 @@ const char* tk_strrstr(const char* str, const char* substr) {
return NULL;
}
bool_t tk_int_is_in_array(int32_t v, const int32_t* array, uint32_t array_size) {
uint32_t i = 0;
return_value_if_fail(array != NULL && array_size > 0, FALSE);
for (i = 0; i < array_size; i++) {
if (v == array[i]) {
return TRUE;
}
}
return FALSE;
}
bool_t tk_str_is_in_array(const char* str, const char** str_array, uint32_t array_size) {
uint32_t i = 0;
return_value_if_fail(str != NULL && str_array != NULL && array_size > 0, FALSE);

View File

@ -887,6 +887,19 @@ ret_t tk_qsort(void** array, size_t nr, tk_compare_t cmp);
*/
bool_t tk_str_is_in_array(const char* str, const char** str_array, uint32_t array_size);
/**
* @method tk_int_is_in_array
*
*
*
* @param {int32_t} v
* @param {const int32_t*} array
* @param {uint32_t} array_size
*
* @return {bool_t} TRUE表示在
*/
bool_t tk_int_is_in_array(int32_t v, const int32_t* array, uint32_t array_size);
/**
* @method tk_memcpy
*

View File

@ -643,6 +643,18 @@ TEST(Utils, is_in_array) {
ASSERT_EQ(tk_str_is_in_array("123", arr3, ARRAY_SIZE(arr3)), TRUE);
}
TEST(Utils, int_is_in_array) {
int32_t arr1[] = {123};
int32_t arr2[] = {123, 200};
int32_t arr3[] = {100, 210, 123};
ASSERT_EQ(tk_int_is_in_array(123, arr1, ARRAY_SIZE(arr1)), TRUE);
ASSERT_EQ(tk_int_is_in_array(123, arr2, ARRAY_SIZE(arr2)), TRUE);
ASSERT_EQ(tk_int_is_in_array(123, arr3, ARRAY_SIZE(arr3)), TRUE);
ASSERT_EQ(tk_int_is_in_array(23, arr3, ARRAY_SIZE(arr1)), FALSE);
ASSERT_EQ(tk_int_is_in_array(23, arr3, ARRAY_SIZE(arr3)), FALSE);
}
TEST(Utils, memcpy_by_align_4) {
#define path_max_len 64
uint8_t path[path_max_len * 2] = {0};