[DeckList] Extract deck root seeking and body reading in XML load (#7324)

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2026-09-19 10:35:05 +02:00 committed by GitHub
parent 662f1b79cc
commit ec39ec611b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 41 additions and 12 deletions

View file

@ -184,6 +184,27 @@ void DeckList::write(QXmlStreamWriter *xml) const
xml->writeEndElement(); // Close "cockatrice_deck" xml->writeEndElement(); // Close "cockatrice_deck"
} }
bool DeckList::seekToNextElement(QXmlStreamReader *xml)
{
while (!xml->atEnd()) {
xml->readNext();
if (xml->isStartElement()) {
return true;
}
}
return false;
}
void DeckList::readDeckBody(QXmlStreamReader *xml)
{
while (!xml->atEnd()) {
xml->readNext();
if (!readElement(xml)) {
break;
}
}
}
bool DeckList::loadFromXml(QXmlStreamReader *xml) bool DeckList::loadFromXml(QXmlStreamReader *xml)
{ {
if (xml->error()) { if (xml->error()) {
@ -192,19 +213,11 @@ bool DeckList::loadFromXml(QXmlStreamReader *xml)
} }
cleanList(); cleanList();
while (!xml->atEnd()) { while (seekToNextElement(xml)) {
xml->readNext(); if (xml->name().toString() != "cockatrice_deck") {
if (xml->isStartElement()) { return false;
if (xml->name().toString() != "cockatrice_deck") {
return false;
}
while (!xml->atEnd()) {
xml->readNext();
if (!readElement(xml)) {
break;
}
}
} }
readDeckBody(xml);
} }
refreshDeckHash(); refreshDeckHash();
if (xml->error()) { if (xml->error()) {

View file

@ -106,6 +106,22 @@ private:
*/ */
mutable QString cachedDeckHash; mutable QString cachedDeckHash;
/** @name XML load helpers */
///@{
/**
* @brief Advances to the next element in the XML stream.
* @param xml Reader to advance past non-element tokens.
* @return true when a start element was reached, false at end of stream.
*/
bool seekToNextElement(QXmlStreamReader *xml);
/**
* @brief Reads the contents of a `cockatrice_deck` element into this deck.
* @param xml Reader positioned at the deck element, stopped at its end.
*/
void readDeckBody(QXmlStreamReader *xml);
///@}
public: public:
/** @name Metadata setters */ /** @name Metadata setters */
///@{ ///@{