Skip to content

Commit 399b9f7

Browse files
committed
slist: on split_tokens add suppor for 'max_split' option
Signed-off-by: Eduardo Silva <[email protected]>
1 parent c07c527 commit 399b9f7

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

include/fluent-bit/flb_slist.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ int flb_slist_add_sds(struct mk_list *head, flb_sds_t str);
3838
void flb_slist_destroy(struct mk_list *list);
3939
int flb_slist_split_string(struct mk_list *list, const char *str,
4040
int separator, int max_split);
41-
int flb_slist_split_tokens(struct mk_list *list, const char *str);
41+
int flb_slist_split_tokens(struct mk_list *list, const char *str, int max_split);
4242

4343
void flb_slist_dump(struct mk_list *list);
4444
struct flb_slist_entry *flb_slist_entry_get(struct mk_list *list, int n);

src/flb_slist.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,10 @@ static flb_sds_t token_retrieve(char **str)
176176
return out;
177177
}
178178

179-
int flb_slist_split_tokens(struct mk_list *list, const char *str)
179+
int flb_slist_split_tokens(struct mk_list *list, const char *str, int max_split)
180180
{
181+
int count = 0;
182+
char *p;
181183
char *buf;
182184
flb_sds_t tmp = NULL;
183185

@@ -187,6 +189,20 @@ int flb_slist_split_tokens(struct mk_list *list, const char *str)
187189
if (!buf) {
188190
break;
189191
}
192+
count++;
193+
194+
/* Append remaining string if we use a maximum number of tokens */
195+
if (count >= max_split && max_split > 0) {
196+
p = buf;
197+
while (*p == ' ') {
198+
p++;
199+
}
200+
201+
if (*p) {
202+
flb_slist_add(list, p);
203+
}
204+
break;
205+
}
190206
}
191207

192208
return 0;

0 commit comments

Comments
 (0)