> For example <cfset foo = true /> is clearly Boolean while "<cfset foo =
>  "true" /> isn't... but I can't figure out a way to determine which was 
> used after the fact.

And you most likely will not. It is, afterall, a typeless language.

There are a few ways to find out what type of data resides in a variable but
that doesn't necessarily mean that's what data type it was INTENDED to be.

Isdate()
Isnumeric()
Etc...

if I <cfset myString = "9/25/2005"> it would pass the isdate() function

<cfset var = 1> is undoubtedly a number right?
I mean I can perform math on it like so...

<cfset var = var + var> and get 2

But I can also do this... <cfset var2 = var & "string"> now its not a number
at all

I think you are opening up this can of worms in the wrong language. Then
again, I just woke up. 

..:.:.:.:.:.:.:.:.:.:.:.:.:.:.
Bobby Hartsfield
http://acoderslife.com


-----Original Message-----
From: Jim Davis [mailto:[EMAIL PROTECTED] 
Sent: Sunday, September 25, 2005 12:47 PM
To: CF-Talk
Subject: Best way of determining CF Datatypes

I'm working on an XML serializer.  It describes data types so I'm looking
for a nice way to determine datatype in CFML.

The idea is to pass in an arbitrary object (any value - a string, a query, a
number, a struct, etc).  The serializer will recurse down the object
generating the XML.  To do this it will attempt to determine the datatype of
each value it encounters. 

It's easy enough to use the various "Is" functions but they're flakey at
best for this.  Simple CF datatypes aren't clearly discoverable.  For
example:

+) Is "1" a boolean?  How about "True"?

+) Is "1e3435654" a number or a string (CF says "number")?

+) Is something that looks like a date a date or a string?

In JavaScript I settled this by only trusting "real" typed objects... Dates
had to have the Date constructor, Booleans had to Boolean constructor and so
forth... but that's not possible in CFML.

I know that, arbitrarily, I can't KNOW, for sure, whether "1" is a Boolean
or a number (or a string for that matter)... but I'd at least like to offer
some way for a developer to force the type into the assignment if possible.

For example <cfset foo = true /> is clearly Boolean while "<cfset foo =
"true" /> isn't... but I can't figure out a way to determine which was used
after the fact.

I'd also settle for a mostly right decision ladder to pick the most likely
simple type... I can then make simple type discovery an option in the parser
- but I'd rather not if I don't have to.

Anybody have any insight to how the built-in WDDX parse does this same task?

Thanks,

Jim Davis





~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Find out how CFTicket can increase your company's customer support 
efficiency by 100%
http://www.houseoffusion.com/banners/view.cfm?bannerid=49

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:219195
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to