Changeset 74008 in vbox for trunk/src/VBox/Runtime/common/rest/RTCRestArrayBase.cpp
- Timestamp:
- Aug 31, 2018 7:08:02 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/rest/RTCRestArrayBase.cpp
r73995 r74008 88 88 /* The default state of an array is empty. At least for now. */ 89 89 clear(); 90 m_fNullIndicator = false; 90 91 return VINF_SUCCESS; 91 92 } … … 94 95 RTCRestOutputBase &RTCRestArrayBase::serializeAsJson(RTCRestOutputBase &a_rDst) const 95 96 { 96 a_rDst.printf("[\n"); 97 unsigned const uOldIndent = a_rDst.incrementIndent(); 98 99 for (size_t i = 0; i < m_cElements; i++) 100 { 101 m_papElements[i]->serializeAsJson(a_rDst); 102 if (i < m_cElements) 103 a_rDst.printf(",\n"); 104 else 105 a_rDst.printf("\n"); 106 } 107 108 a_rDst.setIndent(uOldIndent); 109 a_rDst.printf("]"); 97 if (!m_fNullIndicator) 98 { 99 a_rDst.printf("[\n"); 100 unsigned const uOldIndent = a_rDst.incrementIndent(); 101 102 for (size_t i = 0; i < m_cElements; i++) 103 { 104 m_papElements[i]->serializeAsJson(a_rDst); 105 if (i < m_cElements) 106 a_rDst.printf(",\n"); 107 else 108 a_rDst.printf("\n"); 109 } 110 111 a_rDst.setIndent(uOldIndent); 112 a_rDst.printf("]"); 113 } 114 else 115 a_rDst.printf("null"); 110 116 return a_rDst; 111 117 } … … 119 125 if (m_cElements > 0) 120 126 clear(); 127 m_fNullIndicator = false; 121 128 122 129 /* … … 179 186 RTJsonIteratorFree(hIterator); 180 187 } 181 else if ( rcRet == VERR_JSON_IS_EMPTY 182 || ( rcRet == VERR_JSON_VALUE_INVALID_TYPE 183 && RTJsonValueGetType(a_rCursor.m_hValue) == RTJSONVALTYPE_NULL) ) 188 else if (rcRet == VERR_JSON_IS_EMPTY) 184 189 rcRet = VINF_SUCCESS; 190 else if ( rcRet == VERR_JSON_VALUE_INVALID_TYPE 191 && RTJsonValueGetType(a_rCursor.m_hValue) == RTJSONVALTYPE_NULL) 192 { 193 m_fNullIndicator = true; 194 rcRet = VINF_SUCCESS; 195 } 185 196 else 186 197 rcRet = a_rCursor.m_pPrimary->addError(a_rCursor, rcRet, … … 195 206 { 196 207 int rc; 197 if (m_cElements) 198 { 199 static char const s_szSep[kCollectionFormat_Mask + 1] = ",, \t|,,"; 200 char const chSep = s_szSep[a_fFlags & kCollectionFormat_Mask]; 201 202 rc = m_papElements[0]->toString(a_pDst, a_fFlags); 203 for (size_t i = 1; RT_SUCCESS(rc) && i < m_cElements; i++) 204 { 205 rc = a_pDst->appendNoThrow(chSep); 206 if (RT_SUCCESS(rc)) 207 rc = m_papElements[i]->toString(a_pDst, a_fFlags | kToString_Append); 208 } 209 } 208 if (!m_fNullIndicator) 209 { 210 if (m_cElements) 211 { 212 static char const s_szSep[kCollectionFormat_Mask + 1] = ",, \t|,,"; 213 char const chSep = s_szSep[a_fFlags & kCollectionFormat_Mask]; 214 215 rc = m_papElements[0]->toString(a_pDst, a_fFlags); 216 for (size_t i = 1; RT_SUCCESS(rc) && i < m_cElements; i++) 217 { 218 rc = a_pDst->appendNoThrow(chSep); 219 if (RT_SUCCESS(rc)) 220 rc = m_papElements[i]->toString(a_pDst, a_fFlags | kToString_Append); 221 } 222 } 223 else 224 { 225 if (!(a_fFlags & kToString_Append)) 226 a_pDst->setNull(); 227 rc = VINF_SUCCESS; 228 } 229 } 230 else if (a_fFlags & kToString_Append) 231 rc = a_pDst->appendNoThrow(RT_STR_TUPLE("null")); 210 232 else 211 { 212 a_pDst->setNull(); 213 rc = VINF_SUCCESS; 214 } 233 rc = a_pDst->appendNoThrow(RT_STR_TUPLE("null")); 234 215 235 return rc; 216 236 } … … 239 259 } 240 260 m_cElements = 0; 261 m_fNullIndicator = false; 241 262 } 242 263 … … 291 312 clear(); 292 313 if (a_rThat.m_cElements == 0) 314 { 315 m_fNullIndicator = a_rThat.m_fNullIndicator; 293 316 rc = VINF_SUCCESS; 317 } 294 318 else 295 319 { 320 Assert(!a_rThat.m_fNullIndicator); 296 321 rc = ensureCapacity(a_rThat.m_cElements); 297 322 if (RT_SUCCESS(rc)) … … 346 371 AssertPtr(m_papElements[i]); 347 372 #endif 373 m_fNullIndicator = false; 348 374 return VINF_SUCCESS; 349 375 } … … 352 378 delete m_papElements[a_idx]; 353 379 m_papElements[a_idx] = a_pValue; 380 m_fNullIndicator = false; 354 381 return VWRN_ALREADY_EXISTS; 355 382 }
Note:
See TracChangeset
for help on using the changeset viewer.