Esempio n. 1
0
    virtual bool load(const char *filename) {
      string data;
      if(data.readfile(filename) == true) {
        data.replace("\r", "");
        lstring line;
        line.split("\n", data);

        for(unsigned i = 0; i < line.size(); i++) {
          int position = qstrpos(line[i], "#");
          if(position >= 0) line[i][position] = 0;
          if(qstrpos(line[i], " = ") < 0) continue;

          lstring part;
          part.qsplit(" = ", line[i]);
          trim(part[0]);
          trim(part[1]);

          for(unsigned n = 0; n < list.size(); n++) {
            if(part[0] == list[n].name) {
              list[n].set(part[1]);
              break;
            }
          }
        }

        return true;
      } else {
        return false;
      }
    }
Esempio n. 2
0
inline bool xml_element::parse_head(string data) {
  data.qreplace("\t", " ");
  data.qreplace("\r", " ");
  data.qreplace("\n", " ");
  while(qstrpos(data, "  ")) data.qreplace("  ", " ");
  data.qreplace(" =", "=");
  data.qreplace("= ", "=");
  data.rtrim();

  lstring part;
  part.qsplit(" ", data);

  name = part[0];
  if(name == "") throw "...";

  for(unsigned i = 1; i < part.size(); i++) {
    lstring side;
    side.qsplit("=", part[i]);
    if(side.size() != 2) throw "...";

    xml_attribute attr;
    attr.name = side[0];
    attr.content = side[1];
    if(strbegin(attr.content, "\"") && strend(attr.content, "\"")) attr.content.trim_once("\"");
    else if(strbegin(attr.content, "'") && strend(attr.content, "'")) attr.content.trim_once("'");
    else throw "...";
    attribute.append(attr);
  }

  return true;
}
Esempio n. 3
0
optional<unsigned> string::qposition(const char *key) const { return qstrpos(data, key); }
Esempio n. 4
0
maybe<unsigned> string::qfind(rstring key) const { return qstrpos(data(), key); }