Home » U++ Library support » U++ Core » Suggest Xmlize support for Value
Re: Suggest Xmlize support for Value [message #15863 is a reply to message #15861] |
Tue, 13 May 2008 03:19 |
Mindtraveller
Messages: 917 Registered: August 2007 Location: Russia, Moscow rgn.
|
Experienced Contributor |
|
|
The problem above appeared to be more serious: some serialized strings with trailing zero bytes are automatically truncated while added to the xml. So I suggest my solution by simple uuencoding bytes:
String UUEncode(const String &s)
{
String out;
out.Reserve(s.GetCount()*2);
for (int i=0;i<s.GetCount();++i)
out+=Format("%02X",0xFF & s[i]);
return out;
}
String UUDecode(const String &s)
{
String out;
out.Reserve(s.GetCount()/2);
for (int i=0;i<s.GetCount()/2;++i)
out += (char) (0xFF & ScanInt(s.Mid(i*2,2).Begin(), NULL, 16));
return out;
}
//----------------------------------------------------------------------
NAMESPACE_UPP
template<> void Xmlize(XmlIO xml, Value& v)
{
if (xml.IsLoading())
{
String s;
xml.Attr("value", s);
StringStream ss(UUDecode(s));
ss.SetLoading();
ss % v;
}
else
{
StringStream ss;
ss.SetStoring();
ss % v;
String s(UUEncode((String) ss));
xml.Attr("value",s);
}
}
END_UPP_NAMESPACE
[Updated on: Tue, 13 May 2008 10:03] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Thu May 09 08:50:36 CEST 2024
Total time taken to generate the page: 0.02955 seconds
|