source: trunk/lib/HtmlBuf.cc @ 791

Last change on this file since 791 was 693, checked in by Jari Häkkinen, 13 years ago

Fixes #339. Change to GPLv3.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.0 KB
Line 
1// $Id: HtmlBuf.cc 693 2008-09-11 20:42:56Z jari $
2
3/*
4  Copyright (C) 2007 Jari Häkkinen, Peter Johansson
5  Copyright (C) 2008 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 <cstdio>
26#include <iostream>
27#include <string>
28
29namespace theplu{
30namespace svndigest{
31
32  HtmlBuf::HtmlBuf(std::streambuf& buf)
33    : std::streambuf(), buf_(buf) 
34  {
35    map_['"']=std::string("\"");
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;");
41    map_[' ']=std::string("&nbsp;");
42    // This should be configurable, but for now indentation is two spaces.
43    map_['\t']=std::string("&nbsp;&nbsp;");
44    map_['å']=std::string("&aring;");
45    map_['ä']=std::string("&auml;");
46    map_['ö']=std::string("&ouml;");
47    map_['Å']=std::string("&Aring;");
48    map_['Ä']=std::string("&Auml;");
49    map_['Ö']=std::string("&Ouml;");
50    map_['é']=std::string("&eacute;");
51    map_['É']=std::string("&Eacute;");
52    map_['á']=std::string("&aacute;");
53    map_['Á']=std::string("&Aacute;");
54  }
55
56  HtmlBuf::int_type HtmlBuf::overflow (HtmlBuf::int_type c)
57  {
58    std::map<char, std::string>::const_iterator i = map_.find(c);
59    if (i==map_.end())
60      return buf_.sputc(c);
61    // writing
62    if (buf_.sputn(i->second.c_str(), i->second.size()) == 
63        static_cast<std::streamsize>(i->second.size()))
64      return c;
65    return EOF;
66  }
67
68}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.