Re: Uppercasing text as it is entered
Re: Uppercasing text as it is entered
- Subject: Re: Uppercasing text as it is entered
- From: Douglas Davidson <email@hidden>
- Date: Thu, 23 Aug 2007 12:09:29 -0700
On Aug 23, 2007, at 11:51 AM, Todd Ransom wrote:
I have an app with a text view where some of the text needs to be
automatically upppercased as it is entered. I do this using a
custom attribute and a subclass of NSTextStorage that returns an
uppercase version of the text whenever that attribute is found.
This works great for English language text but I am running into
problems with some unicode characters.
I am using -[NSString uppercaseString] to uppercase the text but I
am getting an unexpected result. The German ß character returns
"SS" from uppercaseString.
In other cases entering characters using multiple keystrokes does
not work with my method. For instance, typing "opt-e e" to enter a
é character is broken because of the multiple keystrokes used to
enter the character. -[NSString uppercaseString] returns the
correct value but my NSTextStorage subclass returns a simple
capitol E.
Is the ß thing a bug in NSString? Does anyone have any advice on a
better way to uppercase text as it is entered? Remember that not
all text should be uppercased, only text with a particular custom
attribute applied to it.
ß->SS is indeed the correct uppercase mapping. Case is described in
section 4.2 of Unicode 5.0; see also <http://www.unicode.org/faq/
casemap_charprop.html> or the superseded but still informative
<http://www.unicode.org/reports/tr21/tr21-5.html> for more details.
In general, casing can change the number of characters, and can
depend on context and locale; that is why casing is defined as an
operation on NSString rather than on individual characters.
Your requirements may have been generated based on assumptions taken
from English-language usage that don't necessarily apply everywhere.
You will need to think about what you want to do in general; for
example, you might delay the uppercasing operation until the entire
range to be cased has been entered, or at least a complete word. I
would suggest modifying the text in the text storage rather than
using a custom text storage subclass.
Douglas Davidson
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden