Make ::input a method on SpyReader, not a field

This commit is contained in:
Max Brunsfeld 2014-09-30 14:57:57 -07:00
parent 8d7d9af661
commit 5f313896c3
3 changed files with 12 additions and 9 deletions

View file

@ -26,18 +26,21 @@ SpyReader::SpyReader(string content, size_t chunk_size) :
buffer(new char[chunk_size]),
content(content),
position(0),
chunk_size(chunk_size),
input({
this,
spy_read,
spy_seek,
nullptr,
}) {}
chunk_size(chunk_size) {}
void SpyReader::clear() {
strings_read.clear();
}
TSInput SpyReader::input() {
TSInput result;
result.data = this;
result.seek_fn = spy_seek;
result.read_fn = spy_read;
result.release_fn = nullptr;
return result;
}
SpyReader::~SpyReader() {
delete buffer;
}

View file

@ -11,12 +11,12 @@ class SpyReader {
~SpyReader();
void clear();
TSInput input();
char *buffer;
std::string content;
size_t position;
size_t chunk_size;
TSInput input;
std::vector<std::string> strings_read;
};

View file

@ -27,7 +27,7 @@ describe("Parser", [&]() {
auto set_text = [&](const char *text) {
reader = new SpyReader(text, chunk_size);
ts_document_set_input(doc, reader->input);
ts_document_set_input(doc, reader->input());
root = ts_document_root_node(doc);
reader->clear();
};