//--------------------------------------------------------------------------- void CSVFile::close (void) { if (isOpen()) { atClose(); File::close(); } }
//--------------------------------------------------------------------------- void PacketFile::close(void) { atClose(); File::close(); }
void XML::deserialize(TextInput& t) { begin: Token n = t.read(); m_attribute.clear(); m_child.clear(); m_name = ""; m_value = ""; if ((n.type() == Token::SYMBOL) && (n.string() == "<")) { // Beginning a tag // Read name n = t.read(); debugAssert(n.type() == Token::SYMBOL); bool isComment = (n.string() == "!") && (t.peek().type() == Token::SYMBOL) && (t.peek().string() == "--"); // ignored tag: <?xml> or <!xml> // comment tag: <!-- ... --> if ((n.string() == "?") || ((n.string() == "!") && ! isComment)) { // Ignore this tag while (t.hasMore() && ! ((n.type() == Token::SYMBOL) && (n.string() == ">"))) { n = t.read(); } goto begin; } else if (isComment) { // Ignore until "-->" bool prevWasDash = false; while (t.hasMore() && ! ((n.type() == Token::SYMBOL) && (n.string() == ">") && prevWasDash)) { prevWasDash = (n.type() == Token::SYMBOL) && (n.string() == "--"); n = t.read(); } goto begin; } // Keep reading until no colon m_name += n.string(); n = t.read(); while ((n.type() == Token::SYMBOL) && (n.string() == ":")) { // tag with namespace: <x:y> m_name += ":" + t.readSymbol(); n = t.read(); } // Read end of tag/close bool done = false; while (! done) { debugAssert(n.type() == Token::SYMBOL); if (n.string() == "/") { // empty-element tag: <foo/> // Consume the close tag t.readSymbol(">"); done = true; } else if (n.string() == ">") { // End of open tag: read children until close tag while (! atClose(t, m_name)) { m_child.next().deserialize(t); } // Read close tag (we wouldn't be here unless it parses correctly) while (t.hasMore() && ! (t.readSymbol() == ">")) {} done = true; } else { // Attribute pair std::string k = n.string(); t.readSymbol("="); std::string v = t.read().string(); m_attribute.set(k, v); // Advance to next n = t.read(); } } } else { // Beginning embedded content. Read until the end of file or the next tag. m_type = VALUE; m_value += n.string(); n = t.peek(); while (t.hasMore() && ! ((n.type() == Token::SYMBOL) && (n.string() == "<"))) { m_value += " " + t.read().string(); n = t.peek(); } } }