Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
140cd169
Commit
140cd169
authored
Dec 01, 2011
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
strmap: allow const arguments to strset_iterate().
parent
932aeb6d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
5 deletions
+39
-5
ccan/strmap/strmap.c
ccan/strmap/strmap.c
+5
-3
ccan/strmap/strmap.h
ccan/strmap/strmap.h
+2
-2
ccan/strmap/test/run-iterate-const.c
ccan/strmap/test/run-iterate-const.c
+32
-0
No files found.
ccan/strmap/strmap.c
View file @
140cd169
...
...
@@ -174,17 +174,19 @@ char *strmap_del_(struct strmap *map, const char *member, void **valuep)
}
static
bool
iterate
(
struct
strmap
n
,
bool
(
*
handle
)(
const
char
*
,
void
*
,
void
*
),
void
*
data
)
bool
(
*
handle
)(
const
char
*
,
void
*
,
void
*
),
const
void
*
data
)
{
if
(
n
.
v
)
return
handle
(
n
.
u
.
s
,
n
.
v
,
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
);
}
void
strmap_iterate_
(
const
struct
strmap
*
map
,
bool
(
*
handle
)(
const
char
*
,
void
*
,
void
*
),
void
*
data
)
bool
(
*
handle
)(
const
char
*
,
void
*
,
void
*
),
const
void
*
data
)
{
/* Empty map? */
if
(
!
map
->
u
.
n
)
...
...
ccan/strmap/strmap.h
View file @
140cd169
...
...
@@ -189,8 +189,8 @@ void strmap_clear_(struct strmap *map);
__typeof__(arg)), (handle)), \
(arg))
void
strmap_iterate_
(
const
struct
strmap
*
map
,
bool
(
*
handle
)(
const
char
*
,
void
*
,
void
*
),
void
*
data
);
bool
(
*
handle
)(
const
char
*
,
void
*
,
void
*
),
const
void
*
data
);
/**
* strmap_prefix - return a submap matching a prefix
...
...
ccan/strmap/test/run-iterate-const.c
0 → 100644
View file @
140cd169
#include <ccan/strmap/strmap.h>
#include <ccan/strmap/strmap.c>
#include <ccan/tap/tap.h>
static
bool
found
=
false
;
/* Make sure const args work. */
static
bool
find_string
(
const
char
*
str
,
char
*
member
,
const
char
*
cmp
)
{
if
(
strcmp
(
member
,
cmp
)
==
0
)
found
=
true
;
return
false
;
}
int
main
(
void
)
{
struct
strmap_charp
{
STRMAP_MEMBERS
(
char
*
);
}
map
;
plan_tests
(
3
);
strmap_init
(
&
map
);
ok1
(
strmap_add
(
&
map
,
"hello"
,
"hello"
));
ok1
(
strmap_add
(
&
map
,
"world"
,
"world"
));
strmap_iterate
(
&
map
,
find_string
,
(
const
char
*
)
"hello"
);
ok1
(
found
);
strmap_clear
(
&
map
);
/* This exits depending on whether all tests passed */
return
exit_status
();
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment