Exemple #1
0
 std::basic_string<Ch> decode_char_entities(const std::basic_string<Ch> &s)
 {
     typedef typename std::basic_string<Ch> Str;
     Str r;
     typename Str::const_iterator end = s.end();
     for (typename Str::const_iterator it = s.begin(); it != end; ++it)
     {
         if (*it == Ch('&'))
         {
             typename Str::const_iterator semicolon = std::find(it + 1, end, Ch(';'));
             if (semicolon == end)
                 BOOST_PROPERTY_TREE_THROW(xml_parser_error("invalid character entity", "", 0));
             Str ent(it + 1, semicolon);
             if (ent == detail::widen<Ch>("lt")) r += Ch('<');
             else if (ent == detail::widen<Ch>("gt")) r += Ch('>');
             else if (ent == detail::widen<Ch>("amp")) r += Ch('&');
             else if (ent == detail::widen<Ch>("quot")) r += Ch('"');
             else if (ent == detail::widen<Ch>("apos")) r += Ch('\'');
             else
                 BOOST_PROPERTY_TREE_THROW(xml_parser_error("invalid character entity", "", 0));
             it = semicolon;
         }
         else
             r += *it;
     }
     return r;
 }
 void write_json_internal(std::basic_ostream<typename Ptree::key_type::value_type> &stream, 
                          const Ptree &pt,
                          const std::string &filename,
                          bool pretty)
 {
     if (!verify_json(pt, 0))
         BOOST_PROPERTY_TREE_THROW(json_parser_error("ptree contains data that cannot be represented in JSON format", filename, 0));
     write_json_helper(stream, pt, 0, pretty);
     stream << std::endl;
     if (!stream.good())
         BOOST_PROPERTY_TREE_THROW(json_parser_error("write error", filename, 0));
 }
 void write_info_internal(std::basic_ostream<typename Ptree::key_type::value_type> &stream, 
                          const Ptree &pt,
                          const std::string &filename,
                          const info_writer_settings<typename Ptree::key_type::value_type> &settings)
 {
     write_info_helper(stream, pt, -1, settings);
     if (!stream.good())
         BOOST_PROPERTY_TREE_THROW(info_parser_error("write error", filename, 0));
 }
Exemple #4
0
 void read_json(const std::string &filename,
                Ptree &pt,
                const std::locale &loc = std::locale())
 {
     std::basic_ifstream<typename Ptree::key_type::value_type>
         stream(filename.c_str());
     if (!stream)
         BOOST_PROPERTY_TREE_THROW(json_parser_error(
             "cannot open file", filename, 0));
     stream.imbue(loc);
     detail::read_json_internal(stream, pt, filename);
 }
Exemple #5
0
 void write_json(const std::string &filename,
                 const Ptree &pt,
                 const std::locale &loc = std::locale(),
                 bool pretty = true)
 {
     std::basic_ofstream<typename Ptree::key_type::value_type>
         stream(filename.c_str());
     if (!stream)
         BOOST_PROPERTY_TREE_THROW(json_parser_error(
             "cannot open file", filename, 0));
     stream.imbue(loc);
     write_json_internal(stream, pt, filename, pretty);
 }
 void read_info(const std::string &filename, Ptree &pt,
                const std::locale &loc = std::locale())
 {
     std::basic_ifstream<typename Ptree::key_type::value_type>
         stream(filename.c_str());
     if (!stream) {
         BOOST_PROPERTY_TREE_THROW(info_parser_error(
             "cannot open file for reading", filename, 0));
     }
     stream.imbue(loc);
     Ptree local;
     read_info_internal(stream, local, filename, 0);
     pt.swap(local);
 }
Exemple #7
0
 void read_xml(const std::string &filename,
               Ptree &pt,
               int flags = 0,
               const std::locale &loc = std::locale())
 {
     BOOST_ASSERT(validate_flags(flags));
     std::basic_ifstream<typename Ptree::key_type::value_type>
         stream(filename.c_str());
     if (!stream)
         BOOST_PROPERTY_TREE_THROW(xml_parser_error(
             "cannot open file", filename, 0));
     stream.imbue(loc);
     read_xml_internal(stream, pt, flags, filename);
 }
 void write_xml_internal(std::basic_ostream<typename Ptree::key_type::value_type> &stream, 
                         const Ptree &pt,
                         const std::string &filename,
                         const xml_writer_settings<typename Ptree::key_type::value_type> & settings)
 {
     typedef typename Ptree::key_type::value_type Ch;
     typedef typename std::basic_string<Ch> Str;
     stream  << detail::widen<Ch>("<?xml version=\"1.0\" encoding=\"")
             << settings.encoding
             << detail::widen<Ch>("\"?>\n");
     write_xml_element(stream, Str(), pt, -1, settings);
     if (!stream)
         BOOST_PROPERTY_TREE_THROW(xml_parser_error("write error", filename, 0));
 }
Exemple #9
0
 void write_xml(const std::string &filename,
                const Ptree &pt,
                const std::locale &loc = std::locale(),
                const xml_writer_settings<
                    typename Ptree::key_type
                > & settings = xml_writer_settings<typename Ptree::key_type>())
 {
     std::basic_ofstream<typename Ptree::key_type::value_type>
         stream(filename.c_str());
     if (!stream)
         BOOST_PROPERTY_TREE_THROW(xml_parser_error(
             "cannot open file", filename, 0));
     stream.imbue(loc);
     write_xml_internal(stream, pt, filename, settings);
 }
Exemple #10
0
 void check_dupes(const Ptree &pt)
 {
     if(pt.size() <= 1)
         return;
     const typename Ptree::key_type *lastkey = 0;
     typename Ptree::const_assoc_iterator it = pt.ordered_begin(),
                                          end = pt.not_found();
     lastkey = &it->first;
     for(++it; it != end; ++it) {
         if(*lastkey == it->first)
             BOOST_PROPERTY_TREE_THROW(ini_parser_error(
                 "duplicate key", "", 0));
         lastkey = &it->first;
     }
 }
    typename Translator::external_type string_path<String, Translator>::reduce()
    {
        assert(!empty() && "Reducing empty path");

        s_iter next_sep = std::find(m_start, m_value.end(), m_separator);
        String part(m_start, next_sep);
        m_start = next_sep;
        if(!empty()) {
          // Unless we're at the end, skip the separator we found.
          ++m_start;
        }

        if(optional<key_type> key = m_tr.get_value(part)) {
            return *key;
        }
        BOOST_PROPERTY_TREE_THROW(ptree_bad_path("Path syntax error", *this));
    }