determining a plain text file

Mark Smith mark at maseurope.net
Mon Jul 10 05:02:09 EDT 2006


	From: 	  mark at maseurope.net
	Subject: 	Re: determining a plain text file
	Date: 	10 July 2006 09:45:12 BDT
	To: 	  use-revolution at lists.runrev.com

Though be aware that if you're going to need to test a lot of files,
and particularly if you're going test big files, then the regex will
be a great deal slower than than a 'repeat for each char
c...charToNum(c)' approach:

On my machine (mac PB 1.5Ghz), the first replaceText approach took
about 200 miliiiseconds on a 40k file, and about 6.5 seconds on a
1.3mb file,
where as testing each char in a repeat for loop took 1 millisecond and
7 milliseconds respectively.

The second regex approach appeared to cause Rev to hang - I got the
spinning beach ball appearing and disappearing - so I forced quit
after a minute or so.

best,

Mark

ps. the function I used was:

function isText tData
  --  put replacetext (tData,"[^\x20-\x7E\n\r\t]","") into nData
  --  return tData = nData

  repeat for each char c in tData
    add 1 to tc
    get charToNum(c)
    if it <> 9 OR it <> 10 Or it <> 13 AND it < 32 then exit repeat
  end repeat
  return tc = length(tData)
end isText



On 10 Jul 2006, at 04:33, Bill Marriott wrote:

Slightly more clever (length isn't actually needed)

put url "file:{yourfile}" into daFile
if daFile = replacetext (daFile,"[^\x20-\x7E\n\r\t]","") then put "Plain
text."


J. Landman Gay wrote:
Bill Marriott wrote:
put url "file:{yourfile}" into oneFile
put replacetext (oneFile,"[^\x20-\x7E\n\r\t]","") into twoFile
if length(oneFile) = length(twoFile) then put "It's a plain text file."

That's pretty clever.



_______________________________________________
use-revolution mailing list
use-revolution at lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your
subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution



More information about the use-livecode mailing list