#ifndef _included_boost_range_algorithm_unquote_hpp_ #define _included_boost_range_algorithm_unquote_hpp_ // Boost string_algo library unquote.hpp header file // Copyright Robert Stewart 2010. // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // See http://www.boost.org/ for updates, documentation, and revision history. #include #include #include #include #include #include #include //#include // only in 1.43 namespace boost { namespace algorithm { template OutIt unquote(OutIt _out, Range & _input, Char _delimiter = '"', Char _escape = '\\'); template inline Sequence unquote(Sequence const & _input); template inline Sequence unquote(Sequence const & _input, Char _delimiter = '"', Char _escape = '\\'); } } template OutIt boost::algorithm::unquote(OutIt _out, Range & _input, Char _delimiter, Char _escape) { typedef typename boost::range_iterator::type iterator_type; typedef typename boost::range_value::type value_type; iterator_type it(boost::begin(_input)); iterator_type end(boost::end(_input)); unsigned nesting(0); while (it != end) { value_type ch(*it); if (ch == _delimiter) { ++nesting; ++it; while (it != end) { ch = *it; if (ch == _escape) { ++it; ch = *it; if (it == end) { break; } } else if (ch == _delimiter) { --nesting; break; } *_out++ = ch; ++it; } } else { *_out++ = ch; } ++it; } if (nesting) { throw std::logic_error("Missing end delimiter"); } } template inline Sequence boost::algorithm::unquote(Sequence const & _input, Char _delimiter, Char _escape) { Sequence result; unquote(std::back_inserter(result), _input, _delimiter, _escape); return result; } template inline Sequence boost::algorithm::unquote(Sequence const & _input) { return unquote(_input, '"', '\\'); } #endif