From 8c561b86372f517b3d6ac9137f09a94f6d2425da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Thu, 31 May 2012 16:36:43 +0200 Subject: Particle : add eiotas_particle_link_fields_set --- src/include/eiotas_particle.h | 9 +++++++++ src/lib/eiotas_particle.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/include/eiotas_particle.h b/src/include/eiotas_particle.h index e6fdedf..34b59ed 100644 --- a/src/include/eiotas_particle.h +++ b/src/include/eiotas_particle.h @@ -107,6 +107,15 @@ EAPI void eiotas_particle_merge(Eiotas_Particle *particle, const Eiotas_Particle EAPI void eiotas_particle_destinations_add(Eiotas_Particle *particle, const char *destinations); /** + * @brief Set the link fields + * + * @param particle The @ref Eiotas_Particle to set the link fields to + * @param link_fields A comma separated list of fields name + * + */ +EAPI void eiotas_particle_link_fields_set(Eiotas_Particle *particle, const char *link_fields); + +/** * @} */ diff --git a/src/lib/eiotas_particle.c b/src/lib/eiotas_particle.c index 7f45848..a2252bd 100644 --- a/src/lib/eiotas_particle.c +++ b/src/lib/eiotas_particle.c @@ -116,6 +116,37 @@ EAPI void eiotas_particle_destinations_add(Eiotas_Particle *particle, const char } } +EAPI void eiotas_particle_link_fields_set(Eiotas_Particle *particle, const char *link_fields) +{ + int n; + unsigned int i; + Eina_Stringshare *s; + Eina_Array_Iterator it; + char *field, *sep; + + EINA_ARRAY_ITER_NEXT(particle->link_fields, i, s, it) eina_stringshare_del(s); + eina_array_clean(particle->link_fields); + + field = (char*)link_fields; + for(; *field;) { + for(; *field==' '; field++) /* eat leading spaces */; + sep = field; + for(; (*sep && *sep!=EIOTAS_FIELDS_SEP && *sep!=' '); sep++) /* search field end */; + n = (sep-field); + if(n==0) { + ERR("ignore empty field"); + } else { + s = eina_stringshare_add_length(field,n); + eina_array_push(particle->link_fields,s); + DBG("add field >%s<",s); + } + for(; (*sep && *sep!=EIOTAS_FIELDS_SEP); sep++) /* eat whatever following */; + if(!*sep) return; + field = sep+1; + } + update_link_value(particle,NULL); +} + static void update_link_value(Eiotas_Particle *particle, const char *field) { unsigned int i; -- cgit v1.1-2-g2b99