Re: (no subject)
Re: (no subject)
- Subject: Re: (no subject)
- From: Nigel Garvey <email@hidden>
- Date: Wed, 20 Feb 2002 00:30:46 +0000
I wrote on Tue, 19 Feb 2002 11:34:04 +0000:
>
Shane Stanley wrote on Tue, 19 Feb 2002 11:54:42 +1100:
>
>
>On 19/2/02 10:32 AM +1000, Pat Cannon, email@hidden, wrote:
>
>
>> repeat
>
>> try
>
>> set nextPointer to pointer + chunkSize
>
>> set pdfText to read pdfFile from pointer to nextPointer
>
>> if pdfText contains searchString then
>
>> set textFound to true
>
>> exit repeat
>
>> end if
>
>> on error -- I'm assuming the error is EOF
>
>> exit repeat
>
>> end try
>
>> set pointer to nextPointer
>
>> end repeat
>
>
>But you're not allowing for the possibility of "CalGray" falling across the
>
>boundary of two chunks. To be safe, you need to do something like store the
>
>last paragraph of each chunk, then concatenate the next chunk to it each
>
>time.
>
>
Or, at the end of the loop, set pointer to nextPointer - searchString's
>
length + 1.
To which Shane replied:
>
Yep; I was trying to avoid the maths ;-)
:-) In fact, I suffered a maths failure myself here. To be really mean,
it should be 'set pointer to nextPointer - searchString's length + 2'.
The last opportunity for 'searchString' to be fully contained in the
chunk of file being examined is when its last character is at
nextPointer. Its first character would then be at nextPointer -
searchString's length + 1. If it hasn't turned up by then, the search
should resume at the byte after that.
After realising this, I've been pottering during my spare time today with
my own "Is this string in this large file?" handler:
on isInFile(theFile, str)
set readStart to 1
set offsetDifference to 4095 -- read-chunk size (4096) - 1
set overlapDifference to (count str) - 2
set strFound to false
try
-- 'alias' stops the file being created if it doesn't exist
set fRef to open for access alias (theFile as string)
set endOfFile to get eof fRef
if endOfFile > 0 then
set readEnd to missing value -- dummy, to get into the repeat
repeat until strFound or readEnd = endOfFile
set readEnd to readStart + offsetDifference
if readEnd > endOfFile then set readEnd to endOfFile
read fRef as text from readStart to readEnd
if the result contains str then
set strFound to true
else
set readStart to readEnd - overlapDifference
end if
end repeat
end if
on error msg
display dialog msg buttons {"OK"} default button 1 with icon stop
end try
try
close access fRef
on error
end try
return strFound
end isInFile
NG
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.