|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r63015 - in branches/filesystem3: boost libs/filesystem/v3/test libs/filesystem/v3/test/msvc libs/filesystem/v3/test/msvc/delimit_string_test
From: bdawes_at_[hidden]
Date: 2010-06-16 07:08:57
Author: bemandawes
Date: 2010-06-16 07:08:55 EDT (Wed, 16 Jun 2010)
New Revision: 63015
URL: http://svn.boost.org/trac/boost/changeset/63015
Log:
delimit_string initial commit
Added:
branches/filesystem3/boost/delimit_string.hpp (contents, props changed)
branches/filesystem3/libs/filesystem/v3/test/delim_string_test.cpp (contents, props changed)
branches/filesystem3/libs/filesystem/v3/test/msvc/delimit_string_test/
branches/filesystem3/libs/filesystem/v3/test/msvc/delimit_string_test/delimit_string_test.vcproj (contents, props changed)
Text files modified:
branches/filesystem3/libs/filesystem/v3/test/msvc/filesystem-v3.sln | 10 ++++++++++
1 files changed, 10 insertions(+), 0 deletions(-)
Added: branches/filesystem3/boost/delimit_string.hpp
==============================================================================
--- (empty file)
+++ branches/filesystem3/boost/delimit_string.hpp 2010-06-16 07:08:55 EDT (Wed, 16 Jun 2010)
@@ -0,0 +1,112 @@
+// 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 <sstream>
+#include <iomanip>
+
+namespace boost
+{
+ namespace string
+ {
+ namespace detail
+ {
+ // ostream operator<< takes a const_proxy& argument, and thus works for arguments
+ // of both type const_proxy and type proxy. istream operator>> takes a proxy&
+ // argument, and thus works for arguments of type proxy but not type const_proxy.
+ // That's what ensures const strings can't be inadvertently written into, not
+ // whether or not const_proxy::s is const.
+ template <class String>
+ struct const_proxy
+ {
+ typedef typename String::value_type value_type;
+ String& s; // must be non-const
+ value_type escape;
+ value_type delim;
+ const_proxy(std::string& s_, value_type escape_, value_type delim_)
+ : s(s_), escape(escape_), delim(delim_) {}
+ };
+
+ template <class String>
+ struct proxy : public const_proxy<String>
+ {
+ proxy(String& s_, value_type escape_, value_type delim_)
+ : const_proxy(s_, escape_, delim_ ) {}
+ };
+ }
+
+ template <class String>
+ inline detail::const_proxy<String> delimit_string(const String& s,
+ typename String::value_type escape='\\',
+ typename String::value_type delim='\"')
+ {
+ // const safety is provided by the detail::proxy - detail::const_proxy relationship,
+ // so we are not giving up type safety by casting away const.
+ return detail::const_proxy<String>(const_cast<std::string&>(s), escape, 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 String>
+ inline detail::proxy<String> delimit_string(String& s,
+ typename String::value_type escape='\\',
+ typename String::value_type delim='\"')
+ {
+ return detail::proxy<String>(s, escape, 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();
+ for (;;)
+ {
+ is >> std::noskipws >> c; //************ save and restore?
+ if (c == prox.escape)
+ is >> c;
+ else if (c == prox.delim)
+ break;
+ prox.s += c;
+ }
+ return is;
+ }
+ } // namespace string
+} // namespace boost
+
+#endif // BOOST_DELIMIT_STRING
Added: branches/filesystem3/libs/filesystem/v3/test/delim_string_test.cpp
==============================================================================
--- (empty file)
+++ branches/filesystem3/libs/filesystem/v3/test/delim_string_test.cpp 2010-06-16 07:08:55 EDT (Wed, 16 Jun 2010)
@@ -0,0 +1,39 @@
+#include <boost/delimit_string.hpp>
+#include <iostream>
+#include <cassert>
+
+using boost::string::delimit_string;
+
+// Should these two operators be in the global namespace?
+using boost::string::operator<<;
+using boost::string::operator>>;
+
+int main()
+{
+ std::cout << delimit_string(std::string("foo\\bar, \" *")) << std::endl;
+ //std::cout << delimit_string("foo & bar, \" *", '&') << std::endl;
+ //std::cout << delimit_string("foo & bar, * ", '&', '*') << std::endl;
+
+ std::string non_const_string("non_const_string");
+ std::cout << delimit_string(non_const_string) << '\n';
+
+ std::stringstream ss;
+
+ const std::string expected("foo\\bar, \" *");
+ std::string actual;
+
+ ss << delimit_string(expected) << '\n';
+ ss >> delimit_string<std::string>(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 >> delimit_string(expected);
+ // ss >> delimit_string("foo");
+
+ return 0;
+}
Added: branches/filesystem3/libs/filesystem/v3/test/msvc/delimit_string_test/delimit_string_test.vcproj
==============================================================================
--- (empty file)
+++ branches/filesystem3/libs/filesystem/v3/test/msvc/delimit_string_test/delimit_string_test.vcproj 2010-06-16 07:08:55 EDT (Wed, 16 Jun 2010)
@@ -0,0 +1,199 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="9.00"
+ Name="delimit_string_test"
+ ProjectGUID="{2907CBB1-FFA6-49DE-A105-B75236214E1F}"
+ RootNamespace="delimit_string_test"
+ Keyword="Win32Proj"
+ TargetFrameworkVersion="196613"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="1"
+ InheritedPropertySheets="..\common.vsprops"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="4"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="2"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ Description="Executing test $(TargetName).exe..."
+ CommandLine=""$(TargetDir)\$(TargetName).exe""
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="1"
+ InheritedPropertySheets="..\common.vsprops"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ EnableIntrinsicFunctions="true"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+ RuntimeLibrary="2"
+ EnableFunctionLevelLinking="true"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ Description="Executing test $(TargetName).exe..."
+ CommandLine=""$(TargetDir)\$(TargetName).exe""
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+ >
+ <File
+ RelativePath="..\..\delim_string_test.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+ >
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+ >
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
Modified: branches/filesystem3/libs/filesystem/v3/test/msvc/filesystem-v3.sln
==============================================================================
--- branches/filesystem3/libs/filesystem/v3/test/msvc/filesystem-v3.sln (original)
+++ branches/filesystem3/libs/filesystem/v3/test/msvc/filesystem-v3.sln 2010-06-16 07:08:55 EDT (Wed, 16 Jun 2010)
@@ -86,6 +86,12 @@
{FFD738F7-96F0-445C-81EA-551665EF53D1} = {FFD738F7-96F0-445C-81EA-551665EF53D1}
EndProjectSection
EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "delimit_string_test", "delimit_string_test\delimit_string_test.vcproj", "{2907CBB1-FFA6-49DE-A105-B75236214E1F}"
+ ProjectSection(ProjectDependencies) = postProject
+ {F94CCADD-A90B-480C-A304-C19D015D36B1} = {F94CCADD-A90B-480C-A304-C19D015D36B1}
+ {FFD738F7-96F0-445C-81EA-551665EF53D1} = {FFD738F7-96F0-445C-81EA-551665EF53D1}
+ EndProjectSection
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
@@ -152,6 +158,10 @@
{256EA89A-E073-4CE8-B675-BE2FBC6B2691}.Debug|Win32.Build.0 = Debug|Win32
{256EA89A-E073-4CE8-B675-BE2FBC6B2691}.Release|Win32.ActiveCfg = Release|Win32
{256EA89A-E073-4CE8-B675-BE2FBC6B2691}.Release|Win32.Build.0 = Release|Win32
+ {2907CBB1-FFA6-49DE-A105-B75236214E1F}.Debug|Win32.ActiveCfg = Debug|Win32
+ {2907CBB1-FFA6-49DE-A105-B75236214E1F}.Debug|Win32.Build.0 = Debug|Win32
+ {2907CBB1-FFA6-49DE-A105-B75236214E1F}.Release|Win32.ActiveCfg = Release|Win32
+ {2907CBB1-FFA6-49DE-A105-B75236214E1F}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
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