• 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: Roland King <email@hidden>
  • Date: Mon, 06 Apr 2015 22:43:10 +0800

I have no idea how a linguistic tagger determines whitespace and whether it uses the same definition for whitespace as NSCharacterSet does. Given that it's multi-language-aware I wouldn't be shocked to find it uses some entirely different way of enumerating textual elements.

> On 6 Apr 2015, at 20:29, Gerriet M. Denkmann <email@hidden> wrote:
>
>
>> On 4 Apr 2015, at 16:13, email@hidden wrote:
>>
>> ok here’s my try, assuming NSLinguisticTagger knows what it’s doing. And yes it’s a bit stupid to use a linguistic tagger to do something like that but .. whatever
>
> Linguistic Tagger should use the same definition for "white" as NSCharacterSet.whitespaceCharacterSet.
> If this is so, this would work for all characters (even if their Unicode code point does NOT fit into an unsigned short):
>
> import Cocoa
>
> let whiteSet = NSCharacterSet.whitespaceCharacterSet()
> let testString = " ..."
>
> var i : Int = 0
> for scalar in testString.unicodeScalars
> {
> 	let uChar : UTF32Char = scalar.value
> 	let isWhite = whiteSet.longCharacterIsMember(uChar)
> 	let note = isWhite ? " whiteSpace " : " non white  "
>
> 	var stringWithScalar = "  "
> 	stringWithScalar.append(scalar)
>
> 	let indexFormated = NSString(format: "-", i++)
>
> 	let codePoint = scalar.value	//	UInt32
> 	let hexFormated = NSString(format: "%#07x", codePoint)
>
> 	println( "codePoint[" + indexFormated + "] = " + hexFormated + note + stringWithScalar)
> }
>
> Gerriet.
>
>
>


_______________________________________________

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: Converting colorspace of a CGColor
  • Next by Date: iOS 7/8 sandboxing question. Path to Documents folder changing on every app launch?
  • Previous by thread: Re: Where are my bytes?
  • Next by thread: iOS 7/8 sandboxing question. Path to Documents folder changing on every app launch?
  • Index(es):
    • Date
    • Thread