Esempio n. 1
0
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);
}
Esempio n. 2
0
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);
}
Esempio n. 3
0
String EmotHandler::prepareBody(const StringRef& body, bool encode, bool html) {
  RegEx reg;
  reg.setSubject(body);

  if (encode) {
    reg.replaceItself(html ? "/&amp;/" : "/&/", "\1");
    reg.replaceItself(html ? "/&lt;/" : "/</", "\2");
    reg.replaceItself(html ? "/&gt;/" : "/>/", "\3");
    reg.replaceItself(html ? "/&quot;/" : "/\"/", "\4");
    reg.replaceItself(html ? "/&(apos|#0?39);/" : "/'/", "\5");
  } else {
    reg.replaceItself("/\1/", html ? "&amp;" : "/&/");
    reg.replaceItself("/\2/", html ? "&lt;" : "/</");
    reg.replaceItself("/\3/", html ? "&gt;" : "/>/");
    reg.replaceItself("/\4/", html ? "&quot;" : "/\"/");
    reg.replaceItself("/\5/", html ? "&#039;" : "/'/");
  }
  return reg.getSubject();
}