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:
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user