diff --git a/src/lib/eina/eina_list.c b/src/lib/eina/eina_list.c index e1088b0d33..6a73243335 100644 --- a/src/lib/eina/eina_list.c +++ b/src/lib/eina/eina_list.c @@ -1569,3 +1569,23 @@ eina_list_accessor_new(const Eina_List *list) return &ac->accessor; } + +EAPI int +eina_list_data_idx(const Eina_List *list, void *data) +{ + const Eina_List *l; + void *list_data; + int ret = 0; + + if (!list) return -1; + EINA_MAGIC_CHECK_LIST(list, -1); + + EINA_LIST_FOREACH(list, l, list_data) + { + if (list_data == data) + return ret; + ret++; + } + + return -1; +} diff --git a/src/lib/eina/eina_list.h b/src/lib/eina/eina_list.h index 91de6ea08c..9d3bb90310 100644 --- a/src/lib/eina/eina_list.h +++ b/src/lib/eina/eina_list.h @@ -1344,6 +1344,22 @@ EAPI Eina_Iterator *eina_list_iterator_reversed_new(const Eina_List *list */ EAPI Eina_Accessor *eina_list_accessor_new(const Eina_List *list) EINA_MALLOC EINA_WARN_UNUSED_RESULT; +/** + * @brief Find the member of the list and return the index. + * + * @param list The list. + * @param data The data member. + * @return The index of data member if found, @c -1 otherwise. + * + * This function searches in @p list from beginning to end for the + * first member whose data pointer is @p data. If it is found, the + * index of the data will be returned, otherwise @c -1 will be returned. + * + * @warning @p list must be a pointer to the first element of the list. + * + */ +EAPI int eina_list_data_idx(const Eina_List *list, void *data); + /** * @def EINA_LIST_FOREACH * @brief Macro to iterate over a list.