Beispiel #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);
}
Beispiel #2
0
void EmotHandler::parseSet(RegEx& reg, eMSet& set) {
  if (!set.isEnabled()) return;

  for (eMSet::tEmots::iterator it = set.getEmots().begin(); it != set.getEmots().end(); it++) {
    sEmotInsertion ei(emotInsertions.size(), &*it, &set);
    try {
      reg.setPattern(prepareBody(!it->isPreg() ? "/" + reg.addSlashes(it->getText()) + "/i" : it->getText(), true, false));
      reg.replaceItself(&EmotHandler::emotInsertion, 0, (void*) &ei);
    } catch (const RegEx::CompileException& e) {
      IMLOG("[EmotHandler::parseSet()] B³¹d definicji emotikony: %s, pos %i", e.error, e.pos);
      continue;
    }
    emotInsertions.push_back(ei);
  }
}