• 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: wordRangeForRange implememtation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: wordRangeForRange implememtation


  • Subject: Re: wordRangeForRange implememtation
  • From: Jérome Laurens <email@hidden>
  • Date: Sun, 11 May 2008 23:45:22 +0200


Le 11 mai 08 à 04:42, Ali Ozer a écrit :

To extract a word range from a string, it may be easier to use something like NSScanner:

// Defining the words
NSCharacterSet *validWordSet = [NSCharacterSet alphanumericCharacterSet]; // Or however you want to define words
NSCharacterSet *wordBreakSet = [validWordSet invertedSet];


// Set up a scanner
NSScanner *scanner = [NSScanner scannerWithString:yourString];
[scanner setCharactersToBeSkipped:nil]; // We will manage skipping ourselves (since we need to find the beginning of the word)

A long time ago, I played seriously with NSScanner to implement some syntax coloring.
It was unbearably slow, and I ended with the conclusion that [NSScanner scannerWithString:]; was making a copy of the given string.
So I reimplemented my own NSScanner and it was way faster.


Is it true that NSScanner duplicates the string?

TIA

_______________________________________________

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: wordRangeForRange implememtation
      • From: "Adam R. Maxwell" <email@hidden>
    • Re: wordRangeForRange implememtation
      • From: "Kyle Sluder" <email@hidden>
References: 
 >wordRangeForRange implememtation (From: Lincoln Green <email@hidden>)
 >Re: wordRangeForRange implememtation (From: Ali Ozer <email@hidden>)

  • Prev by Date: Re: Problems with object observing own key
  • Next by Date: Re: Problems with object observing own key
  • Previous by thread: Re: wordRangeForRange implememtation
  • Next by thread: Re: wordRangeForRange implememtation
  • Index(es):
    • Date
    • Thread