void read_xml_node( pugi::xml_node node, Ptree &pt, int flags) { typedef typename Ptree::key_type::value_type Ch; switch ( node.type() ) { case pugi::node_element: { Ptree &tmp = pt.push_back(std::make_pair( node.name(), Ptree()))->second; for ( pugi::xml_attribute attr = node.first_attribute(); attr; attr = attr.next_attribute() ) tmp.put( xmlattr<Ch>() + "." + attr.name(), attr.value()); for ( pugi::xml_node child = node.first_child(); child; child = child.next_sibling()) read_xml_node(child, tmp, flags); } break; case pugi::node_pcdata: { if (flags & no_concat_text) pt.push_back(std::make_pair(xmltext<Ch>(), Ptree( node.value() ))); else pt.data() += node.value(); } break; case pugi::node_comment: { if (!(flags & no_comments)) pt.push_back(std::make_pair(xmlcomment<Ch>(), Ptree( node.value() ))); } break; default: // skip other types break; } }
void read_xml_node(detail::pdalboostrapidxml::xml_node<Ch> *node, Ptree &pt, int flags) { using namespace detail::pdalboostrapidxml; switch (node->type()) { // Element nodes case node_element: { // Create node Ptree &pt_node = pt.push_back(std::make_pair(node->name(), Ptree()))->second; // Copy attributes if (node->first_attribute()) { Ptree &pt_attr_root = pt_node.push_back( std::make_pair(xmlattr<typename Ptree::key_type>(), Ptree()))->second; for (xml_attribute<Ch> *attr = node->first_attribute(); attr; attr = attr->next_attribute()) { Ptree &pt_attr = pt_attr_root.push_back( std::make_pair(attr->name(), Ptree()))->second; pt_attr.data() = typename Ptree::key_type(attr->value(), attr->value_size()); } } // Copy children for (xml_node<Ch> *child = node->first_node(); child; child = child->next_sibling()) read_xml_node(child, pt_node, flags); } break; // Data nodes case node_data: case node_cdata: { if (flags & no_concat_text) pt.push_back(std::make_pair(xmltext<typename Ptree::key_type>(), Ptree(node->value()))); else pt.data() += typename Ptree::key_type(node->value(), node->value_size()); } break; // Comment nodes case node_comment: { if (!(flags & no_comments)) pt.push_back(std::make_pair(xmlcomment<typename Ptree::key_type>(), Ptree(typename Ptree::key_type(node->value(), node->value_size())))); } break; default: // Skip other node types break; } }
void operator()(Ch) const { if (c.stack.empty()) c.stack.push_back(&c.root); else { Ptree *parent = c.stack.back(); Ptree *child = &parent->push_back(std::make_pair(c.name, Ptree()))->second; c.stack.push_back(child); c.name.clear(); } }
void read_ini(std::basic_istream< typename Ptree::key_type::value_type> &stream, Ptree &pt) { typedef typename Ptree::key_type::value_type Ch; typedef std::basic_string<Ch> Str; const Ch semicolon = stream.widen(';'); const Ch hash = stream.widen('#'); const Ch lbracket = stream.widen('['); const Ch rbracket = stream.widen(']'); Ptree local; unsigned long line_no = 0; Ptree *section = 0; Str line; // For all lines while (stream.good()) { // Get line from stream ++line_no; std::getline(stream, line); if (!stream.good() && !stream.eof()) BOOST_PROPERTY_TREE_THROW(ini_parser_error( "read error", "", line_no)); // If line is non-empty line = property_tree::detail::trim(line, stream.getloc()); if (!line.empty()) { // Comment, section or key? if (line[0] == semicolon || line[0] == hash) { // Ignore comments } else if (line[0] == lbracket) { // If the previous section was empty, drop it again. if (section && section->empty()) local.pop_back(); typename Str::size_type end = line.find(rbracket); if (end == Str::npos) BOOST_PROPERTY_TREE_THROW(ini_parser_error( "unmatched '['", "", line_no)); Str key = property_tree::detail::trim( line.substr(1, end - 1), stream.getloc()); if (local.find(key) != local.not_found()) BOOST_PROPERTY_TREE_THROW(ini_parser_error( "duplicate section name", "", line_no)); section = &local.push_back( std::make_pair(key, Ptree()))->second; } else { Ptree &container = section ? *section : local; typename Str::size_type eqpos = line.find(Ch('=')); if (eqpos == Str::npos) BOOST_PROPERTY_TREE_THROW(ini_parser_error( "'=' character not found in line", "", line_no)); if (eqpos == 0) BOOST_PROPERTY_TREE_THROW(ini_parser_error( "key expected", "", line_no)); Str key = property_tree::detail::trim( line.substr(0, eqpos), stream.getloc()); Str data = property_tree::detail::trim( line.substr(eqpos + 1, Str::npos), stream.getloc()); if (container.find(key) != container.not_found()) BOOST_PROPERTY_TREE_THROW(ini_parser_error( "duplicate key name", "", line_no)); container.push_back(std::make_pair(key, Ptree(data))); } } } // If the last section was empty, drop it again. if (section && section->empty()) local.pop_back(); // Swap local ptree with result ptree pt.swap(local); }