PageRenderTime 7ms CodeModel.GetById 2ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/property_tree/detail/xml_parser_writer_settings.hpp

http://hadesmem.googlecode.com/
C++ Header | 62 lines | 42 code | 8 blank | 12 comment | 1 complexity | 7c365cd2b82026b0d3ab57138f7d3cfd MD5 | raw file
 1// ----------------------------------------------------------------------------
 2// Copyright (C) 2002-2007 Marcin Kalicinski
 3// Copyright (C) 2007 Alexey Baskakov
 4//
 5// Distributed under the Boost Software License, Version 1.0. 
 6// (See accompanying file LICENSE_1_0.txt or copy at 
 7// http://www.boost.org/LICENSE_1_0.txt)
 8//
 9// For more information, see www.boost.org
10// ----------------------------------------------------------------------------
11#ifndef BOOST_PROPERTY_TREE_DETAIL_XML_PARSER_WRITER_SETTINGS_HPP_INCLUDED
12#define BOOST_PROPERTY_TREE_DETAIL_XML_PARSER_WRITER_SETTINGS_HPP_INCLUDED
13
14#include <string>
15#include <boost/property_tree/detail/ptree_utils.hpp>
16
17namespace boost { namespace property_tree { namespace xml_parser
18{
19    
20    // Naively convert narrow string to another character type
21    template<class Ch>
22    std::basic_string<Ch> widen(const char *text)
23    {
24        std::basic_string<Ch> result;
25        while (*text)
26        {
27            result += Ch(*text);
28            ++text;
29        }
30        return result;
31    }
32
33    //! Xml writer settings. The default settings lead to no pretty printing.
34    template<class Ch>
35    class xml_writer_settings
36    {
37    public:
38        xml_writer_settings(Ch inchar = Ch(' '),
39                typename std::basic_string<Ch>::size_type incount = 0,
40                const std::basic_string<Ch> &enc = widen<Ch>("utf-8"))
41            : indent_char(inchar)
42            , indent_count(incount)
43            , encoding(enc)
44        {
45        }
46
47        Ch indent_char;
48        typename std::basic_string<Ch>::size_type indent_count;
49        std::basic_string<Ch> encoding;
50    };
51
52    template <class Ch>
53    xml_writer_settings<Ch> xml_writer_make_settings(Ch indent_char = Ch(' '),
54        typename std::basic_string<Ch>::size_type indent_count = 0,
55        const std::basic_string<Ch> &encoding = widen<Ch>("utf-8"))
56    {
57        return xml_writer_settings<Ch>(indent_char, indent_count, encoding);
58    }
59
60} } }
61
62#endif