From fa2be5fde6bc9549c27d43145b24ec2ea2b59cb4 Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Fri, 18 Jun 2010 00:59:40 +0000 Subject: [PATCH] Accept a number of Eric Niebler's suggestions, including renaming. [SVN r63074] --- include/boost/io/quote_manip.hpp | 179 ------------------------------ include/boost/io/quoted_manip.hpp | 158 ++++++++++++++++++++++++++ 2 files changed, 158 insertions(+), 179 deletions(-) delete mode 100644 include/boost/io/quote_manip.hpp create mode 100644 include/boost/io/quoted_manip.hpp diff --git a/include/boost/io/quote_manip.hpp b/include/boost/io/quote_manip.hpp deleted file mode 100644 index 3a98ca0..0000000 --- a/include/boost/io/quote_manip.hpp +++ /dev/null @@ -1,179 +0,0 @@ -// Copyright Beman Dawes 2010 - -// Distributed under the Boost Software License, Version 1.0. -// See http://www.boost.org/LICENSE_1_0.txt - -//--------------------------------------------------------------------------------------// - -#ifndef BOOST_QUOTE_MANIP -#define BOOST_QUOTE_MANIP - -#include -#include -#include -#include - -namespace boost -{ - namespace io - { - namespace detail { // forward declare the helpers - template struct quote_proxy; - template struct c_str_quote_proxy; - template struct unquote_proxy; - } - - // ------------ public interface ------------------------------------------------// - - template - detail::quote_proxy - quote(const std::basic_string& s, - Char escape='\\', Char delim='\"'); - - template - detail::c_str_quote_proxy - quote(const Char* s, Char escape='\\', Char delim='\"'); - - template - detail::unquote_proxy - unquote(std::basic_string& s, - Char escape='\\', Char delim='\"'); - - // ----------- implementation details -------------------------------------------// - - namespace detail - { - // string inserter helpers - - template - struct quote_proxy - { - const std::basic_string& s; - Char escape; - Char delim; - - quote_proxy(const std::basic_string& s_, - Char escape_, Char delim_) - : s(s_), escape(escape_), delim(delim_) {} - }; - - template - std::basic_ostream& operator<<(std::basic_ostream& os, - quote_proxy& proxy) - { - os << proxy.delim; - std::basic_string::const_iterator end_it = proxy.s.end(); - for (std::basic_string::const_iterator it = proxy.s.begin(); - it != end_it; - ++it ) - { - if (*it == proxy.delim || *it == proxy.escape) - os << proxy.escape; - os << *it; - } - os << proxy.delim; - return os; - } - - // c_str inserter helpers - - template - struct c_str_quote_proxy - { - const Char* s; - Char escape; - Char delim; - - c_str_quote_proxy(const Char* s_, Char escape_, Char delim_) - : s(s_), escape(escape_), delim(delim_) {} - }; - - template - std::basic_ostream& operator<<(std::basic_ostream& os, - c_str_quote_proxy& proxy) - { - os << proxy.delim; - for (const Char* it = proxy.s; - *it; - ++it ) - { - if (*it == proxy.delim || *it == proxy.escape) - os << proxy.escape; - os << *it; - } - os << proxy.delim; - return os; - } - - // string extractor helpers - - template - struct unquote_proxy - { - std::basic_string& s; - Char escape; - Char delim; - - unquote_proxy(std::basic_string& s_, - Char escape_, Char delim_) - : s(s_), escape(escape_), delim(delim_) {} - }; - - template - std::basic_istream& operator>>(std::basic_istream& is, - unquote_proxy& proxy) - { - Char c; - is >> c; - if (c != proxy.delim) - { - proxy.s = c; - is >> proxy.s; - return is; - } - proxy.s.clear(); - { - boost::io::ios_flags_saver ifs(is); - is >> std::noskipws; - for (;;) - { - is >> c; - if (c == proxy.escape) - is >> c; - else if (c == proxy.delim) - break; - proxy.s += c; - } - } - return is; - } - - } // namespace detail - - // manipulator implementations - - template - inline detail::quote_proxy - quote(const std::basic_string& s, Char escape, Char delim) - { - return detail::quote_proxy(s, escape, delim); - } - - template - inline detail::c_str_quote_proxy - quote(const Char* s, Char escape, Char delim) - { - return detail::c_str_quote_proxy(s, escape, delim); - } - - template - inline detail::unquote_proxy - unquote(std::basic_string& s, Char escape, Char delim) - { - return detail::unquote_proxy(s, escape, delim); - } - - } // namespace io -} // namespace boost - -#endif // BOOST_QUOTE_MANIP diff --git a/include/boost/io/quoted_manip.hpp b/include/boost/io/quoted_manip.hpp new file mode 100644 index 0000000..325f14b --- /dev/null +++ b/include/boost/io/quoted_manip.hpp @@ -0,0 +1,158 @@ +// Copyright Beman Dawes 2010 + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +//--------------------------------------------------------------------------------------// + +#ifndef BOOST_QUOTE_MANIP +#define BOOST_QUOTE_MANIP + +#include +#include +#include + +namespace boost +{ + namespace io + { + namespace detail { template struct quoted_proxy; } + + // ------------ public interface ------------------------------------------------// + + template + detail::quoted_proxy const &, Char> + quoted(const std::basic_string& s, + Char escape='\\', Char delim='\"'); + + template + detail::quoted_proxy + quoted(const Char* s, Char escape='\\', Char delim='\"'); + + template + detail::quoted_proxy &, Char> + quoted(std::basic_string& s, + Char escape='\\', Char delim='\"'); + + // ----------- implementation details -------------------------------------------// + + namespace detail + { + + template + struct quoted_proxy + { + String string; + Char escape; + Char delim; + + quoted_proxy(String s_, Char escape_, Char delim_) + : string(s_), escape(escape_), delim(delim_) {} + }; + + template + std::basic_ostream& operator<<(std::basic_ostream& os, + const quoted_proxy const &, Char>& proxy) + { + os << proxy.delim; + std::basic_string::const_iterator end_it = proxy.string.end(); + for (std::basic_string::const_iterator it = proxy.string.begin(); + it != end_it; + ++it ) + { + if (*it == proxy.delim || *it == proxy.escape) + os << proxy.escape; + os << *it; + } + os << proxy.delim; + return os; + } + + template + inline + std::basic_ostream& operator<<(std::basic_ostream& os, + const quoted_proxy&, Char>& proxy) + { + return os << + *reinterpret_cast const &, Char>*>(&proxy); + } + + template + std::basic_ostream& operator<<(std::basic_ostream& os, + const quoted_proxy& proxy) + { + os << proxy.delim; + for (const Char* it = proxy.string; + *it; + ++it ) + { + if (*it == proxy.delim || *it == proxy.escape) + os << proxy.escape; + os << *it; + } + os << proxy.delim; + return os; + } + + template + std::basic_istream& operator>>(std::basic_istream& is, + const quoted_proxy&, Char>& proxy) + { + Char c; + is >> c; + if (c != proxy.delim) + { + proxy.string = c; + is >> proxy.string; + return is; + } + proxy.string.clear(); + { + boost::io::ios_flags_saver ifs(is); + is >> std::noskipws; + for (;;) + { + is >> c; + if (c == proxy.escape) + is >> c; + else if (c == proxy.delim) + break; + proxy.string += c; + } + } + return is; + } + + } // namespace detail + + // manipulator implementations + + template + inline detail::quoted_proxy const &, Char> + quoted(const std::basic_string& s, Char escape, Char delim) + { + return detail::quoted_proxy const &, Char> + (s, escape, delim); + } + + template + inline detail::quoted_proxy + quoted(const Char* s, Char escape, Char delim) + { + return detail::quoted_proxy (s, escape, delim); + } + + + template + inline detail::quoted_proxy &, Char> + quoted(std::basic_string& s, Char escape, Char delim) + { + return detail::quoted_proxy&, Char> + (s, escape, delim); + } + + } // namespace io +} // namespace boost + +#endif // BOOST_QUOTE_MANIP