mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-21 09:05:10 -07:00
[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:
parent
662f1b79cc
commit
ec39ec611b
2 changed files with 41 additions and 12 deletions
|
|
@ -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()) {
|
||||||
|
|
|
||||||
|
|
@ -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 */
|
||||||
///@{
|
///@{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue