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).
* 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[])
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,
* @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:
* {
* // Only dump out num nodes.
* if (*(num--) == 0)
- * return true;
+ * return false;
* printf("%s=>%i\n", member, *value);
- * return false;
+ * return true;
* }
*
* static void dump_map(const struct strmap_intp *map)
ok1(i == atoi(value));
ok1(*count == i);
(*count)++;
- return false;
+ return true;
}
static bool in_order_by_2(const char *member, char *value, unsigned int *count)
ok1(i == atoi(value));
ok1(*count == i);
(*count) += 2;
- return false;
+ return true;
}
static bool dump(const char *member, char *value, bool *ok)
diag("%s=>%s", member, value);
if (value != member + 1)
*ok = false;
- return false;
+ return true;
}
int main(void)
ok1(i == atoi(value));
ok1(*count == i);
(*count)++;
- return false;
+ return true;
}
static bool find_empty(const char *index, char *value, char *empty)
{
if (index == empty)
pass("Found empty entry!");
- return false;
+ return true;
}
int main(void)
* static bool dump(const char *member, void *unused)
* {
* printf("%s ", member);
- * return false;
+ * return true; // Keep going with iteration.
* }
*
* int main(void)
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,
* @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)
- * return true;
+ * return false;
* printf("%s\n", member);
- * return false;
+ * return true;
* }
*
* static void dump_set(const struct strset *set)
encode(template, *count);
ok1(streq(value, template));
(*count)++;
- return false;
+ return true;
}
static bool in_order_by_2(const char *value, unsigned int *count)
encode(template, *count);
ok1(streq(value, template));
(*count) += 2;
- return false;
+ return true;
}
static bool dump(const char *value, void *unused)
{
diag("%s", value);
- return false;
+ return true;
}
int main(void)
{
if (strcmp(str, cmp) == 0)
found = true;
- return false;
+ return true;
}
int main(void)
int i = atoi(value);
ok1(*count == i);
(*count)++;
- return false;
+ return true;
}
static bool in_order_by_2(const char *value, unsigned int *count)
int i = atoi(value);
ok1(*count == i);
(*count) += 2;
- return false;
+ return true;
}
static bool dump(const char *value, void *unused)
{
diag("%s", value);
- return false;
+ return true;
}
int main(void)
int i = atoi(value);
ok1(*count == i);
(*count)++;
- return false;
+ return true;
}
static bool find_empty(const char *value, char *empty)
{
if (value == empty)
pass("Found empty entry!");
- return false;
+ return true;
}
int main(void)