1 | // $Id: HtmlBuf.cc 1267 2010-11-02 03:56:19Z peter $ |
---|
2 | |
---|
3 | /* |
---|
4 | Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson |
---|
5 | Copyright (C) 2009, 2010 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 | |
---|
31 | namespace theplu{ |
---|
32 | namespace svndigest{ |
---|
33 | |
---|
34 | HtmlBuf::HtmlBuf(std::streambuf& buf) |
---|
35 | : std::streambuf(), buf_(buf) |
---|
36 | { |
---|
37 | map_['"']=std::string("""); |
---|
38 | map_['\'']=std::string("\'"); |
---|
39 | map_['\n']=std::string("<br />"); |
---|
40 | map_['<']=std::string("<"); |
---|
41 | map_['>']=std::string(">"); |
---|
42 | map_['&']=std::string("&"); |
---|
43 | map_[' ']=std::string(" "); |
---|
44 | std::string str; |
---|
45 | for (size_t i=0; i<Configuration::instance().tab_size(); ++i) |
---|
46 | str += " "; |
---|
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 |
---|