mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-11-29 18:48:09 +08:00
add tk_int_is_in_array
This commit is contained in:
parent
8be70db48d
commit
f7a1749144
@ -1,5 +1,9 @@
|
||||
# 最新动态
|
||||
|
||||
2024/05/24
|
||||
* 修复awtk-web编译错误。
|
||||
* 增加函数tk\_int\_is\_in\_array
|
||||
|
||||
2024/05/17
|
||||
* 修复拼写错误(感谢兆坤提供补丁)
|
||||
* 修正查找下一个焦点控件时获取坐标的逻辑(感谢颖健提供补丁)
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -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};
|
||||
@ -1842,4 +1854,4 @@ TEST(Utils, skip_to_chars) {
|
||||
ASSERT_STREQ(tk_skip_to_chars("abc123", ""), "");
|
||||
ASSERT_STREQ(tk_skip_to_chars("abc123", "A"), "");
|
||||
ASSERT_STREQ(tk_skip_to_chars("abc123", "a"), "abc123");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user