#include <iostream>
#include <sstream>
#include <string>
// ----- Definitions from the general purpose library -----
// This is the C-based XML parser object
struct XmlParser
{
int dummy;
};
// The read function our parser uses to get more data
typedef int (*xmlReadFn)(void* user_data, char* s, int len);
#define BUF_SIZE 5
// The parse function for our parser
void xmlParse(XmlParser* parser, xmlReadFn read_fn, void* user_data)
{
char buf[BUF_SIZE];
int read_len;
do
{
read_len = read_fn(user_data, buf, BUF_SIZE);
// Here I'm just printing out what we read, one chunk per line
std::string str(buf, read_len);
std::cout << str << std::endl;
}
while (read_len == BUF_SIZE);
}
// ----- Our implementation -----
// This is our implementation of the xmlReadFn function
int readFromStream(void* user_data, char* s, int len)
{
std::istream* str = (std::istream*)user_data;
return str->readsome(s, len);
}
int main()
{
// Allocate the parser
XmlParser parser;
// Construct the stream we want to read from. Normally, this would come from a file
std::stringstream str("The quick brown fox ran over the lazy dog.");
xmlParse(&parser, readFromStream, &str);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3N0cmVhbT4KI2luY2x1ZGUgPHN0cmluZz4KCi8vIC0tLS0tIERlZmluaXRpb25zIGZyb20gdGhlIGdlbmVyYWwgcHVycG9zZSBsaWJyYXJ5IC0tLS0tCi8vIFRoaXMgaXMgdGhlIEMtYmFzZWQgWE1MIHBhcnNlciBvYmplY3QKc3RydWN0IFhtbFBhcnNlcgp7CmludCBkdW1teTsKfTsKCi8vIFRoZSByZWFkIGZ1bmN0aW9uIG91ciBwYXJzZXIgdXNlcyB0byBnZXQgbW9yZSBkYXRhCnR5cGVkZWYgaW50ICgqeG1sUmVhZEZuKSh2b2lkKiB1c2VyX2RhdGEsIGNoYXIqIHMsIGludCBsZW4pOwoKI2RlZmluZSBCVUZfU0laRSA1CgovLyBUaGUgcGFyc2UgZnVuY3Rpb24gZm9yIG91ciBwYXJzZXIKdm9pZCB4bWxQYXJzZShYbWxQYXJzZXIqIHBhcnNlciwgeG1sUmVhZEZuIHJlYWRfZm4sIHZvaWQqIHVz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