]> git.lyx.org Git - lyx.git/blob - src/sgml.C
Small clean-up.
[lyx.git] / src / sgml.C
1 /**
2  * \file sgml.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author José Matos
7  * \author John Levon
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "support/std_ostream.h"
15
16 #include "paragraph.h"
17 #include "sgml.h"
18
19 using std::endl;
20 using std::make_pair;
21
22 using std::ostream;
23 using std::pair;
24
25
26 namespace sgml {
27
28 pair<bool, string> escapeChar(char c)
29 {
30         string str;
31
32         switch (c) {
33         case ' ':
34                 return make_pair(true, string(" "));
35                 break;
36         case '\0': // Ignore :-)
37                 str.erase();
38                 break;
39         case '&':
40                 str = "&amp;";
41                 break;
42         case '<':
43                 str = "&lt;";
44                 break;
45         case '>':
46                 str = "&gt;";
47                 break;
48         case '$':
49                 str = "&dollar;";
50                 break;
51         case '#':
52                 str = "&num;";
53                 break;
54         case '%':
55                 str = "&percnt;";
56                 break;
57         case '[':
58                 str = "&lsqb;";
59                 break;
60         case ']':
61                 str = "&rsqb;";
62                 break;
63         case '{':
64                 str = "&lcub;";
65                 break;
66         case '}':
67                 str = "&rcub;";
68                 break;
69         case '~':
70                 str = "&tilde;";
71                 break;
72         case '"':
73                 str = "&quot;";
74                 break;
75         case '\\':
76                 str = "&bsol;";
77                 break;
78         default:
79                 str = c;
80                 break;
81         }
82         return make_pair(false, str);
83 }
84
85
86 int openTag(ostream & os, Paragraph::depth_type depth,
87             bool mixcont, string const & latexname)
88 {
89         if (!latexname.empty() && latexname != "!-- --") {
90                 if (!mixcont)
91                         os << string(depth, ' ');
92                 os << '<' << latexname << '>';
93         }
94
95         if (!mixcont)
96                 os << endl;
97
98         return !mixcont;
99 }
100
101
102 int closeTag(ostream & os, Paragraph::depth_type depth,
103              bool mixcont, string const & latexname)
104 {
105         if (!latexname.empty() && latexname != "!-- --") {
106                 if (!mixcont)
107                         os << endl << string(depth, ' ');
108                 os << "</" << latexname << '>';
109         }
110
111         if (!mixcont)
112                 os << endl;
113
114         return !mixcont;
115 }
116
117 } // namespace sgml