On Feb 15, 2011, at 4:27 PM, James Hurley wrote:
Peter,
Thanks. Very interesting.
A couple of questions.
Is "lineoffsets" a custom function or a typo?
And what is the "sr" function?
Thanks again,
Jim Hurley
On Feb 15, 2011, at 10:00 AM, use-livecode-requ...@lists.runrev.com
wrote:
function getMileage
put "http://maps.googleapis.com/maps/api/directions/xml?" & \
"origin=<tOrig>&destination=<tDest>&sensor=false" into tURL
put fld "from" into tStart
put fld "to" into tEnd
replace "<tOrig>" with urlEncode(tStart) in tURL
replace "<tDest>" with urlEncode(tEnd) in tURL
put URL tURL into t
put lineoffsets("<distance>",t) into startSect
put item -1 of startSect into startSect
put lineoffsets("</distance>",t) into endSect
put item -1 of endSect into endSect
if startSect = 0 or endSect = 0 then
beep
exit to top
end if
put line startSect+1 to endSect-1 of t into tSect
put lineoffset("<text>",tSect) into dLine
if dLine = 0 then
beep
exit to top
end if
put sr(line startSect + dLine of t) into tMiles
-- <text>3.6 mi</text>
replace "<text>" with empty in tMiles
delete word -1 of tMiles
return tMiles
end getMileage
Ah, sorry, I forgot. A couple of other utility functions from my
personal library that I use constantly -- so much so that it didn't
register that they weren't LC-native. The offsets() function can be
expanded if desired to wordoffsets(), itemoffsets(), etc. Exercise
left to the reader, as they say (or email me off list if you need them
and you're too busy to do it yourself).
--------
function offsets str,ctr
-- returns a comma-delimited list of all the offsets of str in ctr
-- if none found, returns 0
put "" into mosList
put 0 into startPoint
repeat
put offset(str,ctr,startPoint) into os
if os = 0 then exit repeat
add os to startPoint
put startPoint & "," after mosList
end repeat
if char -1 of mosList = "," then delete last char of mosList
if mosList = "" then return "0"
return mosList
end offsets
-- To find the last of multiple matches for str in ctr, use
-- item -1 of lineoffsets(str,ctr)
-- (which is what is done above in the getMileage handler.)
function sr str
-- strips returns and other white space from str, fore & aft
return word 1 to (the number of words of str) of str
end sr
---------
-- Peter
Peter M. Brigham
pmb...@gmail.com
http://home.comcast.net/~pmbrig
_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode