Re: Invisible Characters
Re: Invisible Characters
- Subject: Re: Invisible Characters
- From: Douglas Davidson <email@hidden>
- Date: Thu, 24 Oct 2002 10:16:46 -0700
On Thursday, October 24, 2002, at 09:26 AM, Roberto wrote:
Are there any invisible characters that do not have width AND can be
manually inserted into text? I'm looking for characters that will
truly be invisible to the user, but that I can use to delimit special
words in the text.
For example, I may want to insert the word "help" and be able to
locate that particular word any time I want without confusing it with
the word "help" that the user may have entered themselves. If I could
insert an invisible character before and after that particular
instance of help, then I could distinguish it from the rest of the
text.
I've tried manually inserting a NULL character (0), but the text
system doesn't seem to allow that. Anyone know of other invisible
characters that can be used in this way (or another method of
programmatically delimiting text that's invisible to the user)?
Unicode has a number of characters that could fit this description
(zero-width spaces of one sort or another), but I would like to
recommend against polluting the character stream with what is
essentially control information, if it can be avoided.
You don't say what kind of text you are talking about, but in the Cocoa
text system one is generally dealing with an NSAttributedString of some
sort or another; NSTextStorage, for example, is a subclass of
NSMutableAttributedString. Even in the case of plain text, the text
system still uses attributed strings, although the user may be
prevented from changing attributes.
The attributes generally are a better place for control information
than the character stream. You can define a custom
attribute--attribute names are just strings--and give it any value you
want for any given range of text.
You will, however, need to pay attention to what happens during copy
and paste. Ordinarily copy and paste of text goes through RTF, which
will not preserve your custom attributes. This is probably appropriate
for pasting to and from other applications. You will need to decide
what you want to happen when copying and pasting within your
application.
Douglas Davidson
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.