source: trunk/lib/HtmlStream.cc @ 519

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

trac moved to new location.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.0 KB
Line 
1// $Id: HtmlStream.cc 519 2007-12-23 20:14:50Z jari $
2
3/*
4  Copyright (C) 2007 Jari Häkkinen, Peter Johansson
5
6  This file is part of svndigest, http://trac.thep.lu.se/svndigest
7
8  svndigest is free software; you can redistribute it and/or modify it
9  under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  svndigest is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#include "HtmlStream.h"
25
26#include <string>
27
28namespace theplu{
29namespace svndigest{
30
31  HtmlStream::HtmlStream(std::ostream& os)
32    : os_(os)
33  {
34    map_['"']=std::string("\"");
35    map_['\'']=std::string("\'");
36    map_['\n']=std::string("<br />");
37    map_['<']=std::string("&lt;");
38    map_['>']=std::string("&gt;");
39    map_['&']=std::string("&amp;");
40    map_[' ']=std::string("&nbsp;");
41    // This should be configurable, but for now indentation is two spaces.
42    map_['\t']=std::string("&nbsp;&nbsp;");
43    map_['å']=std::string("&aring;");
44    map_['ä']=std::string("&auml;");
45    map_['ö']=std::string("&ouml;");
46    map_['Å']=std::string("&Aring;");
47    map_['Ä']=std::string("&Auml;");
48    map_['Ö']=std::string("&Ouml;");
49    map_['é']=std::string("&eacute;");
50    map_['É']=std::string("&Eacute;");
51    map_['á']=std::string("&aacute;");
52    map_['Á']=std::string("&Aacute;");
53  }
54
55
56  HtmlStream::~HtmlStream(void)
57  {
58  }
59
60
61  void HtmlStream::print(std::stringstream& ss)
62  {
63    char c;
64    while (true){
65      ss.get(c);
66      if (!ss.good())
67        return;
68      std::map<char, std::string>::const_iterator i = map_.find(c);
69      if (i==map_.end())
70        os_ << c;
71      else
72        os_ << i->second;
73    }
74  }
75
76 
77  std::ostream& HtmlStream::stream(void)
78  {
79    return os_;
80  }
81
82}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.