MCPcopy Create free account
hub / github.com/F-Stack/f-stack / rte_kvargs_tokenize

Function rte_kvargs_tokenize

dpdk/lib/kvargs/rte_kvargs.c:24–111  ·  view source on GitHub ↗

* Receive a string with a list of arguments following the pattern * key=value,key=value,... and insert them into the list. * Params string will be copied to be modified. * list "[]" and list element splitter ",", "-" is treated as value. * Supported examples: * k1=v1,k2=v2 * k1 * k1=x[0-1]y[1,3-5,9]z */

Source from the content-addressed store, hash-verified

22 * k1=x[0-1]y[1,3-5,9]z
23 */
24static int
25rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params)
26{
27 char *str, *start;
28 bool in_list = false, end_key = false, end_value = false;
29 bool save = false, end_pair = false;
30
31 /* Copy the const char *params to a modifiable string
32 * to pass to rte_strsplit
33 */
34 kvlist->str = strdup(params);
35 if (kvlist->str == NULL)
36 return -1;
37
38 /* browse each key/value pair and add it in kvlist */
39 str = kvlist->str;
40 start = str; /* start of current key or value */
41 while (1) {
42 switch (*str) {
43 case '=': /* End of key. */
44 end_key = true;
45 save = true;
46 break;
47 case ',':
48 /* End of value, skip comma in middle of range */
49 if (!in_list) {
50 if (end_key)
51 end_value = true;
52 else
53 end_key = true;
54 save = true;
55 end_pair = true;
56 }
57 break;
58 case '[': /* Start of list. */
59 in_list = true;
60 break;
61 case ']': /* End of list. */
62 if (in_list)
63 in_list = false;
64 break;
65 case '\0': /* End of string */
66 if (end_key)
67 end_value = true;
68 else
69 end_key = true;
70 save = true;
71 end_pair = true;
72 break;
73 default:
74 break;
75 }
76
77 if (!save) {
78 /* Continue if not end of key or value. */
79 str++;
80 continue;
81 }

Callers 1

rte_kvargs_parseFunction · 0.85

Calls 1

strdupFunction · 0.85

Tested by

no test coverage detected