#include #include #include #include #include #include "retriever.h" #include "../node.h" #include "../node_util.h" #include "../string_util.h" #include "../tree.hh" using std::ifstream; using std::invalid_argument; using std::runtime_error; using std::string; using std::cout; using std::endl; using std::vector; static const int BUFFER_SIZE=256; static string read_line(ifstream &file){ static char buffer[BUFFER_SIZE]; file.get(buffer,BUFFER_SIZE); file.get(); return string(buffer); } static void skip_to_line(ifstream &file,int &cur_line, int new_line){ if(new_line==cur_line){ // skip out early if possible return; }else if(new_line &tr){ //cout << "TextPlainRetriever::getData(" << location << ",tree)" << endl; // REMOVE // check that the argument is not an empty string if(location.size()<=0) throw invalid_argument("cannot parse empty string"); // check that the argument is an integer int line_num=string_util::str_to_int(location); // set stream to the line before skip_to_line(infile,current_line,line_num); // read the line and print it to the console string text=read_line(infile); // create an empty node Node node("empty","empty"); // put the data in the node vector dims; dims.push_back(text.size()); update_node_from_string(node,text,dims,Node::CHAR); tr.insert(tr.begin(),node); } const string TextPlainRetriever::MIME_TYPE("text/plain"); string TextPlainRetriever::toString() const{ return "["+MIME_TYPE+"] "+source; }