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,36 +177,18 @@ void XmlParser::Ent(StringBuffer& out)
|
||||||
term = t;
|
term = t;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(t[0] == 'l' && t[1] == 't' && t[2] == ';') {
|
const char *b = t;
|
||||||
t += 3;
|
while(*t && *t != ';')
|
||||||
out.Cat('<');
|
t++;
|
||||||
}
|
if(*t == ';') {
|
||||||
else
|
int q = entity.Find(String(b, t));
|
||||||
if(t[0] == 'g' && t[1] == 't' && t[2] == ';') {
|
if(q >= 0) {
|
||||||
t += 3;
|
out.Cat(entity[q]);
|
||||||
out.Cat('>');
|
term = t + 1;
|
||||||
}
|
return;
|
||||||
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('&');
|
||||||
out.Cat('&');
|
|
||||||
term = t;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static bool IsXmlNameChar(int c)
|
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()
|
bool XmlParser::IsEof()
|
||||||
{
|
{
|
||||||
return type == XML_EOF;
|
return type == XML_EOF;
|
||||||
|
|
@ -677,6 +664,11 @@ int XmlParser::GetColumn() const
|
||||||
|
|
||||||
XmlParser::XmlParser(const char *s)
|
XmlParser::XmlParser(const char *s)
|
||||||
{
|
{
|
||||||
|
RegisterEntity("lt", "<");
|
||||||
|
RegisterEntity("gt", ">");
|
||||||
|
RegisterEntity("amp", "&");
|
||||||
|
RegisterEntity("apos", "\'");
|
||||||
|
RegisterEntity("quot", "\"");
|
||||||
relaxed = false;
|
relaxed = false;
|
||||||
empty_tag = false;
|
empty_tag = false;
|
||||||
npreserve = false;
|
npreserve = false;
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,8 @@ class XmlParser {
|
||||||
bool preserve_blanks;
|
bool preserve_blanks;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
VectorMap<String, String> entity;
|
||||||
|
|
||||||
const char *begin;
|
const char *begin;
|
||||||
const char *term;
|
const char *term;
|
||||||
String attr1, attrval1;
|
String attr1, attrval1;
|
||||||
|
|
@ -73,6 +75,8 @@ class XmlParser {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void SkipWhites();
|
void SkipWhites();
|
||||||
|
|
||||||
|
void RegisterEntity(const String& id, const String& text);
|
||||||
|
|
||||||
bool IsEof();
|
bool IsEof();
|
||||||
const char *GetPtr() const { return term; }
|
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.&]
|
[s2;%% Skips any whitespaces in the input XML.&]
|
||||||
[s3; &]
|
[s3; &]
|
||||||
[s4; &]
|
[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]()&]
|
[s5;:XmlParser`:`:IsEof`(`): [@(0.0.255) bool]_[* IsEof]()&]
|
||||||
[s2;%% Returns true if parser reached the end of text.&]
|
[s2;%% Returns true if parser reached the end of text.&]
|
||||||
[s3; &]
|
[s3; &]
|
||||||
|
|
@ -207,4 +213,4 @@ har]_`*[*@3 s])&]
|
||||||
text must be valid through the whole parsing process (XmlParser
|
text must be valid through the whole parsing process (XmlParser
|
||||||
does not make copy of the text).&]
|
does not make copy of the text).&]
|
||||||
[s3; &]
|
[s3; &]
|
||||||
[s0; ]
|
[s0; ]]
|
||||||
|
|
@ -530,8 +530,7 @@ String AsQTF(const RichText& text, byte charset, dword options)
|
||||||
}
|
}
|
||||||
|
|
||||||
String DeQtf(const char *s) {
|
String DeQtf(const char *s) {
|
||||||
String r;
|
StringBuffer r;
|
||||||
r.Reserve(256);
|
|
||||||
for(; *s; s++) {
|
for(; *s; s++) {
|
||||||
if(*s == '\n')
|
if(*s == '\n')
|
||||||
r.Cat('&');
|
r.Cat('&');
|
||||||
|
|
@ -545,8 +544,7 @@ String DeQtf(const char *s) {
|
||||||
}
|
}
|
||||||
|
|
||||||
String DeQtfLf(const char *s) {
|
String DeQtfLf(const char *s) {
|
||||||
String r;
|
StringBuffer r;
|
||||||
r.Reserve(256);
|
|
||||||
while(*s) {
|
while(*s) {
|
||||||
if((byte)*s > ' ' && !IsDigit(*s) && !IsAlpha(*s) && (byte)*s < 128)
|
if((byte)*s > ' ' && !IsDigit(*s) && !IsAlpha(*s) && (byte)*s < 128)
|
||||||
r.Cat('`');
|
r.Cat('`');
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue