]> git.lyx.org Git - lyx.git/blob - src/sgml.C
The Gtk patch.
[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/LOstream.h"
15
16 #include "paragraph.h"
17 #include "sgml.h"
18
19 using std::pair;
20 using std::make_pair;
21 using std::ostream;
22 using std::endl;
23
24 namespace sgml {
25
26 pair<bool, string> escapeChar(char c)
27 {
28         string str;
29
30         switch (c) {
31         case ' ':
32                 return make_pair(true, string(" "));
33                 break;
34         case '\0': // Ignore :-)
35                 str.erase();
36                 break;
37         case '&':
38                 str = "&amp;";
39                 break;
40         case '<':
41                 str = "&lt;";
42                 break;
43         case '>':
44                 str = "&gt;";
45                 break;
46         case '$':
47                 str = "&dollar;";
48                 break;
49         case '#':
50                 str = "&num;";
51                 break;
52         case '%':
53                 str = "&percnt;";
54                 break;
55         case '[':
56                 str = "&lsqb;";
57                 break;
58         case ']':
59                 str = "&rsqb;";
60                 break;
61         case '{':
62                 str = "&lcub;";
63                 break;
64         case '}':
65                 str = "&rcub;";
66                 break;
67         case '~':
68                 str = "&tilde;";
69                 break;
70         case '"':
71                 str = "&quot;";
72                 break;
73         case '\\':
74                 str = "&bsol;";
75                 break;
76         default:
77                 str = c;
78                 break;
79         }
80         return make_pair(false, str);
81 }
82
83
84 int openTag(ostream & os, Paragraph::depth_type depth,
85             bool mixcont, string const & latexname)
86 {
87         if (!latexname.empty() && latexname != "!-- --") {
88                 if (!mixcont)
89                         os << string(depth, ' ');
90                 os << '<' << latexname << '>';
91         }
92
93         if (!mixcont)
94                 os << endl;
95
96         return !mixcont;
97 }
98
99
100 int closeTag(ostream & os, Paragraph::depth_type depth,
101              bool mixcont, string const & latexname)
102 {
103         if (!latexname.empty() && latexname != "!-- --") {
104                 if (!mixcont)
105                         os << endl << string(depth, ' ');
106                 os << "</" << latexname << '>';
107         }
108
109         if (!mixcont)
110                 os << endl;
111
112         return !mixcont;
113 }
114
115 } // namespace sgml