1 | // $Id: HtmlBuf.cc 980 2009-12-12 21:34:15Z peter $ |
---|
2 | |
---|
3 | /* |
---|
4 | This file is part of svndigest, http://dev.thep.lu.se/svndigest |
---|
5 | |
---|
6 | svndigest is free software; you can redistribute it and/or modify it |
---|
7 | under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 3 of the License, or |
---|
9 | (at your option) any later version. |
---|
10 | |
---|
11 | svndigest is distributed in the hope that it will be useful, but |
---|
12 | WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
14 | General Public License for more details. |
---|
15 | |
---|
16 | You should have received a copy of the GNU General Public License |
---|
17 | along with svndigest. If not, see <http://www.gnu.org/licenses/>. |
---|
18 | */ |
---|
19 | |
---|
20 | #include "HtmlBuf.h" |
---|
21 | |
---|
22 | #include <cstdio> |
---|
23 | #include <iostream> |
---|
24 | #include <string> |
---|
25 | |
---|
26 | namespace theplu{ |
---|
27 | namespace svndigest{ |
---|
28 | |
---|
29 | HtmlBuf::HtmlBuf(std::streambuf& buf) |
---|
30 | : std::streambuf(), buf_(buf) |
---|
31 | { |
---|
32 | map_['"']=std::string("\""); |
---|
33 | map_['\'']=std::string("\'"); |
---|
34 | map_['\n']=std::string("<br />"); |
---|
35 | map_['<']=std::string("<"); |
---|
36 | map_['>']=std::string(">"); |
---|
37 | map_['&']=std::string("&"); |
---|
38 | map_[' ']=std::string(" "); |
---|
39 | // This should be configurable, but for now indentation is two spaces. |
---|
40 | map_['\t']=std::string(" "); |
---|
41 | map_['å']=std::string("å"); |
---|
42 | map_['ä']=std::string("ä"); |
---|
43 | map_['ö']=std::string("ö"); |
---|
44 | map_['Å']=std::string("Å"); |
---|
45 | map_['Ä']=std::string("Ä"); |
---|
46 | map_['Ö']=std::string("Ö"); |
---|
47 | map_['é']=std::string("é"); |
---|
48 | map_['É']=std::string("É"); |
---|
49 | map_['á']=std::string("á"); |
---|
50 | map_['Á']=std::string("Á"); |
---|
51 | } |
---|
52 | |
---|
53 | HtmlBuf::int_type HtmlBuf::overflow (HtmlBuf::int_type c) |
---|
54 | { |
---|
55 | std::map<char, std::string>::const_iterator i = map_.find(c); |
---|
56 | if (i==map_.end()) |
---|
57 | return buf_.sputc(c); |
---|
58 | // writing |
---|
59 | if (buf_.sputn(i->second.c_str(), i->second.size()) == |
---|
60 | static_cast<std::streamsize>(i->second.size())) |
---|
61 | return c; |
---|
62 | return EOF; |
---|
63 | } |
---|
64 | |
---|
65 | }} // end of namespace svndigest and namespace theplu |
---|