source: trunk/lib/HtmlBuf.cc @ 992

Last change on this file since 992 was 992, checked in by Peter Johansson, 12 years ago

adding missing copyright years

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.7 KB
RevLine 
[234]1// $Id: HtmlBuf.cc 992 2009-12-17 02:18:38Z peter $
2
3/*
[992]4  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
5  Copyright (C) 2009 Peter Johansson
6
[687]7  This file is part of svndigest, http://dev.thep.lu.se/svndigest
[234]8
9  svndigest is free software; you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
[693]11  the Free Software Foundation; either version 3 of the License, or
[234]12  (at your option) any later version.
13
14  svndigest is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
[693]20  along with svndigest. If not, see <http://www.gnu.org/licenses/>.
[234]21*/
22
[606]23#include "HtmlBuf.h"
[234]24
[606]25#include <cstdio>
26#include <iostream>
[234]27#include <string>
28
29namespace theplu{
30namespace svndigest{
31
[606]32  HtmlBuf::HtmlBuf(std::streambuf& buf)
33    : std::streambuf(), buf_(buf) 
[234]34  {
[991]35    map_['"']=std::string("&quot;");
[234]36    map_['\'']=std::string("\'");
37    map_['\n']=std::string("<br />");
38    map_['<']=std::string("&lt;");
39    map_['>']=std::string("&gt;");
40    map_['&']=std::string("&amp;");
[380]41    map_[' ']=std::string("&nbsp;");
[234]42    // This should be configurable, but for now indentation is two spaces.
43    map_['\t']=std::string("&nbsp;&nbsp;");
44  }
45
[606]46  HtmlBuf::int_type HtmlBuf::overflow (HtmlBuf::int_type c)
[234]47  {
[606]48    std::map<char, std::string>::const_iterator i = map_.find(c);
49    if (i==map_.end())
50      return buf_.sputc(c);
51    // writing
52    if (buf_.sputn(i->second.c_str(), i->second.size()) == 
53        static_cast<std::streamsize>(i->second.size()))
54      return c;
55    return EOF;
[234]56  }
57
58}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.