/** * \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 #include "sgml.h" #include "buffer.h" #include "bufferparams.h" #include "counters.h" #include "lyxtext.h" #include "paragraph.h" #include "support/lstrings.h" #include "support/std_ostream.h" #include "support/tostr.h" #include using lyx::support::subst; using std::make_pair; using std::ostream; using std::ostringstream; using std::pair; using std::string; namespace sgml { pair escapeChar(char c) { string str; switch (c) { case ' ': return make_pair(true, string(" ")); break; case '\0': // Ignore :-) str.erase(); break; case '&': str = "&"; break; case '<': str = "<"; break; case '>': str = ">"; break; #if 0 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; #endif default: str = c; break; } return make_pair(false, str); } string escapeString(string const & raw) { ostringstream bin; for(int i=0; i < raw.size(); ++i) { bool ws; string str; boost::tie(ws, str) = sgml::escapeChar(raw[i]); bin << str; } return bin.str(); } int openTag(Buffer const & buf, ostream & os, Paragraph::depth_type depth, bool mixcont, string const & name, string const & param) { Counters & counters = buf.params().getLyXTextClass().counters(); LyXLayout_ptr const & defaultstyle = buf.params().getLyXTextClass().defaultLayout(); string attribute = param; // code for paragraphs like the standard paragraph in AGU. if ( defaultstyle->latexname() == name and !defaultstyle->latexparam().empty()) { counters.step(name); int i = counters.value(name); attribute += "" + subst(defaultstyle->latexparam(), "#", tostr(i)); } if (!name.empty() && name != "!-- --") { if (!mixcont) os << string(depth, ' '); os << '<' << name; if (!attribute.empty()) os << " " << attribute; os << '>'; } return !mixcont; } int closeTag(ostream & os, Paragraph::depth_type depth, bool mixcont, string const & name) { if (!name.empty() && name != "!-- --") { if (!mixcont) os << '\n' << string(depth, ' '); os << "'; } if (!mixcont) os << '\n'; return !mixcont; } } // namespace sgml