• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: reading Unicode text files before AS 1.9.1
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: reading Unicode text files before AS 1.9.1


  • Subject: Re: reading Unicode text files before AS 1.9.1
  • From: Paul Berkowitz <email@hidden>
  • Date: Thu, 04 Mar 2004 00:04:17 -0800

On 3/3/04 11:13 PM, "Donald Hall" <email@hidden> wrote:

> The test script below works correctly in AS 1.9.1, but fails in AS 1.9.
>
> My test file contains the following saved as 16 bit Unicode data:
>
> aaa<tab>bbb<tab>ccc<return>
> ddd<tab>eee<tab>fff<return>
>
> (I used TextEdit to create the file.)
>
> In AS 1.9.1 (OS 10.2.6) I get 3 "paragraphs" detected as expected,
> the last one being empty. (In other words "theData" is a list of 3
> items.)
>
> In AS 1.9 (OS 10.2.3) I get 1 paragraph (a list of 1 item) that
> contains the whole contents of the file.
>
> Can anyone suggest a way to read in Unicode text in AS 1.9 that gives
> me the correct number of paragraphs?

In ASS 1.9 the Unicode linefeed character was not a paragraph separator -
you need to do it by text item delimiters (or 1 out of 100 shell scripts
people will offer).

set uLF to (ASCII character 10) as Unicode text

set theDataText to read dataFileRef
set AppleScript's text item delimiters to {uLF}
set theData to text items of theDataText
set AppleScript's text item delimiters to {""}

Unless you think there could be more than about 4000 lines. (Actually, play
it safe wit 3900. I've seen the problem occur once at 3991.)

Back in AS 1.9 and earlier, more than 4000 or so text items could cause a
"stack overflow" error. If so you've got to do it in chunks:

try
set AppleScript's text item delimiters to {uLF}
set theData to text items of theDataText on error
set AppleScript's text item delimiters to {""}
on error
set theData to my LargeTidsList( theDataText, uLF)
end try



on LargeTidsList(theText, tid)

local newList, a, z, done

set AppleScript's text item delimiters to {tid}
set {a, z} to {1, 4000}
set newList to {}
set done to false
repeat until done
try
set newList to newList & text items a thru z of theText
set {a, z} to {a + 4000, z + 4000}
on error -- last segment, fewer than 4000
set newList to newList & text items a thru -1 of theText
set done to true
end try
end repeat
set AppleScript's text item delimiters to {""}

return newList
end LargeTidsList
--
Paul Berkowitz
_______________________________________________
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.


  • Follow-Ups:
    • Re: reading Unicode text files before AS 1.9.1
      • From: Walter Ian Kaye <email@hidden>
References: 
 >reading Unicode text files before AS 1.9.1 (From: Donald Hall <email@hidden>)

  • Prev by Date: reading Unicode text files before AS 1.9.1
  • Next by Date: Re: TechNote 2106
  • Previous by thread: reading Unicode text files before AS 1.9.1
  • Next by thread: Re: reading Unicode text files before AS 1.9.1
  • Index(es):
    • Date
    • Thread