• 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: How to count composed characters in NSString?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to count composed characters in NSString?


  • Subject: Re: How to count composed characters in NSString?
  • From: Kirk Kerekes <email@hidden>
  • Date: Sun, 28 Sep 2008 14:30:37 -0500

Users don't see characters, they see glyphs. If you want your count to maximally agree with user perception, you need to be counting glyphs, not characters.

See NSLayoutManager, esp:

	- (NSRange)glyphRangeForCharacterRange:(NSRange)charRange

 -- and friends.

If you are showing strings to the user, do so in an NSTextView, and then query the NSLayoutManager associated with that view.


On Sep 27, 2008, at 9:37 PM, email@hidden wrote:

Message: 15
Date: Sat, 27 Sep 2008 21:23:25 +0200
From: David Niemeijer <email@hidden>
Subject: How to count composed characters in NSString?
To: email@hidden
Message-ID: <email@hidden>
Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes

Hi,

I have been trying to find this in the documentation and list archives
but without success so far. What is the best way to count the number
of characters in an NSString taking account of the fact that some
characters may take up multiple 16 bit slots. Using "-
(NSUInteger)length" is thus not the right way. Using a series of calls
to "rangeOfComposedCharacterSequenceAtIndex:" seems like a
possibility, but I am not sure this would be the most efficient way.
Is there a simple and straightforward solution? I would like to be
able to display the number of characters in a string and not report
the wrong results for foreign languages (which I would get if I simply
took the length of the string). I need a solution that does not only
work in Leopard (i.e. CFStringTokenizer is not an option) and that
does not require using the lower level UCFindTextBreak.

Thanks,

david.

_______________________________________________

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


  • Prev by Date: Re: How to count composed characters in NSString?
  • Next by Date: Re: Restoring a .nib's Edit menu
  • Previous by thread: Re: How to count composed characters in NSString?
  • Next by thread: Re: How to count composed characters in NSString?
  • Index(es):
    • Date
    • Thread