]> git.lyx.org Git - lyx.git/blob - src/sgml.C
make dispatch_result_t ctor of DispatchResult explicit
[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 {
90         if (!latexname.empty() && latexname != "!-- --") {
91                 if (!mixcont)
92                         os << string(depth, ' ');
93                 os << '<' << latexname << '>';
94         }
95
96         if (!mixcont)
97                 os << endl;
98
99         return !mixcont;
100 }
101
102
103 int closeTag(ostream & os, Paragraph::depth_type depth,
104              bool mixcont, string const & latexname)
105 {
106         if (!latexname.empty() && latexname != "!-- --") {
107                 if (!mixcont)
108                         os << endl << string(depth, ' ');
109                 os << "</" << latexname << '>';
110         }
111
112         if (!mixcont)
113                 os << endl;
114
115         return !mixcont;
116 }
117
118
119 unsigned int closeEnvTags(ostream & ofs, bool mixcont,
120                         string const & environment_inner_depth,
121                         lyx::depth_type total_depth)
122 {
123         unsigned int lines;
124         if (environment_inner_depth != "!-- --") {
125                 string item_name= "listitem";
126                 lines += closeTag(ofs, total_depth, mixcont, item_name);
127                 if (environment_inner_depth == "varlistentry")
128                         lines += closeTag(ofs, total_depth, mixcont,
129                                 environment_inner_depth);
130         }
131         return lines;
132 }
133
134
135 } // namespace sgml