Core: XML optimised charset handling, now supports different charset thatn UTF-8

git-svn-id: svn://ultimatepp.org/upp/trunk@11539 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2017-12-08 18:28:43 +00:00
parent 6f18938d42
commit f786cae08a
2 changed files with 22 additions and 5 deletions

View file

@ -172,9 +172,9 @@ XmlTag& XmlTag::operator()(const char *attr, double q)
force_inline
String XmlParser::Convert(StringBuffer& b)
{
if(charset == CHARSET_UTF8)
if(acharset == scharset)
return b;
return FromUtf8(String(b)).ToString();
return ToCharset(acharset, b, scharset);
}
void XmlParser::Ent(StringBuffer& out)
@ -385,6 +385,22 @@ void XmlParser::Next()
LoadMore();
if(term[0] == '?' && term[1] == '>') {
term += 2;
LLOG("XML_PI " << tagtext);
if(!tagtext.StartsWith("xml "))
return;
int q = tagtext.Find("encoding");
if(q < 0)
return;
q = tagtext.Find('\"', q);
if(q < 0)
return;
q++;
int w = tagtext.Find('\"', q);
if(w < 0)
return;
q = CharsetByName(tagtext.Mid(q, w));
if(q)
scharset = q;
return;
}
if(!HasMore())
@ -393,7 +409,6 @@ void XmlParser::Next()
line++;
tagtext.Cat(*term++);
}
LLOG("XML_PI " << tagtext);
}
else
if(*term == '/') {
@ -792,7 +807,8 @@ void XmlParser::Init()
in = NULL;
len = 0;
raw = false;
charset = GetDefaultCharset();
acharset = GetDefaultCharset();
scharset = CHARSET_UTF8;
}
XmlParser::XmlParser(const char *s)

View file

@ -84,7 +84,8 @@ class XmlParser {
int line;
byte charset;
byte acharset;
byte scharset;
void Init();
void LoadMore0();