Moved is_windows_item() to anonymous namespace,

fixed tabs, added parsing break in OnEndElement()
This commit is contained in:
Alex Novichkov
2014-01-24 09:09:34 +04:00
parent ec85b3cfee
commit 826deeaa9d

View File

@@ -62,21 +62,18 @@ namespace
// context data for the parser
struct ContextData
{
ContextData(Appcast& a, XML_Parser& p)
: appcast(a),
parser(p),
ContextData(XML_Parser& p)
: parser(p),
in_channel(0), in_item(0), in_relnotes(0), in_title(0), in_description(0)
{}
// appcast we're parsing into
Appcast& appcast;
// the parser we're using
XML_Parser& parser;
// is inside <channel>, <item> or <sparkle:releaseNotesLink>, <title>, or <description> respectively?
int in_channel, in_item, in_relnotes, in_title, in_description;
// parsed <item>s
std::vector<Appcast> items;
};
@@ -150,6 +147,10 @@ void XMLCALL OnEndElement(void *data, const char *name)
else if ( ctxt.in_channel && strcmp(name, NODE_ITEM) == 0 )
{
ctxt.in_item--;
if (ctxt.items[ctxt.items.size()-1].Os == OS_MARKER) {
// we've found os-specific <item>, no need to continue parsing
XML_StopParser(ctxt.parser, XML_TRUE);
}
}
else if ( strcmp(name, NODE_CHANNEL) == 0 )
{
@@ -174,6 +175,11 @@ void XMLCALL OnText(void *data, const char *s, int len)
ctxt.items[size-1].Description.append(s, len);
}
bool is_windows_item(const Appcast &item)
{
return item.Os == OS_MARKER;
}
} // anonymous namespace
@@ -181,18 +187,13 @@ void XMLCALL OnText(void *data, const char *s, int len)
Appcast class
*--------------------------------------------------------------------------*/
bool is_windows_item(const Appcast &item)
{
return item.Os == OS_MARKER;
}
void Appcast::Load(const std::string& xml)
{
XML_Parser p = XML_ParserCreateNS(NULL, NS_SEP);
if ( !p )
throw std::runtime_error("Failed to create XML parser.");
ContextData ctxt(*this, p);
ContextData ctxt(p);
XML_SetUserData(p, &ctxt);
XML_SetElementHandler(p, OnStartElement, OnEndElement);