/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. #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 Ch>
  19. std::basic_string<Ch> widen(const char *text)
  20. {
  21. std::basic_string<Ch> result;
  22. while (*text)
  23. {
  24. result += Ch(*text);
  25. ++text;
  26. }
  27. return result;
  28. }
  29. //! Xml writer settings. The default settings lead to no pretty printing.
  30. template<class Ch>
  31. class xml_writer_settings
  32. {
  33. public:
  34. xml_writer_settings(Ch inchar = Ch(' '),
  35. typename std::basic_string<Ch>::size_type incount = 0,
  36. const std::basic_string<Ch> &enc = widen<Ch>("utf-8"))
  37. : indent_char(inchar)
  38. , indent_count(incount)
  39. , encoding(enc)
  40. {
  41. }
  42. Ch indent_char;
  43. typename std::basic_string<Ch>::size_type indent_count;
  44. std::basic_string<Ch> encoding;
  45. };
  46. template <class Ch>
  47. xml_writer_settings<Ch> xml_writer_make_settings(Ch indent_char = Ch(' '),
  48. typename std::basic_string<Ch>::size_type indent_count = 0,
  49. const std::basic_string<Ch> &encoding = widen<Ch>("utf-8"))
  50. {
  51. return xml_writer_settings<Ch>(indent_char, indent_count, encoding);
  52. }
  53. } } }
  54. #endif