xml_parser_writer_settings.hpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. #include <string>
  14. #include <boost/property_tree/detail/ptree_utils.hpp>
  15. namespace boost { namespace property_tree { namespace xml_parser
  16. {
  17. // Naively convert narrow string to another character type
  18. template<class Str>
  19. Str widen(const char *text)
  20. {
  21. typedef typename Str::value_type Ch;
  22. Str result;
  23. while (*text)
  24. {
  25. result += Ch(*text);
  26. ++text;
  27. }
  28. return result;
  29. }
  30. //! Xml writer settings. The default settings lead to no pretty printing.
  31. template<class Str>
  32. class xml_writer_settings
  33. {
  34. typedef typename Str::value_type Ch;
  35. public:
  36. xml_writer_settings(Ch inchar = Ch(' '),
  37. typename Str::size_type incount = 0,
  38. const Str &enc = widen<Str>("utf-8"))
  39. : indent_char(inchar)
  40. , indent_count(incount)
  41. , encoding(enc)
  42. {
  43. }
  44. Ch indent_char;
  45. typename Str::size_type indent_count;
  46. Str encoding;
  47. };
  48. template <class Str>
  49. xml_writer_settings<Str> xml_writer_make_settings(typename Str::value_type indent_char = (typename Str::value_type)(' '),
  50. typename Str::size_type indent_count = 0,
  51. const Str &encoding = widen<Str>("utf-8"))
  52. {
  53. return xml_writer_settings<Str>(indent_char, indent_count, encoding);
  54. }
  55. } } }
  56. #endif