diff options
author | Nick Mathewson <nickm@torproject.org> | 2007-02-05 18:33:52 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2007-02-05 18:33:52 +0000 |
commit | f02be02356a6cedcec2b01d5046e5d5cba0797ad (patch) | |
tree | 1cb0b87b6d886fd4c5db5e8d14807d31b5a67828 /src/common/container.h | |
parent | 03ef2156c93523cb548ea20b41e554b939964c29 (diff) | |
download | tor-f02be02356a6cedcec2b01d5046e5d5cba0797ad.tar.gz tor-f02be02356a6cedcec2b01d5046e5d5cba0797ad.zip |
r11639@catbus: nickm | 2007-02-05 13:33:38 -0500
Add documentation to src/common/*.h; improve documentation for SMARTLIST_FOREACH; remove never-used options and corresponding tests from tor_strpartition.
svn:r9483
Diffstat (limited to 'src/common/container.h')
-rw-r--r-- | src/common/container.h | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/common/container.h b/src/common/container.h index 8fbc863cbb..2756fdeefe 100644 --- a/src/common/container.h +++ b/src/common/container.h @@ -113,7 +113,12 @@ char *smartlist_join_strings2(smartlist_t *sl, const char *join, /** Iterate over the items in a smartlist <b>sl</b>, in order. For each item, * assign it to a new local variable of type <b>type</b> named <b>var</b>, and * execute the statement <b>cmd</b>. Inside the loop, the loop index can - * be accessed as <b>var</b>_sl_idx. + * be accessed as <b>var</b>_sl_idx and the length of the list can be accessed + * as <b>var</b>_sl_len. + * + * NOTE: Do not change the length of the list while the loop is in progress, + * unless you adjust the _sl_len variable correspondingly. See second example + * below. * * Example use: * <pre> @@ -123,7 +128,20 @@ char *smartlist_join_strings2(smartlist_t *sl, const char *join, * printf("%d: %s\n", cp_sl_idx, cp); * tor_free(cp); * }); - * smarlitst_free(list); + * smartlist_free(list); + * </pre> + * + * Example use (advanced): + * <pre> + * SMARTLIST_FOREACH(list, char *, cp, + * { + * if (!strcmp(cp, "junk")) { + * smartlist_del(list, cp_sl_idx); + * tor_free(cp); + * --cp_sl_len; // decrement length of list so we don't run off the end + * --cp_sl_idx; // decrement idx so we consider the item that moved here + * } + * }); * </pre> */ #define SMARTLIST_FOREACH(sl, type, var, cmd) \ |