1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-26 21:06:38 +02:00

core: add function hdata_count

This commit is contained in:
Sébastien Helleu
2024-06-11 10:15:03 +02:00
parent 24e023d467
commit 8945b7bf33
3 changed files with 37 additions and 0 deletions
+21
View File
@@ -656,6 +656,27 @@ end:
return ret_pointer;
}
/*
* Returns number of item in this hdata, starting at "pointer".
*/
int
hdata_count (struct t_hdata *hdata, void *pointer)
{
int count;
if (!hdata || !pointer)
return 0;
count = 0;
while (pointer)
{
count++;
pointer = hdata_move (hdata, pointer, 1);
}
return count;
}
/*
* Extracts index from name of a variable.
*
+1
View File
@@ -122,6 +122,7 @@ extern void *hdata_search (struct t_hdata *hdata, void *pointer,
const char *search, struct t_hashtable *pointers,
struct t_hashtable *extra_vars,
struct t_hashtable *options, int move);
extern int hdata_count (struct t_hdata *hdata, void *pointer);
extern void hdata_get_index_and_name (const char *name, int *index,
const char **ptr_name);
extern char hdata_char (struct t_hdata *hdata, void *pointer,
+15
View File
@@ -1728,6 +1728,21 @@ TEST(CoreHdataWithList, Search)
hashtable_free (extra_vars);
}
/*
* Tests functions:
* hdata_count
*/
TEST(CoreHdataWithList, Count)
{
LONGS_EQUAL(0, hdata_count (NULL, NULL));
LONGS_EQUAL(0, hdata_count (ptr_hdata, NULL));
LONGS_EQUAL(0, hdata_count (NULL, items));
LONGS_EQUAL(2, hdata_count (ptr_hdata, items));
LONGS_EQUAL(1, hdata_count (ptr_hdata, ptr_item2));
}
/*
* Tests functions:
* hdata_get_index_and_name