Re: Swift: How to determine if a Character represents whitespace?
Re: Swift: How to determine if a Character represents whitespace?
- Subject: Re: Swift: How to determine if a Character represents whitespace?
- From: Marco S Hyman <email@hidden>
- Date: Fri, 03 Apr 2015 11:02:37 -0700
> extension Character {
>
> func isMemberOfSet( set:NSCharacterSet )
> -> Bool
> {
> // The for loop only executes once;
> // its purpose is to convert Character to a type
> // you can actually do something with
> for char in String( self ).utf16 {
> if set.characterIsMember( char ) {
> return true
> }
> }
> return false
> }
>
> }
I believe your comment that the loop executes once is incorrect. It may
execute more than once when the Character is a composed character that
maps to multiple utf16 characters.
Example (stolen from this link):
http://stackoverflow.com/questions/27697508/nscharacterset-characterismember-with-swifts-character-type
let acuteA: Character = "\u{e1}" // An "a" with an accent
let acuteAComposed: Character = "\u{61}\u{301}" // Also an "a" with an accent
Both are a single Character. The latter will cause the loop to iterate twice.
Marc
_______________________________________________
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