From 00f3bc3b9d4e74d089a76d1a31f74f3a4207b541 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sat, 2 Jun 2012 19:08:53 +0200 Subject: add eiotas_particle_destination_set and tests --- src/include/eiotas_particle.h | 8 ++++++++ src/lib/eiotas_particle.c | 12 ++++++++++++ tests/particle.c | 11 +++++++++++ 3 files changed, 31 insertions(+) diff --git a/src/include/eiotas_particle.h b/src/include/eiotas_particle.h index 12026d8..ca8cc8e 100644 --- a/src/include/eiotas_particle.h +++ b/src/include/eiotas_particle.h @@ -127,6 +127,14 @@ EAPI Eina_Bool eiotas_particle_next_dst(Eiotas_Particle *particle); EAPI void eiotas_particle_split_dst(Eiotas_Particle *particle); /** + * @brief Add a destination and set it as current + * + * @param particle The @ref Eiotas_Particle to add destination to + * @param destination The destination to add and set as current + */ +EAPI void eiotas_particle_destination_set(Eiotas_Particle *particle, const char *destination); + +/** * @brief Add destinations to the @ref Eiotas_Particle * * @param particle The @ref Eiotas_Particle to add destinations to diff --git a/src/lib/eiotas_particle.c b/src/lib/eiotas_particle.c index f29eeda..5f67ad7 100644 --- a/src/lib/eiotas_particle.c +++ b/src/lib/eiotas_particle.c @@ -185,6 +185,18 @@ EAPI void eiotas_particle_split_dst(Eiotas_Particle *particle) } } +EAPI void eiotas_particle_destination_set(Eiotas_Particle *particle, const char *destination) +{ + char *dst, *sep; + + dst = (char*)destination; + for(; *dst==' '; dst++) /* eat leading spaces */; + sep = dst; + for(; (*sep && *sep!=' '); sep++) /* search destination end */; + add_destination(particle,dst,(sep-dst)); + particle->cur_dst = eina_array_count_get(particle->dsts)-1; +} + EAPI void eiotas_particle_destinations_add(Eiotas_Particle *particle, const char* destinations) { char *dst, *sep; diff --git a/tests/particle.c b/tests/particle.c index 199df27..60837ac 100644 --- a/tests/particle.c +++ b/tests/particle.c @@ -134,6 +134,17 @@ void test_particle() check_str((char*)p2->cur_room,"room/room","room is wrong"); p3 = eiotas_require_particle(dom0); + eiotas_particle_destinations_add(p3,"dom0/room0/room1/doorx?get,door?get,dom0/room0/door0?get"); + eiotas_particle_split_dst(p3); + check_str((char*)p3->cur_action,"get","action is wrong"); + check_str((char*)p3->cur_door,"doorx","door is wrong"); + check_str((char*)p3->cur_room,"dom0/room0/room1","room is wrong"); + eiotas_particle_destination_set(p3," room/door?got nothing else matters "); + eiotas_particle_split_dst(p3); + check_str((char*)p3->cur_action,"got","action is wrong"); + check_str((char*)p3->cur_door,"door","door is wrong"); + check_str((char*)p3->cur_room,"room","room is wrong"); + p4 = eiotas_require_particle(dom0); eiotas_particle_merge(p0,p1); eiotas_particle_merge(p0,p2); -- cgit v1.1-2-g2b99