diff options
author | Nico von Geyso <Nico.Geyso@FU-Berlin.de> | 2013-03-17 23:39:01 +0400 |
---|---|---|
committer | Carlos MartÃn Nieto <cmn@dwim.me> | 2013-08-08 13:07:03 +0400 |
commit | 6385fc5ff5d669d3ec99d89f19c5860cf53011ba (patch) | |
tree | 56dfda0bba992c09c7d336600f1844b95d0ae863 /src/strmap.c | |
parent | c7d4904c47d493073b8f816d2b17dcf68eefe26d (diff) |
added new type and several functions to git_strmap
This step is needed to easily add iterators to git_config_backend
As well use these new git_strmap functions to implement foreach
* git_strmap_iter
* git_strmap_has_data(...)
* git_strmap_begin(...)
* git_strmap_end(...)
* git_strmap_next(...)
Diffstat (limited to 'src/strmap.c')
-rw-r--r-- | src/strmap.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/strmap.c b/src/strmap.c new file mode 100644 index 000000000..1b07359d1 --- /dev/null +++ b/src/strmap.c @@ -0,0 +1,34 @@ +/* + * Copyright (C) the libgit2 contributors. All rights reserved. + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ + +#include "strmap.h" + +int git_strmap_next( + const char **key, + void **data, + git_strmap_iter* iter, + git_strmap *map) +{ + if (!map) + return GIT_ERROR; + + while (*iter != git_strmap_end(map)) { + if (!(git_strmap_has_data(map, *iter))) { + ++(*iter); + continue; + } + + *key = git_strmap_key(map, *iter); + *data = git_strmap_value_at(map, *iter); + + ++(*iter); + + return GIT_OK; + } + + return GIT_ITEROVER; +} |