MCPcopy Create free account
hub / github.com/MultiMC/Launcher / parse_array

Function parse_array

libraries/tomlc99/src/toml.c:992–1078  ·  view source on GitHub ↗

We are at '[...]' */

Source from the content-addressed store, hash-verified

990
991/* We are at '[...]' */
992static int parse_array(context_t* ctx, toml_array_t* arr)
993{
994 if (eat_token(ctx, LBRACKET, 0, FLINE)) return -1;
995
996 for (;;) {
997 if (skip_newlines(ctx, 0)) return -1;
998
999 /* until ] */
1000 if (ctx->tok.tok == RBRACKET) break;
1001
1002 switch (ctx->tok.tok) {
1003 case STRING:
1004 {
1005 /* set array kind if this will be the first entry */
1006 if (arr->kind == 0)
1007 arr->kind = 'v';
1008 else if (arr->kind != 'v')
1009 arr->kind = 'm';
1010
1011 char* val = ctx->tok.ptr;
1012 int vlen = ctx->tok.len;
1013
1014 /* make a new value in array */
1015 toml_arritem_t* newval = create_value_in_array(ctx, arr);
1016 if (!newval)
1017 return e_outofmemory(ctx, FLINE);
1018
1019 if (! (newval->val = STRNDUP(val, vlen)))
1020 return e_outofmemory(ctx, FLINE);
1021
1022 newval->valtype = valtype(newval->val);
1023
1024 /* set array type if this is the first entry */
1025 if (arr->nitem == 1)
1026 arr->type = newval->valtype;
1027 else if (arr->type != newval->valtype)
1028 arr->type = 'm'; /* mixed */
1029
1030 if (eat_token(ctx, STRING, 0, FLINE)) return -1;
1031 break;
1032 }
1033
1034 case LBRACKET:
1035 { /* [ [array], [array] ... ] */
1036 /* set the array kind if this will be the first entry */
1037 if (arr->kind == 0)
1038 arr->kind = 'a';
1039 else if (arr->kind != 'a')
1040 arr->kind = 'm';
1041
1042 toml_array_t* subarr = create_array_in_array(ctx, arr);
1043 if (!subarr) return -1;
1044 if (parse_array(ctx, subarr)) return -1;
1045 break;
1046 }
1047
1048 case LBRACE:
1049 { /* [ {table}, {table} ... ] */

Callers 1

parse_keyvalFunction · 0.85

Calls 10

eat_tokenFunction · 0.85
skip_newlinesFunction · 0.85
create_value_in_arrayFunction · 0.85
e_outofmemoryFunction · 0.85
STRNDUPFunction · 0.85
valtypeFunction · 0.85
create_array_in_arrayFunction · 0.85
create_table_in_arrayFunction · 0.85
parse_inline_tableFunction · 0.85
e_syntaxFunction · 0.85

Tested by

no test coverage detected