void CExporterXML::ExportURB(CURB *pURB) { LPTSTR sBuffer = (LPTSTR) alloca((2 * MAX_USB_TRANSFERBUFFER_SIZE + 1) * sizeof(TCHAR)); OutputFormat("<urb sequence=\"%d\">", pURB->GetSequenceNr()); IncreaseIndent(); OutputTag("function", pURB->GetFunctionStr()); OutputTag("timestamp", "%d", pURB->GetTime(m_pAR)); OutputTag("endpoint", "%d", pURB->GetEndpoint()); if(pURB->GetPayloadCount(-1) > 0) { OutputTag("packetcount", "%d", pURB->GetPacketCount()); for(int nPacket = 0 ; nPacket < pURB->GetPacketCount(); ++nPacket) { OutputFormat("<payload packet=\"%d\">", nPacket); IncreaseIndent(); OutputTag("payloadcount", "%d", pURB->GetPayloadCount(nPacket)); OutputTag("payloadbytes", pURB->GetPayloadXML(nPacket, sBuffer)); DecreaseIndent(); OutputFormat("</payload>"); } } DecreaseIndent(); OutputFormat("</urb>"); }
bool wxMarkupParser::Parse(const wxString& text) { // The stack containing the names and corresponding attributes (which are // actually only used for <span> tags) of all of the currently opened tag // or none if we're not inside any tag. wxStack<TagAndAttrs> tags; // Current run of text. wxString current; const wxString::const_iterator end = text.end(); for ( wxString::const_iterator it = text.begin(); it != end; ++it ) { switch ( (*it).GetValue() ) { case '<': { // Flush the text preceding the tag, if any. if ( !current.empty() ) { m_output.OnText(current); current.clear(); } // Remember the tag starting position for the error // messages. const size_t pos = it - text.begin(); bool start = true; if ( ++it != end && *it == '/' ) { start = false; ++it; } const wxString tag = ExtractUntil('>', it, end); if ( tag.empty() ) { wxLogDebug("%s at %lu.", it == end ? "Unclosed tag starting" : "Empty tag", pos); return false; } if ( start ) { wxString attrs; const wxString name = tag.BeforeFirst(' ', &attrs); TagAndAttrs tagAndAttrs(name); const wxString err = ParseAttrs(attrs, tagAndAttrs); if ( !err.empty() ) { wxLogDebug("Bad attributes for \"%s\" " "at %lu: %s.", name, pos, err); return false; } tags.push(tagAndAttrs); } else // end tag { if ( tags.empty() || tags.top().name != tag ) { wxLogDebug("Unmatched closing tag \"%s\" at %lu.", tag, pos); return false; } } if ( !OutputTag(tags.top(), start) ) { wxLogDebug("Unknown tag at %lu.", pos); return false; } if ( !start ) tags.pop(); } break; case '>': wxLogDebug("'>' should be escaped as \">\"; at %lu.", it - text.begin()); break; case '&': // Processing is somewhat complicated: we need to recognize at // least the "<" entity to allow escaping left square // brackets in the markup and, in fact, we recognize all of the // standard XML entities for consistency with Pango markup // parsing. // // However we also allow '&' to appear unescaped, i.e. directly // and not as "&" when it is used to introduce the mnemonic // for the label. In this case we simply leave it alone. // // Notice that this logic makes it impossible to have a label // with "lt;" inside it and using "l" as mnemonic but hopefully // this shouldn't be a problem in practice. { const size_t pos = it - text.begin() + 1; unsigned n; for ( n = 0; n < WXSIZEOF(xmlEntities); n++ ) { const XMLEntity& xmlEnt = xmlEntities[n]; if ( text.compare(pos, xmlEnt.len, xmlEnt.name) == 0 && text[pos + xmlEnt.len] == ';' ) { // Escape the ampersands if needed to protect them // from being interpreted as mnemonics indicators. if ( xmlEnt.value == '&' ) current += "&&"; else current += xmlEnt.value; it += xmlEnt.len + 1; // +1 for '&' itself break; } } if ( n < WXSIZEOF(xmlEntities) ) break; //else: fall through, '&' is not special } default: current += *it; } } if ( !tags.empty() ) { wxLogDebug("Missing closing tag for \"%s\"", tags.top().name); return false; } if ( !current.empty() ) m_output.OnText(current); return true; }