CharSet VValueBag::DebugDump(char* inTextBuffer, sLONG& inBufferSize) const { if (VProcess::Get() != NULL) { VString dump; VString temp; VIndex i; VIndex count = GetAttributesCount(); for (i = 1 ; i <= count ; ++i) { const VValueSingle* theValue = GetNthAttribute( i, &temp); dump.AppendPrintf("%S = %A\n", &temp, theValue); } count = GetElementNamesCount(); for (i = 1 ; i <= count ; ++i) { const VBagArray *theBagArray = GetNthElementName( i, &temp); dump.AppendPrintf("=======\n%d %S :\n", theBagArray->GetCount(), &temp); for (sLONG j = 1 ; j <= theBagArray->GetCount() ; ++j) { dump.AppendPrintf("--\n%V", theBagArray->RetainNth(j)); } } dump.Truncate(inBufferSize/2); inBufferSize = (sLONG) dump.ToBlock(inTextBuffer, inBufferSize, VTC_UTF_16, false, false); } else inBufferSize = 0; return VTC_UTF_16; }
VError VValueBag::_GetJSONString(VString& outJSONString, sLONG& curlevel, bool prettyformat, JSONOption inModifier) const { AppendBeginJSONObject(outJSONString, curlevel, prettyformat); VIndex nbatt = GetAttributesCount(); VIndex nbelem = GetElementNamesCount(); bool first = true; for (VIndex i = 1; i <= nbatt; i++) { VStr255 s; const VValueSingle* val = GetNthAttribute(i, &s); if ( !s.EqualToUSASCIICString( "____objectunic") && !s.EqualToUSASCIICString( "____property_name_in_jsarray")) { if (first) first = false; else outJSONString.AppendUniChar(','); if (s.EqualToUSASCIICString( "<>")) s = "__CDATA"; AppendJSONPropertyName(outJSONString, curlevel, prettyformat, s); if (val == NULL || val->IsNull()) outJSONString += "null"; else { val->GetJSONString(s, JSON_WithQuotesIfNecessary); outJSONString += s; } } } for (VIndex i = 1; i <= nbelem; i++) { if (first) first = false; else outJSONString.AppendUniChar(','); VStr255 s; const VBagArray* subelems = GetNthElementName(i, &s); AppendJSONPropertyName(outJSONString, curlevel, prettyformat, s); if ((inModifier & JSON_UniqueSubElementsAreNotArrays) != 0 && subelems->GetCount() == 1) { subelems->GetNth(1)->_GetJSONString(outJSONString, curlevel, prettyformat, inModifier); } else if (subelems->GetNth(1)->GetAttribute("____objectunic")) { subelems->GetNth(1)->_GetJSONString(outJSONString, curlevel, prettyformat, inModifier); } else subelems->_GetJSONString(outJSONString, curlevel, prettyformat, inModifier); } AppendEndJSONObject(outJSONString, curlevel, prettyformat); return VE_OK; }
void WriteElement() { if (NULL == m_pCurrentNode) { m_pNode = new CXmlNodeBase(); m_pNode->m_pDocument = this; m_pNode->m_pDocument->AddRef(); m_pCurrentNode = m_pNode; } else { // это m_pCurrentNode CXmlNodeBase* pNewBase = new CXmlNodeBase(); pNewBase->m_pDocument = this; pNewBase->m_pDocument->AddRef(); m_pCurrentNode->m_nodes.insert(m_pCurrentNode->m_nodes.end(), pNewBase); m_pCurrentNode = pNewBase; } m_pCurrentNode->m_sName = GetName(); m_list.push_back(m_pCurrentNode); if (GetAttributesCount() > 0) { MoveToFirstAttribute(); CStringA sName = GetNameA(); while (!sName.IsEmpty()) { m_pCurrentNode->m_attributes.insert(std::make_pair(sName, GetTextA())); if ( !MoveToNextAttribute() ) break; sName = GetNameA(); } MoveToElement(); } if (IsEmptyNode()) { m_list.pop_back(); if (0 != m_list.size()) { std::list<CXmlNodeBase*>::iterator iter = m_list.end(); --iter; m_pCurrentNode = *iter; } else { m_pCurrentNode = m_pNode; } } }
VError VValueBag::WriteToStreamMinimal( VStream *inStream, bool inWithIndex) const { uBYTE flags = 0; if (GetAttributesCount() > 0) flags |= 1; if (GetElementNamesCount() > 0) flags |= 2; inStream->PutByte( flags); if (GetAttributesCount() > 0) fAttributes.WriteToStream( inStream, inWithIndex); if (GetElementNamesCount() > 0) fElements->WriteToStream( inStream, inWithIndex); return inStream->GetLastError(); }
void VValueBag::DumpXMLAttributes(VString& ioDump, const VString& inTitle, VIndex inCDataAttributeIndex, sLONG inIndentLevel) const { VStr<1000> attributes; // start tag attributes += CHAR_LESS_THAN_SIGN; attributes += inTitle; // attributes VStr<50> temp; VIndex count = GetAttributesCount(); for ( VIndex i = 1 ; i <= count ; ++i) { if (i != inCDataAttributeIndex) { attributes += CHAR_SPACE; const VValueSingle *val = GetNthAttribute( i, &temp); attributes += temp; attributes += CHAR_EQUALS_SIGN; attributes += CHAR_QUOTATION_MARK; val->GetXMLString( temp, XSO_Default); attributes += temp; attributes += CHAR_QUOTATION_MARK; } } // need to close now if no element nor cdata if ( (GetElementNamesCount() == 0) && (inCDataAttributeIndex <= 0) ) { attributes += CHAR_SOLIDUS; } attributes += CHAR_GREATER_THAN_SIGN; // no carriage return if no element but some cdata if ( (inIndentLevel >= 0) && ((GetElementNamesCount() > 0) || (inCDataAttributeIndex <= 0) ) ) { attributes += CHAR_CONTROL_000A; } ioDump += attributes; }