Re: styled text to record, ok. But record to styled text?
Re: styled text to record, ok. But record to styled text?
- Subject: Re: styled text to record, ok. But record to styled text?
- From: Walter Ian Kaye <email@hidden>
- Date: Sat, 24 Jan 2004 21:36:10 -0800
At 01:57a +0000 01/25/2004, Nigel Garvey didst inscribe upon an
electronic papyrus:
Walter Ian Kaye wrote on Sat, 24 Jan 2004 08:51:34 -0800:
>At 01:47p +0000 01/24/2004, Nigel Garvey didst inscribe upon an
>electronic papyrus:
>> about saving
>>styled text to file and retrieving it as such.
>>The list approach is a nice one for this. It's also good for when
>>you don't know at the time of writing what sort of data you'll be
>>saving and retrieving
>
>Hmm... so I can have a bunch of known classes that can be written
>as-is, and then everything else can be embedded in a list... and then
>if the data read back starts with "list---+" (where ---+ is 0x00 0x00
>0x00 0x01 indicating a one-item list) then read it back as list and
>un-list it. That oughta work, right?
Well I wouldn't like to have to analyse the data formats in the file
itself. :-) My point was that if you know you'll be saving an item of an
unforeknown type, you can save it wrapped in a list and not have to worry
about how to read it back. You read it back 'as list'. After that, it's
relatively easy to test the class(es) of whatever's in the list.
True, but I'm *really* just trying to *flatten* AS datatypes, and so
I'd rather not use a list wrapper unless it is impossible to flatten
without.
Similarly with multiple items of known type(s). One problem with reading
these back individually from a file is that you have to know how long
each one is. If you've saved two dates, say, the following isn't good
enough:
set date1 to (read fRef as date)
set date2 to (read fRef as date)
The first date's set OK, but the file's read through to the end, causing
an eof error when you try to read the second date. But this does work:
set date1 to (read fRef for 8 as date)
set date2 to (read fRef as date) -- 'for 8' if more data to read
Popping everything into one list saves a lot of hassle and prior research.
In general, yes. But since I'm just writing a single datatype at a
time (cuz it's flatten/unflatten routines) I've only got the "to list
or not to list" thing to deal with. Permanent storage of the
flattened data would be elsewhere (such as in a plist preferences
file).
Something interesting I've just discovered: the 'write' command's 'as
list' parameter encapsulates rather than coerces:
set r to {a:1, b:2}
write r as list to fRef -- 'write' parameter
read fRef from 1 as list
--> {{a:1, b:2}}
Which is what I was counting on (since it's our workaround!).
But:
set r to {a:1, b:2}
write (r as list) to fRef -- AS coercion
read fRef from 1 as list
--> {1, 2}
Ah, parentheses.
>I really do wish I could store the datatypes directly, without a list
>wrapper.
I certainly agree as far as styled text is concerned. :-) Testing in
10.2.8, so far I've had no trouble with text, Unicode Text, lists,
records, dates, aliases, integers, or reals. But only in the case of text
is is the 'as' parameter optional when reading and the type class
specified has to be precisely the same as the class of the saved item.
'As number' doesn't work. So far, I've only found that styled text,
booleans, Wednesdays, and other items whose class is 'class' need to be
"enlisted". I haven't tried application-specific classes yet.
Thanks for testing!
I figure 'picture' oughta work raw/plain, and it's easy to get a PICT
into a variable... but how would I test TIFF picture? It oughta work
raw/plain, eh?
-boo
_______________________________________________
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.