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
737dcc0f
Commit
737dcc0f
authored
Dec 03, 2012
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tal/str: make tal_count() work for strsplit.
Signed-off-by:
Rusty Russell
<
rusty@rustcorp.com.au
>
parent
83c75170
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
2 deletions
+12
-2
ccan/tal/str/str.c
ccan/tal/str/str.c
+5
-0
ccan/tal/str/str.h
ccan/tal/str/str.h
+2
-1
ccan/tal/str/test/run.c
ccan/tal/str/test/run.c
+5
-1
No files found.
ccan/tal/str/str.c
View file @
737dcc0f
...
@@ -49,6 +49,11 @@ char **strsplit(const tal_t *ctx,
...
@@ -49,6 +49,11 @@ char **strsplit(const tal_t *ctx,
goto
fail
;
goto
fail
;
}
}
parts
[
num
]
=
NULL
;
parts
[
num
]
=
NULL
;
/* Ensure that tal_count() is correct. */
if
(
unlikely
(
!
tal_resize
(
&
parts
,
num
+
1
)))
goto
fail
;
if
(
taken
(
delims
))
if
(
taken
(
delims
))
tal_free
(
delims
);
tal_free
(
delims
);
return
parts
;
return
parts
;
...
...
ccan/tal/str/str.h
View file @
737dcc0f
...
@@ -26,7 +26,8 @@ enum strsplit {
...
@@ -26,7 +26,8 @@ enum strsplit {
* Multiple delimiters result in empty substrings. By definition, no
* Multiple delimiters result in empty substrings. By definition, no
* delimiters will appear in the substrings.
* delimiters will appear in the substrings.
*
*
* The final char * in the array will be NULL.
* The final char * in the array will be NULL, and tal_count() will
* return the number of elements plus 1 (for that NULL).
*
*
* Example:
* Example:
* #include <ccan/tal/str/str.h>
* #include <ccan/tal/str/str.h>
...
...
ccan/tal/str/test/run.c
View file @
737dcc0f
...
@@ -14,24 +14,27 @@ int main(int argc, char *argv[])
...
@@ -14,24 +14,27 @@ int main(int argc, char *argv[])
char
**
split
,
*
str
;
char
**
split
,
*
str
;
void
*
ctx
;
void
*
ctx
;
plan_tests
(
6
5
);
plan_tests
(
6
9
);
split
=
strsplit
(
NULL
,
"hello world"
,
" "
,
STR_EMPTY_OK
);
split
=
strsplit
(
NULL
,
"hello world"
,
" "
,
STR_EMPTY_OK
);
ok1
(
!
strcmp
(
split
[
0
],
"hello"
));
ok1
(
!
strcmp
(
split
[
0
],
"hello"
));
ok1
(
!
strcmp
(
split
[
1
],
""
));
ok1
(
!
strcmp
(
split
[
1
],
""
));
ok1
(
!
strcmp
(
split
[
2
],
"world"
));
ok1
(
!
strcmp
(
split
[
2
],
"world"
));
ok1
(
split
[
3
]
==
NULL
);
ok1
(
split
[
3
]
==
NULL
);
ok1
(
tal_count
(
split
)
==
4
);
tal_free
(
split
);
tal_free
(
split
);
split
=
strsplit
(
NULL
,
"hello world"
,
" "
,
STR_NO_EMPTY
);
split
=
strsplit
(
NULL
,
"hello world"
,
" "
,
STR_NO_EMPTY
);
ok1
(
!
strcmp
(
split
[
0
],
"hello"
));
ok1
(
!
strcmp
(
split
[
0
],
"hello"
));
ok1
(
!
strcmp
(
split
[
1
],
"world"
));
ok1
(
!
strcmp
(
split
[
1
],
"world"
));
ok1
(
split
[
2
]
==
NULL
);
ok1
(
split
[
2
]
==
NULL
);
ok1
(
tal_count
(
split
)
==
3
);
tal_free
(
split
);
tal_free
(
split
);
split
=
strsplit
(
NULL
,
" hello world"
,
" "
,
STR_NO_EMPTY
);
split
=
strsplit
(
NULL
,
" hello world"
,
" "
,
STR_NO_EMPTY
);
ok1
(
!
strcmp
(
split
[
0
],
"hello"
));
ok1
(
!
strcmp
(
split
[
0
],
"hello"
));
ok1
(
!
strcmp
(
split
[
1
],
"world"
));
ok1
(
!
strcmp
(
split
[
1
],
"world"
));
ok1
(
split
[
2
]
==
NULL
);
ok1
(
split
[
2
]
==
NULL
);
ok1
(
tal_count
(
split
)
==
3
);
tal_free
(
split
);
tal_free
(
split
);
split
=
strsplit
(
NULL
,
"hello world"
,
"o "
,
STR_EMPTY_OK
);
split
=
strsplit
(
NULL
,
"hello world"
,
"o "
,
STR_EMPTY_OK
);
...
@@ -41,6 +44,7 @@ int main(int argc, char *argv[])
...
@@ -41,6 +44,7 @@ int main(int argc, char *argv[])
ok1
(
!
strcmp
(
split
[
3
],
"w"
));
ok1
(
!
strcmp
(
split
[
3
],
"w"
));
ok1
(
!
strcmp
(
split
[
4
],
"rld"
));
ok1
(
!
strcmp
(
split
[
4
],
"rld"
));
ok1
(
split
[
5
]
==
NULL
);
ok1
(
split
[
5
]
==
NULL
);
ok1
(
tal_count
(
split
)
==
6
);
ctx
=
split
;
ctx
=
split
;
split
=
strsplit
(
ctx
,
"hello world"
,
"o "
,
STR_EMPTY_OK
);
split
=
strsplit
(
ctx
,
"hello world"
,
"o "
,
STR_EMPTY_OK
);
...
...
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