Re: FileMaker styled text [part 1 of 2]
Re: FileMaker styled text [part 1 of 2]
- Subject: Re: FileMaker styled text [part 1 of 2]
- From: Kai <email@hidden>
- Date: Mon, 23 Jun 2003 03:34:35 +0100
on Mon, 16 Jun 2003 12:54:32 +0200, EBI Aktivitet <email@hidden> wrote:
>
Den 03-06-14 23.56, skrev "Kai" <email@hidden>:
>
>> try
>
>>
>
>> --open file to read
>
>> set theFile to open for access alias theFileToRead
>
>> set theUpdateRecords to (read theFile as Unicode text)
>
>> close access theFile
>
>>
>
>> --Convert from Unicode to text
>
>> set theUpdateRecords to theUpdateRecords as text
>
>
>
> Try replacing that last line above with:
>
>
>
> -------------------------------------------------------
>
>
>
> set {text:theUpdateRecords} to theUpdateRecords as text
>
>
>
> -------------------------------------------------------
>
>
>
Fantastic! It works :-) Big thanks to all of you who helped!
>
>
However, I'm getting greedy now...
>
>
1. Kai, would you like to give an explanation on how and why your
>
{text:theUpdataeRecords} works?
I'd like to but, since it involves a bit of a hack (and because I'm only a
simple country boy), I'm not sure that I can with any certainty. However,
I'll take a stab at it...
>
In my way of seeing this, the Style class should still be preserved in
>
theUpdateRecords, but maybe (obviously) I got it all wrong...
As I understand it, coercing Unicode text to a string strips out the Unicode
data - but still leaves the style data. So while international or styled
text might return a class of 'string', it may still be coerced to a record -
to reveal its style data. (Since plain text contains no style data, any
attempt to coerce it to a record would normally error.)
Let's also make sure we understand the syntax used above for assigning
values to variables. I imagine that most of us are familiar enough with
simple assignment, such as 'set x to 5' - or even the assignment of multiple
values to a single variable, like 'set y to {"Joe", 36, true}.
Following on from that, we can also set a variable pattern (or, putting it
another way, assign values to multiple variables).
With a list, it might be done like this:
--------------------------
set {a, b, c} to {1, 2, 3}
(a + b) * c
--> 9
--------------------------
More interestingly, we can also do something like this:
--------------------------
set {a, b, c, d} to "goodbye"
{a, b, c, d} as string
--> "good"
--------------------------
Here, because the target of the set command is a list, the string "goodbye"
is 'silently' coerced to a list of the string's items (characters). Since
only 4 values are required by the target list, {a, b, c, d}, only the first
4 items of the source list, {"g", "o", "o", "d"}, are assigned.
Similarly, when a set command targets a record, assignment is confined to
only the properties from the source whose labels/keys correspond to those
specified for the target record[1].
So 'set {text:y} to x as string' is similar to 'set y to text of (x as
string)' - although only the former statement appears to result in plain
(that is, not styled) text. I therefore wonder whether another silent
coercion (to some kind of record) might be involved here. (If so, it seems
any exceptions resulting from a plain text source are being trapped, since
no errors occur.)
Certainly, we know that an explicit coercion to a record can successfully
extract plain text - simply because the record separates the text value from
the style data:
--------------------------
set x to "hello" as Unicode text
x as record
--> {<<class ktxt>>:"hello",
<<class ksty>>:<<data styl0001000000000010000E00030000000C000000000000>>}
--------------------------
One of the oft-quoted text extraction methods is therefore:
--------------------------
(x as record)'s <<class ksty>> --[2], [3]
--------------------------
However, variations like the following should also work:
--------------------------
(x as record)'s text as string
--------------------------
x as record as list as string
--------------------------
The only problem with these methods is that, because they rely on an
explicit coercion to record, they'll error if x already happens to be plain
text. If this is a possibility, then we need to add a try block:
--------------------------
try
set x to x as record as list as string
end try
--------------------------
So how does the 'set {text:x} to x as text' approach compare with the above
forms?
======================================
[please see part 2 of this message...]
--
Kai
_______________________________________________
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.