mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-21 06:45:39 -06:00
Core: XML RegisterEntity
git-svn-id: svn://ultimatepp.org/upp/trunk@6072 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
97187d6845
commit
238fbf6c39
4 changed files with 33 additions and 33 deletions
|
|
@ -177,37 +177,19 @@ void XmlParser::Ent(StringBuffer& out)
|
|||
term = t;
|
||||
return;
|
||||
}
|
||||
if(t[0] == 'l' && t[1] == 't' && t[2] == ';') {
|
||||
t += 3;
|
||||
out.Cat('<');
|
||||
const char *b = t;
|
||||
while(*t && *t != ';')
|
||||
t++;
|
||||
if(*t == ';') {
|
||||
int q = entity.Find(String(b, t));
|
||||
if(q >= 0) {
|
||||
out.Cat(entity[q]);
|
||||
term = t + 1;
|
||||
return;
|
||||
}
|
||||
else
|
||||
if(t[0] == 'g' && t[1] == 't' && t[2] == ';') {
|
||||
t += 3;
|
||||
out.Cat('>');
|
||||
}
|
||||
else
|
||||
if(t[0] == 'a')
|
||||
if(t[1] == 'm' && t[2] == 'p' && t[3] == ';') {
|
||||
t += 4;
|
||||
out.Cat('&');
|
||||
}
|
||||
else
|
||||
if(t[1] == 'p' && t[2] == 'o' && t[3] == 's' && t[4] == ';') {
|
||||
t += 5;
|
||||
out.Cat('\'');
|
||||
}
|
||||
else
|
||||
out.Cat('&');
|
||||
else
|
||||
if(t[0] == 'q' && t[1] == 'u' && t[2] == 'o' && t[3] == 't' && t[4] == ';') {
|
||||
t += 5;
|
||||
out.Cat('\"');
|
||||
}
|
||||
else
|
||||
out.Cat('&');
|
||||
term = t;
|
||||
}
|
||||
|
||||
inline static bool IsXmlNameChar(int c)
|
||||
{
|
||||
|
|
@ -425,6 +407,11 @@ void XmlParser::Next()
|
|||
}
|
||||
}
|
||||
|
||||
void XmlParser::RegisterEntity(const String& id, const String& text)
|
||||
{
|
||||
entity.Add(id, text);
|
||||
}
|
||||
|
||||
bool XmlParser::IsEof()
|
||||
{
|
||||
return type == XML_EOF;
|
||||
|
|
@ -677,6 +664,11 @@ int XmlParser::GetColumn() const
|
|||
|
||||
XmlParser::XmlParser(const char *s)
|
||||
{
|
||||
RegisterEntity("lt", "<");
|
||||
RegisterEntity("gt", ">");
|
||||
RegisterEntity("amp", "&");
|
||||
RegisterEntity("apos", "\'");
|
||||
RegisterEntity("quot", "\"");
|
||||
relaxed = false;
|
||||
empty_tag = false;
|
||||
npreserve = false;
|
||||
|
|
|
|||
|
|
@ -46,6 +46,8 @@ class XmlParser {
|
|||
bool preserve_blanks;
|
||||
};
|
||||
|
||||
VectorMap<String, String> entity;
|
||||
|
||||
const char *begin;
|
||||
const char *term;
|
||||
String attr1, attrval1;
|
||||
|
|
@ -74,6 +76,8 @@ class XmlParser {
|
|||
public:
|
||||
void SkipWhites();
|
||||
|
||||
void RegisterEntity(const String& id, const String& text);
|
||||
|
||||
bool IsEof();
|
||||
const char *GetPtr() const { return term; }
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,12 @@ for implementation of descent parsers of XML.&]
|
|||
[s2;%% Skips any whitespaces in the input XML.&]
|
||||
[s3; &]
|
||||
[s4; &]
|
||||
[s5;:XmlParser`:`:RegisterEntity`(const String`&`,const String`&`): [@(0.0.255) void]_[* R
|
||||
egisterEntity]([@(0.0.255) const]_[_^String^ String][@(0.0.255) `&]_[*@3 id],
|
||||
[@(0.0.255) const]_[_^String^ String][@(0.0.255) `&]_[*@3 text])&]
|
||||
[s2;%% Registers a new XML entity [%-*@3 id] with value [%-*@3 text].&]
|
||||
[s3;%% &]
|
||||
[s4; &]
|
||||
[s5;:XmlParser`:`:IsEof`(`): [@(0.0.255) bool]_[* IsEof]()&]
|
||||
[s2;%% Returns true if parser reached the end of text.&]
|
||||
[s3; &]
|
||||
|
|
@ -207,4 +213,4 @@ har]_`*[*@3 s])&]
|
|||
text must be valid through the whole parsing process (XmlParser
|
||||
does not make copy of the text).&]
|
||||
[s3; &]
|
||||
[s0; ]
|
||||
[s0; ]]
|
||||
|
|
@ -530,8 +530,7 @@ String AsQTF(const RichText& text, byte charset, dword options)
|
|||
}
|
||||
|
||||
String DeQtf(const char *s) {
|
||||
String r;
|
||||
r.Reserve(256);
|
||||
StringBuffer r;
|
||||
for(; *s; s++) {
|
||||
if(*s == '\n')
|
||||
r.Cat('&');
|
||||
|
|
@ -545,8 +544,7 @@ String DeQtf(const char *s) {
|
|||
}
|
||||
|
||||
String DeQtfLf(const char *s) {
|
||||
String r;
|
||||
r.Reserve(256);
|
||||
StringBuffer r;
|
||||
while(*s) {
|
||||
if((byte)*s > ' ' && !IsDigit(*s) && !IsAlpha(*s) && (byte)*s < 128)
|
||||
r.Cat('`');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue