Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r63042 - in branches/filesystem3: boost boost/io libs/filesystem/v3/test
From: bdawes_at_[hidden]
Date: 2010-06-17 12:09:51


Author: bemandawes
Date: 2010-06-17 12:09:50 EDT (Thu, 17 Jun 2010)
New Revision: 63042
URL: http://svn.boost.org/trac/boost/changeset/63042

Log:
Move header, provide all template parameters, clean up code
Added:
   branches/filesystem3/boost/io/quote_manip.hpp (contents, props changed)
   branches/filesystem3/libs/filesystem/v3/test/quote_string_test.cpp
      - copied, changed from r63017, /branches/filesystem3/libs/filesystem/v3/test/delim_string_test.cpp
Removed:
   branches/filesystem3/boost/delimit_string.hpp
   branches/filesystem3/libs/filesystem/v3/test/delim_string_test.cpp
Text files modified:
   branches/filesystem3/libs/filesystem/v3/test/quote_string_test.cpp | 28 +++++++++++++++-------------
   1 files changed, 15 insertions(+), 13 deletions(-)

Deleted: branches/filesystem3/boost/delimit_string.hpp
==============================================================================
--- branches/filesystem3/boost/delimit_string.hpp 2010-06-17 12:09:50 EDT (Thu, 17 Jun 2010)
+++ (empty file)
@@ -1,149 +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_DELIMIT_STRING
-#define BOOST_DELIMIT_STRING
-
-#include <istream>
-#include <ostream>
-#include <string>
-#include <boost/io/ios_state.hpp>
-
-namespace boost
-{
- namespace detail
- {
- // inserter support
-
- template <class String>
- struct const_proxy
- {
- typedef typename String::value_type value_type;
- const String& s;
- value_type escape;
- value_type delim;
- const_proxy(const String& s_, value_type escape_, value_type delim_)
- : s(s_), escape(escape_), delim(delim_) {}
- };
-
- template <class String>
- std::basic_ostream<typename String::value_type>&
- operator<<(std::basic_ostream<typename String::value_type>& os,
- const detail::const_proxy<String>& prox)
- {
- os << prox.delim;
- typename String::const_iterator end_it = prox.s.end();
- for (typename String::const_iterator it = prox.s.begin();
- it != end_it;
- ++it )
- {
- if (*it == prox.delim || *it == prox.escape)
- os << prox.escape;
- os << *it;
- }
- os << prox.delim;
- return os;
- }
-
- template <class Char>
- struct c_str_proxy
- {
- const Char* s;
- Char escape;
- Char delim;
- c_str_proxy(const Char* s_, Char escape_, Char delim_)
- : s(s_), escape(escape_), delim(delim_) {}
- };
-
- template <class Char>
- std::basic_ostream<Char>&
- operator<<(std::basic_ostream<Char>& os, const detail::c_str_proxy<Char>& prox)
- {
- os << prox.delim;
- for (const Char* it = prox.s;
- *it;
- ++it )
- {
- if (*it == prox.delim || *it == prox.escape)
- os << prox.escape;
- os << *it;
- }
- os << prox.delim;
- return os;
- }
-
- // extractor support
-
- template <class String>
- struct proxy
- {
- typedef typename String::value_type value_type;
- String& s;
- value_type escape;
- value_type delim;
- proxy(String& s_, value_type escape_, value_type delim_)
- : s(s_), escape(escape_), delim(delim_) {}
- };
-
- template <class String>
- std::basic_istream<typename String::value_type>&
- operator>>(std::basic_istream<typename String::value_type>& is,
- const detail::proxy<String>& prox)
- {
- typename String::value_type c;
- is >> c;
- if (c != prox.delim)
- {
- prox.s = c;
- is >> prox.s;
- return is;
- }
- prox.s.clear();
- {
- boost::io::ios_flags_saver ifs(is);
- is >> std::noskipws;
- for (;;)
- {
- is >> c;
- if (c == prox.escape)
- is >> c;
- else if (c == prox.delim)
- break;
- prox.s += c;
- }
- }
- return is;
- }
-
- } // namespace detail
-
- template <class String>
- inline detail::const_proxy<String> delimit(const String& s,
- typename String::value_type escape='\\',
- typename String::value_type delim='\"')
- {
- return detail::const_proxy<String>(s, escape, delim);
- }
-
- template <class Char>
- inline detail::c_str_proxy<Char> delimit(const Char* s,
- Char escape='\\',
- Char delim='\"')
- {
- return detail::c_str_proxy<Char>(s, escape, delim);
- }
-
- template <class String>
- inline detail::proxy<String> undelimit(String& s,
- typename String::value_type escape='\\',
- typename String::value_type delim='\"')
- {
- return detail::proxy<String>(s, escape, delim);
- }
-} // namespace boost
-
-#endif // BOOST_DELIMIT_STRING

