|
|
Home » U++ Library support » U++ Core » Suggest Xmlize support for Value
Suggest Xmlize support for Value [message #15861] |
Tue, 13 May 2008 00:34 |
Mindtraveller
Messages: 917 Registered: August 2007 Location: Russia, Moscow rgn.
|
Experienced Contributor |
|
|
In the process of mastering U++ XML abilities I`ve met a problem with storing Value variables in XML, also with storing Value vectors and maps. I suggest following code to solve this problem:
template<> void Upp::Xmlize(XmlIO xml, Value& v)
{
if (xml.IsLoading())
{
String s;
xml.Attr("value", s);
StringStream ss(s);
ss.SetLoading();
ss % v;
}
else
{
StringStream ss;
ss.SetStoring();
ss % v;
xml.Attr("value",(String) ss);
}
}
P.S. Maybe it would also be useful to add raw data <-> string uuencoding if it is vital to comply XML standard at 100% (some XML readers doesn`t read "non standard" characters like ).
[Updated on: Tue, 13 May 2008 00:50] Report message to a moderator
|
|
|
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: Fri Mar 29 15:43:38 CET 2024
Total time taken to generate the page: 0.01899 seconds
|
|
|