]> git.lyx.org Git - lyx.git/blob - src/sgml.C
fix reading the author field.
[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 #if 0
50         case '$':
51                 str = "&dollar;";
52                 break;
53         case '#':
54                 str = "&num;";
55                 break;
56         case '%':
57                 str = "&percnt;";
58                 break;
59         case '[':
60                 str = "&lsqb;";
61                 break;
62         case ']':
63                 str = "&rsqb;";
64                 break;
65         case '{':
66                 str = "&lcub;";
67                 break;
68         case '}':
69                 str = "&rcub;";
70                 break;
71         case '~':
72                 str = "&tilde;";
73                 break;
74         case '"':
75                 str = "&quot;";
76                 break;
77         case '\\':
78                 str = "&bsol;";
79                 break;
80 #endif
81         default:
82                 str = c;
83                 break;
84         }
85         return make_pair(false, str);
86 }
87
88
89 int openTag(ostream & os, Paragraph::depth_type depth,
90             bool mixcont, string const & latexname,
91                 string const & latexparam)
92 {
93         if (!latexname.empty() && latexname != "!-- --") {
94                 if (!mixcont)
95                         os << string(depth, ' ');
96                 os << '<' << latexname;
97                 if (!latexparam.empty())
98                         os << " " << latexparam;
99                 os << '>';
100         }
101
102         if (!mixcont)
103                 os << endl;
104
105         return !mixcont;
106 }
107
108
109 int closeTag(ostream & os, Paragraph::depth_type depth,
110              bool mixcont, string const & latexname)
111 {
112         if (!latexname.empty() && latexname != "!-- --") {
113                 if (!mixcont)
114                         os << endl << string(depth, ' ');
115                 os << "</" << latexname << '>';
116         }
117
118         if (!mixcont)
119                 os << endl;
120
121         return !mixcont;
122 }
123
124
125 unsigned int closeEnvTags(ostream & os, bool mixcont,
126                         string const & environment_inner_depth,
127                         string const & itemtag,
128                         lyx::depth_type total_depth)
129 {
130         unsigned int lines = 0;
131         if (environment_inner_depth != "!-- --") {
132                 lines += closeTag(os, total_depth, mixcont, itemtag);
133                 if (!environment_inner_depth.empty())
134                         lines += closeTag(os, total_depth, mixcont,
135                                 environment_inner_depth);
136         }
137         return lines;
138 }
139
140
141 } // namespace sgml