Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » U++ community news and announcements » Json Date/Time support
Re: Json Date/Time support [message #40908 is a reply to message #40907] Sun, 06 October 2013 20:06 Go to previous message
mirek is currently offline  mirek
Messages: 13976
Registered: November 2005
Ultimate Member
unodgs wrote on Sun, 06 October 2013 13:55

That's great to have it, but I had it already implemented in my private branch. But my solution checked if the json value can be converted to a date using IsDateString function:
bool IsDateString(const String& s)
{
	if(s.GetLength() != 10)
		return false;
	
	int cnt = 0;
	for(int i = 0; i < s.GetLength(); i++) {
		if(IsAlpha(s[i]) || IsSpace(s[i]))
			return false;
		if(!IsDigit(s[i]))
			 ++cnt;
	}
	return cnt == 2;
}

and then in ParseJSON I changed if(p.IsString()) section to:
if(p.IsString())
{
	String s = p.ReadString();
	if(IsDateString(s)) {
		Date d = ScanDate(s);
		if(!IsNull(d))
			return d;
	}
	return s;
}

The good thing is it does accept most of the date formats that satisfy ScanDate function.
However relaying on unofficial standard might be better.



Well, what I do like about that hack is that it quite safely excludes false positives. "\/" escape code really does not make much sense....
 
Read Message
Read Message
Read Message
Previous Topic: Ide improvements
Next Topic: ArrayCtrl: Set/Add maps
Goto Forum:
  


Current Time: Sat May 11 11:46:44 CEST 2024

Total time taken to generate the page: 0.03243 seconds