mirror of
https://github.com/boostorg/iostreams.git
synced 2026-02-22 15:32:20 +00:00
89 lines
2.5 KiB
HTML
Executable File
89 lines
2.5 KiB
HTML
Executable File
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
<HTML>
|
|
<HEAD>
|
|
<LINK REL='stylesheet' HREF='../../../../boost.css'>
|
|
<LINK REL='stylesheet' HREF='../theme/iostreams.css'>
|
|
<STYLE>
|
|
PRE { background-color: white; border:0; font-size: 10pt }
|
|
</STYLE>
|
|
<TITLE>Tab-expanding OutputFilter Example Output</TITLE>
|
|
</HEAD>
|
|
<BODY>
|
|
<PRE>**** Code with tabs ****
|
|
|
|
class tab_expanding_output_filter : public output_filter {
|
|
public:
|
|
explicit tab_expanding_output_filter(int tab_size = 8)
|
|
: tab_size_(tab_size), col_no_(0)
|
|
{ assert(tab_size > 0); }
|
|
|
|
template<typename Sink>
|
|
void put(Sink& dest, int c)
|
|
{
|
|
if (c == '\t') {
|
|
do {
|
|
this->put(dest, ' ');
|
|
} while(col_no_ % tab_size_ != 0);
|
|
} else {
|
|
boost::iostreams::put(dest, c);
|
|
if (c == '\n')
|
|
col_no_ = 0;
|
|
else
|
|
++col_no_;
|
|
}
|
|
}
|
|
templatetypename Sink
|
|
void close(Sink&) { col_no_ = 0; }
|
|
private:
|
|
int tab_size_;
|
|
int col_no_;
|
|
};
|
|
|
|
|
|
**** Code with tabs replaced ****
|
|
|
|
class tab_expanding_output_filter : public output_filter {
|
|
public:
|
|
explicit tab_expanding_output_filter(int tab_size = 8)
|
|
: tab_size_(tab_size), col_no_(0)
|
|
{ assert(tab_size > 0); }
|
|
|
|
template<typename Sink>
|
|
void put(Sink& dest, int c)
|
|
{
|
|
if (c == '\t') {
|
|
do {
|
|
this->put(dest, ' ');
|
|
} while(col_no_ % tab_size_ != 0);
|
|
} else {
|
|
boost::iostreams::put(dest, c);
|
|
if (c == '\n')
|
|
col_no_ = 0;
|
|
else
|
|
++col_no_;
|
|
}
|
|
}
|
|
template<typename Sink>
|
|
void close(Sink&) { col_no_ = 0; }
|
|
private:
|
|
int tab_size_;
|
|
int col_no_;
|
|
};
|
|
</PRE>
|
|
|
|
<!-- Begin Footer -->
|
|
|
|
<HR>
|
|
<P CLASS='copyright'>Revised
|
|
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
|
|
20 May, 2004
|
|
<!--webbot bot="Timestamp" endspan i-checksum="38504" -->
|
|
</P>
|
|
|
|
<P CLASS='copyright'>© Copyright Jonathan Turkanis, 2004</P>
|
|
<P CLASS='copyright'>
|
|
Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at <A HREF='http://www.boost.org/LICENSE_1_0.txt'>http://www.boost.org/LICENSE_1_0.txt</A>)
|
|
</P>
|
|
|
|
<!-- End Footer -->
|
|
</BODY> |