iPackage* GGParser::parse(const FindFile::Found& defFile) { ifstream file(defFile.getFilePath().c_str()); string buff; if (!file.is_open()) { throw CannotOpen("Cannot open file " + defFile.getFilePath()); } bool inMenu; eMSet result; RegEx reg; while (!file.eof()) { getline(file, buff); eMSet::tEmots emots; if (buff[0] == '*') { inMenu = false; buff.erase(0); } else { inMenu = true; } reg.setSubject(buff); reg.setPattern("/,?\"(.+?)\",?/"); while (reg.match_global()) { eM emot(inMenu, reg[1][0] == '/'); emot.setText(reg[1].c_str()); emots.push_back(emot); if (reg.getSubject()[reg.getStart()] == ')' || buff[0] != '(') { string img_path; string menu_img_path; if (reg.match_global()) { img_path = reg[1]; menu_img_path = reg.match_global() ? reg[1] : ""; for (eMSet::tEmots::iterator it = emots.begin(); it != emots.end(); it++) { if (menu_img_path.length()) it->setMenuImgPath(defFile.getDirectory() + menu_img_path); it->setImgPath(defFile.getDirectory() + img_path); } } else { throw WrongFormat("Brak œcie¿ki do obrazka"); } break; } } result.getEmots().insert(result.getEmots().end(), emots.begin(), emots.end()); } file.close(); return new eMSet(result); }
String EmotHandler::parse(const StringRef& body) { RegEx reg; reg.setSubject(prepareBody(body)); for (tPackages::iterator it = _packages.begin(); it != _packages.end(); it++) { parseSet(reg, (eMSet&) **it); } reg.replaceItself("#<kiev2:emot:insertion id=\"([0-9]+)\" />#", &EmotHandler::replaceEmot, 0, (void*) this); emotInsertions.clear(); return prepareBody(reg.getSubject(), false); }
String EmotHandler::prepareBody(const StringRef& body, bool encode, bool html) { RegEx reg; reg.setSubject(body); if (encode) { reg.replaceItself(html ? "/&/" : "/&/", "\1"); reg.replaceItself(html ? "/</" : "/</", "\2"); reg.replaceItself(html ? "/>/" : "/>/", "\3"); reg.replaceItself(html ? "/"/" : "/\"/", "\4"); reg.replaceItself(html ? "/&(apos|#0?39);/" : "/'/", "\5"); } else { reg.replaceItself("/\1/", html ? "&" : "/&/"); reg.replaceItself("/\2/", html ? "<" : "/</"); reg.replaceItself("/\3/", html ? ">" : "/>/"); reg.replaceItself("/\4/", html ? """ : "/\"/"); reg.replaceItself("/\5/", html ? "'" : "/'/"); } return reg.getSubject(); }