#include #include #include #include "library.h" #include "Var.h" #include "Packet.h" void parse(std::string packet); int main() { std::string packet = ":_source\tpsyc://localhost\n=_target\tpsyc://localhost:-51058\n:_implementation\tpsycMUVE/0.99 LDMUD/3.4.0 Linux/2.6.12-rc3-love1-jakarta i686\n \tCool\n:_page_description\thttp://psyc.pages.de/\n_notice_circuit_established\nHello [_target].\nCircuit to [_source] running [_implementation] established.\n."; parse(packet); return 0; } void parse(std::string buf) { //line based parsing std::vector lines = string_split(buf, '\n'); std::vector vars; std::string message = ""; std::string lastvar; psyc::Packet* packet = new psyc::Packet(); for (int i = 0; i < lines.size(); i++) { switch (lines[i].at(0)) { case '\n': case '.': break; //variable continuation case '\t': case ' ': packet->getVars()[lastvar]->setValue(packet->getVars()[lastvar]->getValue() + " " + lines[i].substr(2, std::string::npos)); break; // variables case ':': case '=': vars = string_split(lines.at(i), '\t', 1); packet->addVar(new psyc::Var((lastvar = vars[0].substr(1, std::string::npos)), vars[1], ((vars[0][0] == '=') ? true : false))); break; // mc case '_': packet->setMc(lines[i]); break; // message content default: for (; i < lines.size()-1; i++) { message += lines[i] + "\n"; } packet->setMessage(message); break; } } std::cout << packet->print(); }