• 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: Highlighting chars in an NSTextField?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Highlighting chars in an NSTextField?


  • Subject: Re: Highlighting chars in an NSTextField?
  • From: Clark Williams <email@hidden>
  • Date: Fri, 27 Jan 2012 10:03:43 -0800

On Jan 27, 2012, at 08:07, Ross Carter wrote:

> On Jan 26, 2012, at 7:53 PM, Clark Williams wrote:
>
>>
>> something.m file in an action or message received method:
>>   if ( charIndex < [ [ theAS string ] length ] ) {
>>   	NSRange nxt2Chars = NSMakeRange ( charIndex, 2 );
>>   	[ theAS beginEditing ];
>>   	[ theAS addAttribute: NSBackgroundColorAttributeName
>>                              value: [ NSColor orangeColor ]
>>                             range: nxt2Chars ];
>> 	[ theAS endEditing ];
>> 	[ currentDataTextBox setAttributedStringValue:theAS ];
>>   }
>>   charIndex += 2;
>
> One small comment, FWIW: your code is not Unicode-safe. What if an accented e is composed of two characters instead of one? (Both representations are valid.) Your highlighting will be off. There is not necessarily a 1-to1 correspondence between unichars in a NSString and characters rendered on screen. That's why we have rangeOfComposedCharacterSequenceAtIndex:.
>
> Of course, if you absolutely know that the string is composed entirely of base characters, this precaution is unnecessary.
>
> Ross
>

Ross,
Thank you!
You are of course absolutely correct!
In this case I know there are exactly 8-bit ASCII values (unsigned char) used.
As these are by design byte values.
Still…it wouldn't hurt to do it correctly.

Clark
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >Highlighting chars in an NSTextField? (From: Clark Williams <email@hidden>)
 >Re: Highlighting chars in an NSTextField? (From: Fritz Anderson <email@hidden>)
 >Re: Highlighting chars in an NSTextField? (From: Christiaan Hofman <email@hidden>)
 >Re: Highlighting chars in an NSTextField? (From: Clark Williams <email@hidden>)
 >Re: Highlighting chars in an NSTextField? (From: Ross Carter <email@hidden>)

  • Prev by Date: Re: Highlighting chars in an NSTextField?
  • Next by Date: Team member refresh not allowed
  • Previous by thread: Re: Highlighting chars in an NSTextField?
  • Next by thread: Team member refresh not allowed
  • Index(es):
    • Date
    • Thread