VirtualBox

Ignore:
Timestamp:
Aug 29, 2018 3:09:34 PM (6 years ago)
Author:
vboxsync
Message:

IPRT/rest: Added RTJsonIteratorBeginArray and RTJsonIteratorBeginObject for more accurate JSON decoding. Early RTCRestArray implementation. bugref:9167

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/misc/json.cpp

    r73930 r73956  
    14861486}
    14871487
     1488static int rtJsonIteratorBeginWorker(PRTJSONVALINT pThis, PRTJSONIT phJsonIt)
     1489{
     1490    PRTJSONITINT pIt = (PRTJSONITINT)RTMemTmpAllocZ(sizeof(RTJSONITINT));
     1491    if (pIt)
     1492    {
     1493        RTJsonValueRetain(pThis);
     1494        pIt->pJsonVal = pThis;
     1495        pIt->idxCur = 0;
     1496
     1497        *phJsonIt = pIt;
     1498        return VINF_SUCCESS;
     1499    }
     1500    return VERR_NO_MEMORY;
     1501}
     1502
    14881503RTDECL(int) RTJsonIteratorBegin(RTJSONVAL hJsonVal, PRTJSONIT phJsonIt)
    14891504{
     
    14911506    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
    14921507    AssertPtrReturn(phJsonIt, VERR_INVALID_POINTER);
    1493 
    14941508    RTJSON_TYPECHECK_CONTAINER_RETURN(pThis);
    14951509
    1496     PRTJSONITINT pIt = (PRTJSONITINT)RTMemTmpAllocZ(sizeof(RTJSONITINT));
    1497     if (RT_UNLIKELY(!pIt))
    1498         return VERR_NO_MEMORY;
    1499 
    1500     RTJsonValueRetain(hJsonVal);
    1501     pIt->pJsonVal = pThis;
    1502     pIt->idxCur = 0;
    1503     *phJsonIt = pIt;
    1504 
    1505     return VINF_SUCCESS;
     1510    return rtJsonIteratorBeginWorker(pThis, phJsonIt);
     1511}
     1512
     1513RTDECL(int) RTJsonIteratorBeginArray(RTJSONVAL hJsonVal, PRTJSONIT phJsonIt)
     1514{
     1515    PRTJSONVALINT pThis = hJsonVal;
     1516    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     1517    AssertPtrReturn(phJsonIt, VERR_INVALID_POINTER);
     1518    RTJSON_TYPECHECK_RETURN(pThis, RTJSONVALTYPE_ARRAY);
     1519
     1520    return rtJsonIteratorBeginWorker(pThis, phJsonIt);
     1521}
     1522
     1523RTDECL(int) RTJsonIteratorBeginObject(RTJSONVAL hJsonVal, PRTJSONIT phJsonIt)
     1524{
     1525    PRTJSONVALINT pThis = hJsonVal;
     1526    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     1527    AssertPtrReturn(phJsonIt, VERR_INVALID_POINTER);
     1528    RTJSON_TYPECHECK_RETURN(pThis, RTJSONVALTYPE_OBJECT);
     1529
     1530    return rtJsonIteratorBeginWorker(pThis, phJsonIt);
    15061531}
    15071532
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette