Re: Make a version of NSData "rangeOfData: options: range:" for multiple search parameters
Re: Make a version of NSData "rangeOfData: options: range:" for multiple search parameters
- Subject: Re: Make a version of NSData "rangeOfData: options: range:" for multiple search parameters
- From: Jens Alfke <email@hidden>
- Date: Fri, 15 Apr 2016 10:14:58 -0700
> On Apr 14, 2016, at 9:33 PM, Daryle Walker <email@hidden> wrote:
>
> I need a version of the method listed in the subject that works on multiple search strings instead of one, stopping at the first & longest match. Any ideas?
Depends on your requirements…
If performance isn’t critical, just call -rangeOfData: on each search string, then pick the match with the minimum location. (If you don’t know whether performance will be critical, do it this way anyway and then profile the app to see if it’s fast enough.)
If that’s not fast enough, and the data is text, NSRegularExpression might be faster. You’ll need to construct a regex of the form “foo|bar|baz”, i.e. the search strings separated with “|”. Metachars in the search strings need to be escaped. The actual search should be fast, but constructing the regex will have some overhead.
If neither of those is good enough, then you may have to crack open some books (or search Github) to find a multiple string search algorithm.
—Jens
_______________________________________________
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