mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
common: New function split_fields_colon.
* common/stringhelp.c (split_fields_colon): New. * common/t-stringhelp.c (test_split_fields_colon): New test. (main): Call that test. Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
58eafd11ed
commit
849467870e
3 changed files with 116 additions and 0 deletions
|
@ -1339,6 +1339,42 @@ split_fields (char *string, char **array, int arraysize)
|
|||
}
|
||||
|
||||
|
||||
/* Split a string into colon delimited fields A pointer to each field
|
||||
* is stored in ARRAY. Stop splitting at ARRAYSIZE fields. The
|
||||
* function modifies STRING. The number of parsed fields is returned.
|
||||
* Note that leading and trailing spaces are not removed from the fields.
|
||||
* Example:
|
||||
*
|
||||
* char *fields[2];
|
||||
* if (split_fields (string, fields, DIM (fields)) < 2)
|
||||
* return // Not enough args.
|
||||
* foo (fields[0]);
|
||||
* foo (fields[1]);
|
||||
*/
|
||||
int
|
||||
split_fields_colon (char *string, char **array, int arraysize)
|
||||
{
|
||||
int n = 0;
|
||||
char *p, *pend;
|
||||
|
||||
p = string;
|
||||
do
|
||||
{
|
||||
if (n == arraysize)
|
||||
break;
|
||||
array[n++] = p;
|
||||
pend = strchr (p, ':');
|
||||
if (!pend)
|
||||
break;
|
||||
*pend++ = 0;
|
||||
p = pend;
|
||||
}
|
||||
while (*p);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Version number parsing. */
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue