source: trunk/lib/HtmlBuf.cc

Last change on this file was 1515, checked in by Peter Johansson, 9 years ago

update copyright years

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.7 KB
Line 
1// $Id: HtmlBuf.cc 1515 2012-09-26 00:35:10Z peter $
2
3/*
4  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
5  Copyright (C) 2009, 2010, 2012 Peter Johansson
6
7  This file is part of svndigest, http://dev.thep.lu.se/svndigest
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
11  the Free Software Foundation; either version 3 of the License, or
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
20  along with svndigest. If not, see <http://www.gnu.org/licenses/>.
21*/
22
23#include "HtmlBuf.h"
24
25#include "Configuration.h"
26
27#include <cstdio>
28#include <iostream>
29#include <string>
30
31namespace theplu{
32namespace svndigest{
33
34  HtmlBuf::HtmlBuf(std::streambuf& buf)
35    : std::streambuf(), buf_(buf)
36  {
37    map_['"']=std::string("&quot;");
38    map_['\'']=std::string("\'");
39    map_['\n']=std::string("<br />");
40    map_['<']=std::string("&lt;");
41    map_['>']=std::string("&gt;");
42    map_['&']=std::string("&amp;");
43    map_[' ']=std::string("&nbsp;");
44    std::string str;
45    for (size_t i=0; i<Configuration::instance().tab_size(); ++i)
46      str += "&nbsp;";
47    map_['\t']=str;
48  }
49
50  HtmlBuf::int_type HtmlBuf::overflow (HtmlBuf::int_type c)
51  {
52    std::map<char, std::string>::const_iterator i = map_.find(c);
53    if (i==map_.end())
54      return buf_.sputc(c);
55    // writing
56    if (buf_.sputn(i->second.c_str(), i->second.size()) ==
57        static_cast<std::streamsize>(i->second.size()))
58      return c;
59    return EOF;
60  }
61
62}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.