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:19:02 -0700
> On Apr 3, 2015, at 11:04 AM, Quincey Morris <email@hidden> wrote:
>
> On Apr 3, 2015, at 04:00 , Charles Jenkins <email@hidden> wrote:
>>
>> for char in String( self ).utf16 {
>> if set.characterIsMember( char ) {
>> return true
>> }
>
> Now we’re back to the place we started. This code is wrong. It fails for any code point that isn’t representable a single UTF-16 code value, and it fails for any grapheme that isn’t representable as a single code point.
No it doesn't. Give it a test.
let acuteA: Character = "\u{e1}" // An "a" with an accent
let acuteAComposed: Character = "\u{61}\u{301}" // Also an "a" with an accent
func howManyChars( c: Character) -> Int {
var count = 0
for char in String( c ).utf16 {
count += 1
}
return count
}
howManyChars(acuteA) // returns 1
howManyChars(acuteAComposed) // returns 2
The original code will return true only if all code points map to white space.
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