1 // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
2 // (C) Copyright 2005-2007 Jonathan Turkanis
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
6 // See http://www.boost.org/libs/iostreams for documentation.
8 #ifndef BOOST_IOSTREAMS_UNIX2DOS_FILTER_FILTER_HPP_INCLUDED
9 #define BOOST_IOSTREAMS_UNIX2DOS_FILTER_FILTER_HPP_INCLUDED
12 #include <cstdio> // EOF.
13 #include <iostream> // cin, cout.
14 #include <boost/iostreams/concepts.hpp>
15 #include <boost/iostreams/filter/stdio.hpp>
16 #include <boost/iostreams/operations.hpp>
18 namespace boost { namespace iostreams { namespace example {
20 class unix2dos_stdio_filter : public stdio_filter {
25 while ((c = std::cin.get()) != EOF) {
33 class unix2dos_input_filter : public input_filter {
35 unix2dos_input_filter() : has_linefeed_(false) { }
37 template<typename Source>
41 has_linefeed_ = false;
46 if ((c = iostreams::get(src)) == '\n') {
54 template<typename Source>
55 void close(Source&) { has_linefeed_ = false; }
60 class unix2dos_output_filter : public output_filter {
62 unix2dos_output_filter() : has_linefeed_(false) { }
64 template<typename Sink>
65 bool put(Sink& dest, int c)
68 return has_linefeed_ ?
69 put_char(dest, '\n') :
70 put_char(dest, '\r') ?
71 this->put(dest, '\n') :
73 return iostreams::put(dest, c);
76 template<typename Sink>
77 void close(Sink&) { has_linefeed_ = false; }
79 template<typename Sink>
80 bool put_char(Sink& dest, int c)
83 if ((result = iostreams::put(dest, c)) == true) {
97 } } } // End namespaces example, iostreams, boost.
99 #endif // #ifndef BOOST_IOSTREAMS_UNIX2DOS_FILTER_FILTER_HPP_INCLUDED