Make a false return abort the iteration, not true.
The old way makes sense for search functions (true == I found it), but
other kinds of iteration are more common (brute force search is
probably dumb).
12 files changed:
* static bool dump(const char *member, size_t value, void *unused)
* {
* printf("%s at %zu. ", member, value);
* static bool dump(const char *member, size_t value, void *unused)
* {
* printf("%s at %zu. ", member, value);
- * // false means keep going with iteration.
- * return false;
+ * // true means keep going with iteration.
+ * return true;
* }
*
* int main(int argc, char *argv[])
* }
*
* int main(int argc, char *argv[])
return handle(n.u.s, n.v, (void *)data);
return iterate(n.u.n->child[0], handle, data)
return handle(n.u.s, n.v, (void *)data);
return iterate(n.u.n->child[0], handle, data)
- || iterate(n.u.n->child[1], handle, data);
+ && iterate(n.u.n->child[1], handle, data);
}
void strmap_iterate_(const struct strmap *map,
}
void strmap_iterate_(const struct strmap *map,
* @handle's prototype should be:
* bool @handle(const char *member, type value, typeof(arg) arg)
*
* @handle's prototype should be:
* bool @handle(const char *member, type value, typeof(arg) arg)
*
- * If @handle returns true, the iteration will stop.
+ * If @handle returns false, the iteration will stop.
* You should not alter the map within the @handle function!
*
* Example:
* You should not alter the map within the @handle function!
*
* Example:
* {
* // Only dump out num nodes.
* if (*(num--) == 0)
* {
* // Only dump out num nodes.
* if (*(num--) == 0)
* printf("%s=>%i\n", member, *value);
* printf("%s=>%i\n", member, *value);
* }
*
* static void dump_map(const struct strmap_intp *map)
* }
*
* static void dump_map(const struct strmap_intp *map)
ok1(i == atoi(value));
ok1(*count == i);
(*count)++;
ok1(i == atoi(value));
ok1(*count == i);
(*count)++;
}
static bool in_order_by_2(const char *member, char *value, unsigned int *count)
}
static bool in_order_by_2(const char *member, char *value, unsigned int *count)
ok1(i == atoi(value));
ok1(*count == i);
(*count) += 2;
ok1(i == atoi(value));
ok1(*count == i);
(*count) += 2;
}
static bool dump(const char *member, char *value, bool *ok)
}
static bool dump(const char *member, char *value, bool *ok)
diag("%s=>%s", member, value);
if (value != member + 1)
*ok = false;
diag("%s=>%s", member, value);
if (value != member + 1)
*ok = false;
ok1(i == atoi(value));
ok1(*count == i);
(*count)++;
ok1(i == atoi(value));
ok1(*count == i);
(*count)++;
}
static bool find_empty(const char *index, char *value, char *empty)
{
if (index == empty)
pass("Found empty entry!");
}
static bool find_empty(const char *index, char *value, char *empty)
{
if (index == empty)
pass("Found empty entry!");
* static bool dump(const char *member, void *unused)
* {
* printf("%s ", member);
* static bool dump(const char *member, void *unused)
* {
* printf("%s ", member);
+ * return true; // Keep going with iteration.
return handle(n.u.n->child[0].u.s, (void *)data);
return iterate(n.u.n->child[0], handle, data)
return handle(n.u.n->child[0].u.s, (void *)data);
return iterate(n.u.n->child[0], handle, data)
- || iterate(n.u.n->child[1], handle, data);
+ && iterate(n.u.n->child[1], handle, data);
}
void strset_iterate_(const struct strset *set,
}
void strset_iterate_(const struct strset *set,
* @arg: the argument for the function (types should match).
*
* You should not alter the set within the @handle function! If it returns
* @arg: the argument for the function (types should match).
*
* You should not alter the set within the @handle function! If it returns
- * true, the iteration will stop.
+ * false, the iteration will stop.
*
* Example:
* static bool dump_some(const char *member, int *num)
* {
* // Only dump out num nodes.
* if (*(num--) == 0)
*
* Example:
* static bool dump_some(const char *member, int *num)
* {
* // Only dump out num nodes.
* if (*(num--) == 0)
* printf("%s\n", member);
* printf("%s\n", member);
* }
*
* static void dump_set(const struct strset *set)
* }
*
* static void dump_set(const struct strset *set)
encode(template, *count);
ok1(streq(value, template));
(*count)++;
encode(template, *count);
ok1(streq(value, template));
(*count)++;
}
static bool in_order_by_2(const char *value, unsigned int *count)
}
static bool in_order_by_2(const char *value, unsigned int *count)
encode(template, *count);
ok1(streq(value, template));
(*count) += 2;
encode(template, *count);
ok1(streq(value, template));
(*count) += 2;
}
static bool dump(const char *value, void *unused)
{
diag("%s", value);
}
static bool dump(const char *value, void *unused)
{
diag("%s", value);
{
if (strcmp(str, cmp) == 0)
found = true;
{
if (strcmp(str, cmp) == 0)
found = true;
int i = atoi(value);
ok1(*count == i);
(*count)++;
int i = atoi(value);
ok1(*count == i);
(*count)++;
}
static bool in_order_by_2(const char *value, unsigned int *count)
}
static bool in_order_by_2(const char *value, unsigned int *count)
int i = atoi(value);
ok1(*count == i);
(*count) += 2;
int i = atoi(value);
ok1(*count == i);
(*count) += 2;
}
static bool dump(const char *value, void *unused)
{
diag("%s", value);
}
static bool dump(const char *value, void *unused)
{
diag("%s", value);
int i = atoi(value);
ok1(*count == i);
(*count)++;
int i = atoi(value);
ok1(*count == i);
(*count)++;
}
static bool find_empty(const char *value, char *empty)
{
if (value == empty)
pass("Found empty entry!");
}
static bool find_empty(const char *value, char *empty)
{
if (value == empty)
pass("Found empty entry!");