• 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: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


  • Follow-Ups:
    • Re: Swift: How to determine if a Character represents whitespace?
      • From: Quincey Morris <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>)
 >Re: Swift: How to determine if a Character represents whitespace? (From: Quincey Morris <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