Fix sgml::escapeChar and sgml::escapeString to return docstring.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15444 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
José Matox 2006-10-21 11:38:43 +00:00
parent 2c0d4b31ee
commit 5d6963b0ca
4 changed files with 30 additions and 53 deletions

View File

@ -46,9 +46,8 @@ docstring const InsetIndex::getScreenLabel(Buffer const &) const
int InsetIndex::docbook(Buffer const &, odocstream & os,
OutputParams const &) const
{
// FIXME UNICODE
os << "<indexterm><primary>"
<< from_ascii(sgml::escapeString(lyx::to_ascii(getParam("name"))))
<< sgml::escapeString(getParam("name"))
<< "</primary></indexterm>";
return 0;
}

View File

@ -1179,14 +1179,8 @@ pos_type Paragraph::getFirstWord(Buffer const & buf, odocstream & os, OutputPara
value_type c = getChar(i);
if (c == ' ')
break;
bool ws;
string str;
// FIXME UNICODE
// sgml::escapeChar takes a char, not lyx::char_type
boost::tie(ws, str) = sgml::escapeChar(c);
// FIXME UNICODE
os << from_ascii(str);
}
os << sgml::escapeChar(c);
}
}
return i;
}
@ -1244,17 +1238,12 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf,
inset->docbook(buf, os, runparams);
} else {
value_type c = getChar(i);
bool ws;
string str;
// FIXME UNICODE
// sgml::escapeChar takes a char, not lyx::char_type
boost::tie(ws, str) = sgml::escapeChar(c);
if (style->pass_thru)
os.put(c);
else
// FIXME UNICODE
os << from_ascii(str);
os << sgml::escapeChar(c);
}
font_old = font;
}

View File

@ -20,12 +20,11 @@
#include "outputparams.h"
#include "paragraph.h"
#include "support/docstring.h"
#include "support/lstrings.h"
#include "support/std_ostream.h"
#include "support/convert.h"
#include <boost/tuple/tuple.hpp>
#include <map>
#include <sstream>
@ -34,82 +33,73 @@ namespace lyx {
using support::subst;
using std::make_pair;
using std::map;
using std::ostream;
using std::ostringstream;
using std::pair;
using std::string;
pair<bool, string> sgml::escapeChar(char c)
docstring sgml::escapeChar(char_type c)
{
string str;
docstring str;
switch (c) {
case ' ':
return make_pair(true, string(" "));
break;
case '\0': // Ignore :-)
str.erase();
str += " ";
break;
case '&':
str = "&amp;";
str += "&amp;";
break;
case '<':
str = "&lt;";
str += "&lt;";
break;
case '>':
str = "&gt;";
str += "&gt;";
break;
#if 0
case '$':
str = "&dollar;";
str += "&dollar;";
break;
case '#':
str = "&num;";
str += "&num;";
break;
case '%':
str = "&percnt;";
str += "&percnt;";
break;
case '[':
str = "&lsqb;";
str += "&lsqb;";
break;
case ']':
str = "&rsqb;";
str += "&rsqb;";
break;
case '{':
str = "&lcub;";
str += "&lcub;";
break;
case '}':
str = "&rcub;";
str += "&rcub;";
break;
case '~':
str = "&tilde;";
str += "&tilde;";
break;
case '"':
str = "&quot;";
str += "&quot;";
break;
case '\\':
str = "&bsol;";
str += "&bsol;";
break;
#endif
default:
str = c;
str += c;
break;
}
return make_pair(false, str);
return str;
}
string sgml::escapeString(string const & raw)
docstring sgml::escapeString(docstring const & raw)
{
ostringstream bin;
odocstringstream bin;
for(string::size_type i = 0; i < raw.size(); ++i) {
bool ws;
string str;
boost::tie(ws, str) = sgml::escapeChar(raw[i]);
bin << str;
for(docstring::size_type i = 0; i < raw.size(); ++i) {
bin << sgml::escapeChar(raw[i]);
}
return bin.str();
}

View File

@ -31,13 +31,12 @@ namespace sgml {
/**
* Escape the given character, if necessary,
* to an SGML entity. Returns true
* if it was a whitespace character.
* to an SGML entity.
*/
std::pair<bool, std::string> escapeChar(char c);
docstring escapeChar(char_type c);
/// Escape a word instead of a single character
std::string escapeString(std::string const & raw);
docstring escapeString(docstring const & raw);
/// replaces illegal characters from SGML/XML ID attributes
std::string cleanID(Buffer const & buf, OutputParams const & runparams,