0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2025-01-14 16:46:50 +01:00

librb: Add array_to_string() to invert string_to_array().

This commit is contained in:
Jason Volk 2016-06-24 22:27:33 -07:00
parent 14cd76b435
commit c9f0354dbc
3 changed files with 32 additions and 0 deletions

View file

@ -48,6 +48,7 @@ char *rb_basename(const char *);
char *rb_dirname(const char *);
int rb_string_to_array(char *string, char **parv, int maxpara);
size_t rb_array_to_string(int parc, const char **parv, char *buf, size_t max);
typedef struct _rb_zstring
{

View file

@ -174,6 +174,7 @@ rb_strcasecmp
rb_strcasestr
rb_strerror
rb_string_to_array
rb_array_to_string
rb_strlcat
rb_strlcpy
rb_strncasecmp

View file

@ -138,6 +138,36 @@ rb_string_to_array(char *string, char **parv, int maxpara)
return x;
}
/* rb_array_to_string()
* Inverse of rb_string_to_array()
* - space for delim
* - ':' prefixed at last parameter
*/
size_t
rb_array_to_string(int parc, const char **parv, char *buf, size_t max)
{
size_t ret = 0;
if(rb_unlikely(!max))
return ret;
buf[0] = '\0';
for(int i = 0; i < parc - 1; ++i)
{
ret = rb_strlcat(buf, parv[i], max);
ret = rb_strlcat(buf, " ", max);
}
if(parc)
{
ret = rb_strlcat(buf, ":", max);
ret = rb_strlcat(buf, parv[parc - 1], max);
}
return ret;
}
#ifndef HAVE_STRCASECMP
#ifndef _WIN32
/* Fallback taken from FreeBSD. --Elizafox */