static void read_xml(std::istream & in, PTree & node, Include * include, std::string key) { std::string line, escape("/"+node.value()); while (in.good()) { std::getline(in, line, '\n'); if (line.empty()) { continue; } size_t begin = line.find_first_not_of(" \t\n<"); size_t end = line.length(); if (begin >= end || line[begin] == '!') { continue; } line = line.substr(begin, end); if (line.find(escape) == 0) { break; } if (key.length() == 0) { end = line.find(" "); key = line.substr(0, end); continue; } size_t next = line.find("</"+key); if (next < end) { // New property. std::string value = line.substr(0, next); // Include? if (include && key == "include") { (*include)(node, value); } else { node.set(key, value); } } else { // New node. end = line.find(" "); std::string child_key = line.substr(0, end); read_xml(in, node.set(key, PTree()), include, child_key); } key.clear(); } }
void read(PTree & node) { std::string line, name; while (in.good()) { std::getline(in, line, '\n'); if (line.empty()) { continue; } size_t begin = line.find_first_not_of(" \t["); size_t end = line.find_first_of(";#]\r", begin); if (begin >= end) { continue; } size_t next = line.find("=", begin); if (next >= end) { // New node. next = line.find_last_not_of(" \t\r]", end); name = line.substr(begin, next); read(root.set(name, PTree())); continue; } size_t next2 = line.find_first_not_of(" \t\r", next+1); next = line.find_last_not_of(" \t", next-1); if (next2 >= end) continue; name = line.substr(begin, next+1); if (!fopen || line.at(next2) != '&') { // New property. std::string value = line.substr(next2, end-next2); node.set(name, value); continue; } // Value is a reference. std::string value = line.substr(next2+1, end-next2-1); const PTree * ref_ptr; if (root.get(value, ref_ptr) || cache.get(value, ref_ptr)) { node.set(name, *ref_ptr); continue; } // Load external reference. PTree ref; read_ini(value, *fopen, ref); cache.set(value, ref); node.set(name, ref); } }
static void read_inf(std::istream & in, PTree & node, Include * include, bool child) { std::string line, name; while (in.good()) { std::getline(in, line, '\n'); if (line.empty()) { continue; } size_t begin = line.find_first_not_of(" \t"); size_t end = line.find_first_of(";#"); if (begin >= end) { continue; } line = line.substr(begin, end); if (line[0] == '{' && name.length()) { // New node. read_inf(in, node.set(name, PTree()), include, true); continue; } if (line[0] == '}' && child) { break; } size_t next = line.find(" "); end = line.length(); name = line.substr(0, next); if (next < end) { // New property. std::string value = line.substr(next+1, end); // Include? if (include && name == "include") { (*include)(node, value); } else { node.set(name, value); } name.clear(); } } }
static void read_xml(std::istream & in, PTree & p, std::string key) { std::string line, escape("/"+p.value()); while (in.good()) { std::getline(in, line, '\n'); if (line.empty()) { continue; } size_t begin = line.find_first_not_of(" \t\n<"); size_t end = line.length(); if (begin >= end || line[begin] == '!') { continue; } line = line.substr(begin, end); if (line.find(escape) == 0) { break; } if (key.length() == 0) { end = line.find(" "); key = line.substr(0, end); continue; } size_t next = line.find("</"+key); if (next < end) { std::string value = line.substr(0, next); p.set(key, value); } else { end = line.find(" "); std::string child_key = line.substr(0, end); read_xml(in, p.set(key, PTree()), child_key); } key.clear(); } }
void operator()(PTree & node, std::string & value) { std::tr1::shared_ptr<PTree> sptr; if (content.load(sptr, path, value)) { node.set(*sptr); } }