* This class provides recovery from invalid characters in an XML stream. * * Some characters are not allowed in well-formed XML 1.0 (cf. * https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Char). While QXmlStreamWriter * will not complain when writing such characters, QXmlStreamReader will raise * a NotWellFormedError. This class will remove offending characters from the * input and reset the
| 82 | * } |
| 83 | */ |
| 84 | class XmlRecoveryHelper |
| 85 | { |
| 86 | public: |
| 87 | /** |
| 88 | * Constructs a new recovery helper for the given xml stream. |
| 89 | * |
| 90 | * Captures the current position in the XML stream (QXmlStreamReader::characterOffset()). |
| 91 | */ |
| 92 | XmlRecoveryHelper(QXmlStreamReader& xml) : xml (xml), recovery_start {xml.characterOffset()} {} |
| 93 | |
| 94 | /** |
| 95 | * Checks the stream for an error which this utility can handle, |
| 96 | * applies corrections, and resets the stream. |
| 97 | * |
| 98 | * If this operator returns false if either there was a different type of |
| 99 | * error, or if recovery failed. If it returns true, the stream was modified |
| 100 | * in order to fix the errors which are handled by this utility, and a new |
| 101 | * attempt can be made to parse the remainder of the stream. |
| 102 | */ |
| 103 | bool operator() (); |
| 104 | |
| 105 | private: |
| 106 | QXmlStreamReader& xml; |
| 107 | const qint64 recovery_start; |
| 108 | }; |
| 109 | |
| 110 | |
| 111 |
no outgoing calls
no test coverage detected