lyx_mirror/src/sgml.C
José Matox eb3d6435d1 Reorganized docbook export code and fixed several bugs in the process.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9114 a592a061-630c-0410-9148-cb99ea01b6c8
2004-10-24 00:02:39 +00:00

122 lines
1.8 KiB
C

/**
* \file sgml.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author José Matos
* \author John Levon
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "support/std_ostream.h"
#include "paragraph.h"
#include "sgml.h"
using std::endl;
using std::make_pair;
using std::ostream;
using std::pair;
using std::string;
namespace sgml {
pair<bool, string> escapeChar(char c)
{
string str;
switch (c) {
case ' ':
return make_pair(true, string(" "));
break;
case '\0': // Ignore :-)
str.erase();
break;
case '&':
str = "&amp;";
break;
case '<':
str = "&lt;";
break;
case '>':
str = "&gt;";
break;
#if 0
case '$':
str = "&dollar;";
break;
case '#':
str = "&num;";
break;
case '%':
str = "&percnt;";
break;
case '[':
str = "&lsqb;";
break;
case ']':
str = "&rsqb;";
break;
case '{':
str = "&lcub;";
break;
case '}':
str = "&rcub;";
break;
case '~':
str = "&tilde;";
break;
case '"':
str = "&quot;";
break;
case '\\':
str = "&bsol;";
break;
#endif
default:
str = c;
break;
}
return make_pair(false, str);
}
int openTag(ostream & os, Paragraph::depth_type depth,
bool mixcont, string const & latexname,
string const & latexparam)
{
if (!latexname.empty() && latexname != "!-- --") {
if (!mixcont)
os << string(depth, ' ');
os << '<' << latexname;
if (!latexparam.empty())
os << " " << latexparam;
os << '>';
}
return !mixcont;
}
int closeTag(ostream & os, Paragraph::depth_type depth,
bool mixcont, string const & latexname)
{
if (!latexname.empty() && latexname != "!-- --") {
if (!mixcont)
os << '\n' << string(depth, ' ');
os << "</" << latexname << '>';
}
if (!mixcont)
os << '\n';
return !mixcont;
}
} // namespace sgml