1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "tools/rbd/IndentStream.h"
8 int IndentBuffer::overflow (int c) {
9 if (traits_type::eq_int_type(traits_type::eof(), c)) {
10 return traits_type::not_eof(c);
18 r = m_streambuf->sputn(m_buffer.c_str(), m_buffer.size());
22 // convert tab to single space and fall-through
25 if (m_indent + m_buffer.size() >= m_line_length) {
26 size_t word_offset = m_buffer.find_last_of(m_delim);
27 bool space_delim = (m_delim == " ");
28 if (word_offset == std::string::npos && !space_delim) {
29 word_offset = m_buffer.find_last_of(" ");
32 if (word_offset != std::string::npos) {
34 m_streambuf->sputn(m_buffer.c_str(), word_offset);
35 m_buffer = std::string(m_buffer,
36 word_offset + (space_delim ? 1 : 0));
39 m_streambuf->sputn(m_buffer.c_str(), m_buffer.size());
42 m_streambuf->sputc('\n');
49 void IndentBuffer::flush_line() {
50 if (m_initial_offset >= m_indent) {
52 m_streambuf->sputc('\n');
55 m_streambuf->sputn(m_indent_prefix.c_str(), m_indent - m_initial_offset);