• 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: Swift: How to determine if a Character represents whitespace?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Swift: How to determine if a Character represents whitespace? (From: Charles Jenkins <email@hidden>)
 >Re: Swift: How to determine if a Character represents whitespace? (From: Charles Srstka <email@hidden>)
 >Re: Swift: How to determine if a Character represents whitespace? (From: Charles Jenkins <email@hidden>)
 >Re: Swift: How to determine if a Character represents whitespace? (From: Quincey Morris <email@hidden>)
 >Re: Swift: How to determine if a Character represents whitespace? (From: Charles Jenkins <email@hidden>)
 >Re: Swift: How to determine if a Character represents whitespace? (From: Quincey Morris <email@hidden>)
 >Re: Swift: How to determine if a Character represents whitespace? (From: Charles Jenkins <email@hidden>)
 >Re: Swift: How to determine if a Character represents whitespace? (From: Quincey Morris <email@hidden>)
 >Re: Swift: How to determine if a Character represents whitespace? (From: Charles Jenkins <email@hidden>)

  • Prev by Date: Re: Swift: How to determine if a Character represents whitespace?
  • Next by Date: Re: Swift: How to determine if a Character represents whitespace?
  • Previous by thread: Re: Swift: How to determine if a Character represents whitespace?
  • Next by thread: Re: Swift: How to determine if a Character represents whitespace?
  • Index(es):
    • Date
    • Thread