2002-08-09 00:42:12 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file sgml.C
|
|
|
|
|
* Copyright 2002 the LyX Team
|
|
|
|
|
* Read the file COPYING
|
|
|
|
|
*
|
|
|
|
|
* \author Jos<EFBFBD> Matos
|
|
|
|
|
* \author John Levon <levon@movementarian.org>
|
|
|
|
|
*/
|
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
#include <config.h>
|
2002-11-04 02:12:42 +00:00
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
#include "support/LOstream.h"
|
2002-11-04 02:12:42 +00:00
|
|
|
|
|
2002-08-09 00:42:12 +00:00
|
|
|
|
#include "paragraph.h"
|
2002-10-21 16:21:56 +00:00
|
|
|
|
#include "sgml.h"
|
2002-11-04 02:12:42 +00:00
|
|
|
|
|
2002-08-09 00:42:12 +00:00
|
|
|
|
using std::pair;
|
|
|
|
|
using std::make_pair;
|
2002-10-21 16:21:56 +00:00
|
|
|
|
using std::ostream;
|
|
|
|
|
using std::endl;
|
2002-11-04 02:12:42 +00:00
|
|
|
|
|
2002-08-09 00:42:12 +00:00
|
|
|
|
namespace sgml {
|
|
|
|
|
|
|
|
|
|
pair<bool, string> escapeChar(char c)
|
|
|
|
|
{
|
|
|
|
|
string str;
|
2002-11-04 02:12:42 +00:00
|
|
|
|
|
2002-08-09 00:42:12 +00:00
|
|
|
|
switch (c) {
|
|
|
|
|
case ' ':
|
|
|
|
|
return make_pair(true, string(" "));
|
|
|
|
|
break;
|
|
|
|
|
case '\0': // Ignore :-)
|
|
|
|
|
str.erase();
|
|
|
|
|
break;
|
|
|
|
|
case '&':
|
|
|
|
|
str = "&";
|
|
|
|
|
break;
|
|
|
|
|
case '<':
|
|
|
|
|
str = "<";
|
|
|
|
|
break;
|
|
|
|
|
case '>':
|
|
|
|
|
str = ">";
|
|
|
|
|
break;
|
|
|
|
|
case '$':
|
|
|
|
|
str = "$";
|
|
|
|
|
break;
|
|
|
|
|
case '#':
|
|
|
|
|
str = "#";
|
|
|
|
|
break;
|
|
|
|
|
case '%':
|
|
|
|
|
str = "%";
|
|
|
|
|
break;
|
|
|
|
|
case '[':
|
|
|
|
|
str = "[";
|
|
|
|
|
break;
|
|
|
|
|
case ']':
|
|
|
|
|
str = "]";
|
|
|
|
|
break;
|
|
|
|
|
case '{':
|
|
|
|
|
str = "{";
|
|
|
|
|
break;
|
|
|
|
|
case '}':
|
|
|
|
|
str = "}";
|
|
|
|
|
break;
|
|
|
|
|
case '~':
|
|
|
|
|
str = "˜";
|
|
|
|
|
break;
|
|
|
|
|
case '"':
|
|
|
|
|
str = """;
|
|
|
|
|
break;
|
|
|
|
|
case '\\':
|
|
|
|
|
str = "\";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
str = c;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return make_pair(false, str);
|
|
|
|
|
}
|
|
|
|
|
|
2002-11-04 02:12:42 +00:00
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
int openTag(ostream & os, Paragraph::depth_type depth,
|
|
|
|
|
bool mixcont, string const & latexname)
|
|
|
|
|
{
|
|
|
|
|
if (!latexname.empty() && latexname != "!-- --") {
|
|
|
|
|
if (!mixcont)
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << string(depth, ' ');
|
|
|
|
|
os << '<' << latexname << '>';
|
2002-10-21 16:21:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!mixcont)
|
|
|
|
|
os << endl;
|
|
|
|
|
|
|
|
|
|
return !mixcont;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int closeTag(ostream & os, Paragraph::depth_type depth,
|
|
|
|
|
bool mixcont, string const & latexname)
|
|
|
|
|
{
|
|
|
|
|
if (!latexname.empty() && latexname != "!-- --") {
|
|
|
|
|
if (!mixcont)
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << endl << string(depth, ' ');
|
|
|
|
|
os << "</" << latexname << '>';
|
2002-10-21 16:21:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!mixcont)
|
|
|
|
|
os << endl;
|
|
|
|
|
|
|
|
|
|
return !mixcont;
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-09 00:42:12 +00:00
|
|
|
|
} // namespace sgml
|