Skip to content

Commit 1eaec16

Browse files
committed
Squashed 'libs/ujson4c/' changes from 65d3e3586..6c0831944
6c0831944 add function to return lenght of an array git-subtree-dir: libs/ujson4c git-subtree-split: 6c0831944229cadc6948c12833faad999fb6cd47
1 parent 0319ade commit 1eaec16

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/ujdecode.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ typedef struct __ArrayItem
7575
Item item;
7676
ArrayEntry *head;
7777
ArrayEntry *tail;
78-
} ArrayItem;
78+
int length;
79+
} ArrayItem;
7980

8081
typedef struct __LongValue
8182
{
@@ -229,6 +230,7 @@ static void arrayAddItem(void* context, JSOBJ obj, JSOBJ value)
229230
}
230231
ai->tail = ae;
231232

233+
ai->length ++;
232234
}
233235

234236
static JSOBJ newTrue(void* context)
@@ -272,6 +274,7 @@ static JSOBJ newArray(void *context)
272274
ArrayItem *ai = (ArrayItem *) alloc(ds, sizeof(ArrayItem));
273275
ai->head = NULL;
274276
ai->tail = NULL;
277+
ai->length = 0;
275278
ai->item.type = UJT_Array;
276279
return (JSOBJ) ai;
277280
}
@@ -473,6 +476,15 @@ int UJIterArray(void **iter, UJObject *outObj)
473476
return 1;
474477
}
475478

479+
int UJLengthArray(UJObject arrObj)
480+
{
481+
switch ( ((Item *) arrObj)->type)
482+
{
483+
case UJT_Array: return ((ArrayItem *) arrObj)->length;
484+
default: return -1;
485+
}
486+
}
487+
476488
void *UJBeginObject(UJObject objObj)
477489
{
478490
switch ( ((Item *) objObj)->type)
@@ -688,7 +700,6 @@ int UJObjectUnpack(UJObject objObj, int keys, const char *format, const wchar_t
688700
const wchar_t *keyNames[64];
689701
UJObject *outValues[64];
690702
va_list args;
691-
UJObject *outValue;
692703

693704

694705
if (!UJIsObject(objObj))
@@ -707,8 +718,7 @@ int UJObjectUnpack(UJObject objObj, int keys, const char *format, const wchar_t
707718
for (ki = 0; ki < keys; ki ++)
708719
{
709720
keyNames[ki] = _keyNames[ki];
710-
outValue = va_arg(args, UJObject *);
711-
outValues[ki] = outValue;
721+
outValues[ki] = va_arg(args, UJObject *);
712722
}
713723
va_end(args);
714724

src/ujdecode.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,14 @@ extern "C" {
163163
*/
164164
int UJIterArray(void **iter, UJObject *outObj);
165165

166+
/*
167+
===============================================================================
168+
Returns the count of elements in an array object,
169+
or negative if not an array.
170+
===============================================================================
171+
*/
172+
int UJLengthArray(UJObject arrObj);
173+
166174
/*
167175
===============================================================================
168176
Called to initiate the iterator of an Object (key-value structure)

0 commit comments

Comments
 (0)