]> git.lyx.org Git - lyx.git/blob - src/sgml.C
more cursor dispatch
[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 using std::string;
25
26
27 namespace sgml {
28
29 pair<bool, string> escapeChar(char c)
30 {
31         string str;
32
33         switch (c) {
34         case ' ':
35                 return make_pair(true, string(" "));
36                 break;
37         case '\0': // Ignore :-)
38                 str.erase();
39                 break;
40         case '&':
41                 str = "&amp;";
42                 break;
43         case '<':
44                 str = "&lt;";
45                 break;
46         case '>':
47                 str = "&gt;";
48                 break;
49         case '$':
50                 str = "&dollar;";
51                 break;
52         case '#':
53                 str = "&num;";
54                 break;
55         case '%':
56                 str = "&percnt;";
57                 break;
58         case '[':
59                 str = "&lsqb;";
60                 break;
61         case ']':
62                 str = "&rsqb;";
63                 break;
64         case '{':
65                 str = "&lcub;";
66                 break;
67         case '}':
68                 str = "&rcub;";
69                 break;
70         case '~':
71                 str = "&tilde;";
72                 break;
73         case '"':
74                 str = "&quot;";
75                 break;
76         case '\\':
77                 str = "&bsol;";
78                 break;
79         default:
80                 str = c;
81                 break;
82         }
83         return make_pair(false, str);
84 }
85
86
87 int openTag(ostream & os, Paragraph::depth_type depth,
88             bool mixcont, string const & latexname,
89                 string const & latexparam)
90 {
91         if (!latexname.empty() && latexname != "!-- --") {
92                 if (!mixcont)
93                         os << string(depth, ' ');
94                 os << '<' << latexname;
95                 if (!latexparam.empty())
96                         os << " " << latexparam;
97                 os << '>';
98         }
99
100         if (!mixcont)
101                 os << endl;
102
103         return !mixcont;
104 }
105
106
107 int closeTag(ostream & os, Paragraph::depth_type depth,
108              bool mixcont, string const & latexname)
109 {
110         if (!latexname.empty() && latexname != "!-- --") {
111                 if (!mixcont)
112                         os << endl << string(depth, ' ');
113                 os << "</" << latexname << '>';
114         }
115
116         if (!mixcont)
117                 os << endl;
118
119         return !mixcont;
120 }
121
122
123 unsigned int closeEnvTags(ostream & os, bool mixcont,
124                         string const & environment_inner_depth,
125                         string const & itemtag,
126                         lyx::depth_type total_depth)
127 {
128         unsigned int lines = 0;
129         if (environment_inner_depth != "!-- --") {
130                 lines += closeTag(os, total_depth, mixcont, itemtag);
131                 if (!environment_inner_depth.empty())
132                         lines += closeTag(os, total_depth, mixcont,
133                                 environment_inner_depth);
134         }
135         return lines;
136 }
137
138
139 } // namespace sgml