Added: branches/filesystem3/boost/io/quote_manip.hpp
==============================================================================
--- (empty file)
+++ branches/filesystem3/boost/io/quote_manip.hpp 2010-06-17 12:09:50 EDT (Thu, 17 Jun 2010)
@@ -0,0 +1,179 @@
+// 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

Deleted: branches/filesystem3/libs/filesystem/v3/test/delim_string_test.cpp
==============================================================================
--- branches/filesystem3/libs/filesystem/v3/test/delim_string_test.cpp 2010-06-17 12:09:50 EDT (Thu, 17 Jun 2010)
+++ (empty file)
@@ -1,39 +0,0 @@
-#include <boost/delimit_string.hpp>
-#include <iostream>
-#include <sstream>
-#include <cassert>
-
-using boost::delimit;
-using boost::undelimit;
-
-int main()
-{
- std::cout << delimit("foo\\bar, \" *") << std::endl;
- std::cout << delimit("foo & bar, \" *", '&') << std::endl;
- std::cout << delimit("foo & bar, * ", '&', '*') << std::endl;
-
- std::wcout << delimit(L"foo$bar, \" *", L'$') << std::endl;
-
- std::string non_const_string("non_const_string");
- std::cout << delimit(non_const_string) << '\n';
-
- std::stringstream ss;
-
- const std::string expected("foo\\bar, \" *");
- std::string actual;
-
- ss << delimit(expected);
- ss >> undelimit(actual);
-
- std::cout << "round trip tests...\n";
- std::cout << " expected--: " << expected << '\n';
- std::cout << " actual----: " << actual << '\n';
-
- assert(expected == actual);
-
- // each of these should fail to compile because they are const:
- // ss >> undelimit(expected);
- // ss >> undelimit("foo");
-
- return 0;
-}

Copied: branches/filesystem3/libs/filesystem/v3/test/quote_string_test.cpp (from r63017, /branches/filesystem3/libs/filesystem/v3/test/delim_string_test.cpp)
==============================================================================
--- /branches/filesystem3/libs/filesystem/v3/test/delim_string_test.cpp (original)
+++ branches/filesystem3/libs/filesystem/v3/test/quote_string_test.cpp 2010-06-17 12:09:50 EDT (Thu, 17 Jun 2010)
@@ -1,29 +1,31 @@
-#include <boost/delimit_string.hpp>
+#include <boost/io/quote_manip.hpp>
 #include <iostream>
 #include <sstream>
 #include <cassert>
 
-using boost::delimit;
-using boost::undelimit;
+using boost::io::quote;
+using boost::io::unquote;
 
 int main()
 {
- std::cout << delimit("foo\\bar, \" *") << std::endl;
- std::cout << delimit("foo & bar, \" *", '&') << std::endl;
- std::cout << delimit("foo & bar, * ", '&', '*') << std::endl;
 
- std::wcout << delimit(L"foo$bar, \" *", L'$') << std::endl;
+ std::cout << quote(std::string("foo\\bar, \" *")) << std::endl;
+ std::cout << quote("foo\\bar, \" *") << std::endl;
+ std::cout << quote("foo & bar, \" *", '&') << std::endl;
+ std::cout << quote("foo & bar, * ", '&', '*') << std::endl;
+
+ std::wcout << quote(L"foo$bar, \" *", L'$') << std::endl;
 
   std::string non_const_string("non_const_string");
- std::cout << delimit(non_const_string) << '\n';
+ std::cout << quote(non_const_string) << '\n';
 
   std::stringstream ss;
 
   const std::string expected("foo\\bar, \" *");
   std::string actual;
 
- ss << delimit(expected);
- ss >> undelimit(actual);
+ ss << quote(expected);
+ ss >> unquote(actual);
 
   std::cout << "round trip tests...\n";
   std::cout << " expected--: " << expected << '\n';
@@ -31,9 +33,9 @@
 
   assert(expected == actual);
 
- // each of these should fail to compile because they are const:
- // ss >> undelimit(expected);
- // ss >> undelimit("foo");
+ // these should fail to compile because the arguments are non-const:
+ // ss >> unquote(expected);
+ // ss >> unquote("foo");
 
   return 0;
 }


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