Beispiel #1
0
int strlist_destroy(cstrlist *l)
{
    if (l==NULL)
        return -1;
    
    strlist_empty(l);
    
    return 0;
}
Beispiel #2
0
static const char *wlist(const char *s)
{
	const char *res = "FAIL";
	struct StrList *sl = strlist_new(USUAL_ALLOC);
	bool ok = parse_word_list(s, sl_add, sl);
	if (ok) {
		if (strlist_empty(sl))
			res = "-";
		else
			res = lshow(sl);
	}
	strlist_free(sl);
	return res;
}
Beispiel #3
0
int strlist_split(cstrlist *l, char *text, char sep)
{
    char *textcopy;
    char delims[4];
    char *saveptr;
    char *result;
    int len;

    if (!l || !text)
    {   errprintf("invalid param\n");
        return -1;
    }
    
    // init
    len=strlen(text);
    snprintf(delims, sizeof(delims), "%c", sep);
    strlist_empty(l);
    
    if ((textcopy=malloc(len+1))==NULL)
    {   errprintf("malloc(%d) failed\n", len+1);
        return -1;
    }

    memcpy(textcopy, text, len+1);
    for (result=strtok_r(textcopy, delims, &saveptr); result!=NULL; result=strtok_r(NULL, delims, &saveptr))
    {
        if (strlist_add(l, result)!=0)
        {   errprintf("strlist_add(l, [%s]) failed\n", result);
            free(textcopy);
            return -1;
        }
    }
    
    free(textcopy);
    return 0;
}