|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r63074 - branches/filesystem3/boost/io
From: bdawes_at_[hidden]
Date: 2010-06-17 20:59:41
Author: bemandawes
Date: 2010-06-17 20:59:40 EDT (Thu, 17 Jun 2010)
New Revision: 63074
URL: http://svn.boost.org/trac/boost/changeset/63074
Log:
Accept a number of Eric Niebler's suggestions, including renaming.
Added:
branches/filesystem3/boost/io/quoted_manip.hpp
- copied, changed from r63042, /branches/filesystem3/boost/io/quote_manip.hpp
Removed:
branches/filesystem3/boost/io/quote_manip.hpp
Text files modified:
branches/filesystem3/boost/io/quoted_manip.hpp | 117 ++++++++++++++++-----------------------
1 files changed, 48 insertions(+), 69 deletions(-)
Deleted: branches/filesystem3/boost/io/quote_manip.hpp
==============================================================================
--- branches/filesystem3/boost/io/quote_manip.hpp 2010-06-17 20:59:40 EDT (Thu, 17 Jun 2010)
+++ (empty file)
@@ -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 <istream>
-#include <ostream>
-#include <string>
-#include <boost/io/ios_state.hpp>
-
-namespace boost
-{
- namespace io
- {
- namespace detail { // forward declare the helpers
- template <class Char, class Traits, class Alloc> struct quote_proxy;
- template <class Char> struct c_str_quote_proxy;
- template <class Char, class Traits, class Alloc> struct unquote_proxy;
- }
-
- // ------------ public interface ------------------------------------------------//
-
- template <class Char, class Traits, class Alloc>
- detail::quote_proxy<Char, Traits, Alloc>
- quote(const std::basic_string<Char, Traits, Alloc>& s,
- Char escape='\\', Char delim='\"');
-
- template <class Char>
- detail::c_str_quote_proxy<Char>
- quote(const Char* s, Char escape='\\', Char delim='\"');
-
- template <class Char, class Traits, class Alloc>
- detail::unquote_proxy<Char, Traits, Alloc>
- unquote(std::basic_string<Char, Traits, Alloc>& s,
- Char escape='\\', Char delim='\"');
-
- // ----------- implementation details -------------------------------------------//
-
- namespace detail
- {
- // string inserter helpers
-
- template <class Char, class Traits, class Alloc>
- struct quote_proxy
- {
- const std::basic_string<Char, Traits, Alloc>& s;
- Char escape;
- Char delim;
-
- quote_proxy(const std::basic_string<Char, Traits, Alloc>& s_,
- Char escape_, Char delim_)
- : s(s_), escape(escape_), delim(delim_) {}
- };
-
- template <class Char, class Traits, class Alloc>
- std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& os,
- quote_proxy<Char, Traits, Alloc>& proxy)
- {
- os << proxy.delim;
- std::basic_string<Char, Traits, Alloc>::const_iterator end_it = proxy.s.end();
- for (std::basic_string<Char, Traits, Alloc>::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 <class Char>
- 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 <class Char, class Traits>
- std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& os,
- c_str_quote_proxy<Char>& 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 <class Char, class Traits, class Alloc>
- struct unquote_proxy
- {
- std::basic_string<Char, Traits, Alloc>& s;
- Char escape;
- Char delim;
-
- unquote_proxy(std::basic_string<Char, Traits, Alloc>& s_,
- Char escape_, Char delim_)
- : s(s_), escape(escape_), delim(delim_) {}
- };
-
- template <class Char, class Traits, class Alloc>
- std::basic_istream<Char, Traits>& operator>>(std::basic_istream<Char, Traits>& is,
- unquote_proxy<Char, Traits, Alloc>& 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 <class Char, class Traits, class Alloc>
- inline detail::quote_proxy<Char, Traits, Alloc>
- quote(const std::basic_string<Char, Traits, Alloc>& s, Char escape, Char delim)
- {
- return detail::quote_proxy<Char, Traits, Alloc>(s, escape, delim);
- }
-
- template <class Char>
- inline detail::c_str_quote_proxy<Char>
- quote(const Char* s, Char escape, Char delim)
- {
- return detail::c_str_quote_proxy<Char>(s, escape, delim);
- }
-
- template <class Char, class Traits, class Alloc>
- inline detail::unquote_proxy<Char, Traits, Alloc>
- unquote(std::basic_string<Char, Traits, Alloc>& s, Char escape, Char delim)
- {
- return detail::unquote_proxy<Char, Traits, Alloc>(s, escape, delim);
- }
-
- } // namespace io
-} // namespace boost
-
-#endif // BOOST_QUOTE_MANIP
Copied: branches/filesystem3/boost/io/quoted_manip.hpp (from r63042, /branches/filesystem3/boost/io/quote_manip.hpp)
==============================================================================
--- /branches/filesystem3/boost/io/quote_manip.hpp (original)
+++ branches/filesystem3/boost/io/quoted_manip.hpp 2010-06-17 20:59:40 EDT (Thu, 17 Jun 2010)
@@ -8,8 +8,7 @@
#ifndef BOOST_QUOTE_MANIP
#define BOOST_QUOTE_MANIP
-#include <istream>
-#include <ostream>
+#include <iosfwd>
#include <string>
#include <boost/io/ios_state.hpp>
@@ -17,53 +16,47 @@
{
namespace io
{
- namespace detail { // forward declare the helpers
- template <class Char, class Traits, class Alloc> struct quote_proxy;
- template <class Char> struct c_str_quote_proxy;
- template <class Char, class Traits, class Alloc> struct unquote_proxy;
- }
+ namespace detail { template <class String, class Char> struct quoted_proxy; }
// ------------ public interface ------------------------------------------------//
template <class Char, class Traits, class Alloc>
- detail::quote_proxy<Char, Traits, Alloc>
- quote(const std::basic_string<Char, Traits, Alloc>& s,
- Char escape='\\', Char delim='\"');
+ detail::quoted_proxy<std::basic_string<Char, Traits, Alloc> const &, Char>
+ quoted(const std::basic_string<Char, Traits, Alloc>& s,
+ Char escape='\\', Char delim='\"');
template <class Char>
- detail::c_str_quote_proxy<Char>
- quote(const Char* s, Char escape='\\', Char delim='\"');
+ detail::quoted_proxy<const Char*, Char>
+ quoted(const Char* s, Char escape='\\', Char delim='\"');
template <class Char, class Traits, class Alloc>
- detail::unquote_proxy<Char, Traits, Alloc>
- unquote(std::basic_string<Char, Traits, Alloc>& s,
- Char escape='\\', Char delim='\"');
+ detail::quoted_proxy<std::basic_string<Char, Traits, Alloc> &, Char>
+ quoted(std::basic_string<Char, Traits, Alloc>& s,
+ Char escape='\\', Char delim='\"');
// ----------- implementation details -------------------------------------------//
namespace detail
{
- // string inserter helpers
- template <class Char, class Traits, class Alloc>
- struct quote_proxy
+ template <class String, class Char>
+ struct quoted_proxy
{
- const std::basic_string<Char, Traits, Alloc>& s;
- Char escape;
- Char delim;
-
- quote_proxy(const std::basic_string<Char, Traits, Alloc>& s_,
- Char escape_, Char delim_)
- : s(s_), escape(escape_), delim(delim_) {}
+ String string;
+ Char escape;
+ Char delim;
+
+ quoted_proxy(String s_, Char escape_, Char delim_)
+ : string(s_), escape(escape_), delim(delim_) {}
};
template <class Char, class Traits, class Alloc>
std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& os,
- quote_proxy<Char, Traits, Alloc>& proxy)
+ const quoted_proxy<std::basic_string<Char, Traits, Alloc> const &, Char>& proxy)
{
os << proxy.delim;
- std::basic_string<Char, Traits, Alloc>::const_iterator end_it = proxy.s.end();
- for (std::basic_string<Char, Traits, Alloc>::const_iterator it = proxy.s.begin();
+ std::basic_string<Char, Traits, Alloc>::const_iterator end_it = proxy.string.end();
+ for (std::basic_string<Char, Traits, Alloc>::const_iterator it = proxy.string.begin();
it != end_it;
++it )
{
@@ -75,25 +68,22 @@
return os;
}
- // c_str inserter helpers
-
- template <class Char>
- struct c_str_quote_proxy
+ template <class Char, class Traits, class Alloc>
+ inline
+ std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& os,
+ const quoted_proxy<std::basic_string<Char, Traits, Alloc>&, Char>& 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_) {}
- };
+ return os <<
+ *reinterpret_cast<const quoted_proxy<std::basic_string
+ <Char, Traits, Alloc> const &, Char>*>(&proxy);
+ }
template <class Char, class Traits>
std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& os,
- c_str_quote_proxy<Char>& proxy)
+ const quoted_proxy<const Char*, Char>& proxy)
{
os << proxy.delim;
- for (const Char* it = proxy.s;
+ for (const Char* it = proxy.string;
*it;
++it )
{
@@ -105,33 +95,19 @@
return os;
}
- // string extractor helpers
-
- template <class Char, class Traits, class Alloc>
- struct unquote_proxy
- {
- std::basic_string<Char, Traits, Alloc>& s;
- Char escape;
- Char delim;
-
- unquote_proxy(std::basic_string<Char, Traits, Alloc>& s_,
- Char escape_, Char delim_)
- : s(s_), escape(escape_), delim(delim_) {}
- };
-
template <class Char, class Traits, class Alloc>
std::basic_istream<Char, Traits>& operator>>(std::basic_istream<Char, Traits>& is,
- unquote_proxy<Char, Traits, Alloc>& proxy)
+ const quoted_proxy<std::basic_string<Char, Traits, Alloc>&, Char>& proxy)
{
Char c;
is >> c;
if (c != proxy.delim)
{
- proxy.s = c;
- is >> proxy.s;
+ proxy.string = c;
+ is >> proxy.string;
return is;
}
- proxy.s.clear();
+ proxy.string.clear();
{
boost::io::ios_flags_saver ifs(is);
is >> std::noskipws;
@@ -142,7 +118,7 @@
is >> c;
else if (c == proxy.delim)
break;
- proxy.s += c;
+ proxy.string += c;
}
}
return is;
@@ -153,24 +129,27 @@
// manipulator implementations
template <class Char, class Traits, class Alloc>
- inline detail::quote_proxy<Char, Traits, Alloc>
- quote(const std::basic_string<Char, Traits, Alloc>& s, Char escape, Char delim)
+ inline detail::quoted_proxy<std::basic_string<Char, Traits, Alloc> const &, Char>
+ quoted(const std::basic_string<Char, Traits, Alloc>& s, Char escape, Char delim)
{
- return detail::quote_proxy<Char, Traits, Alloc>(s, escape, delim);
+ return detail::quoted_proxy<std::basic_string<Char, Traits, Alloc> const &, Char>
+ (s, escape, delim);
}
template <class Char>
- inline detail::c_str_quote_proxy<Char>
- quote(const Char* s, Char escape, Char delim)
+ inline detail::quoted_proxy<const Char*, Char>
+ quoted(const Char* s, Char escape, Char delim)
{
- return detail::c_str_quote_proxy<Char>(s, escape, delim);
+ return detail::quoted_proxy<const Char*, Char> (s, escape, delim);
}
+
template <class Char, class Traits, class Alloc>
- inline detail::unquote_proxy<Char, Traits, Alloc>
- unquote(std::basic_string<Char, Traits, Alloc>& s, Char escape, Char delim)
+ inline detail::quoted_proxy<std::basic_string<Char, Traits, Alloc> &, Char>
+ quoted(std::basic_string<Char, Traits, Alloc>& s, Char escape, Char delim)
{
- return detail::unquote_proxy<Char, Traits, Alloc>(s, escape, delim);
+ return detail::quoted_proxy<std::basic_string<Char, Traits, Alloc>&, Char>
+ (s, escape, delim);
}
} // namespace io
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk