• 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: Something strange in the NSString documentation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Something strange in the NSString documentation


  • Subject: Re: Something strange in the NSString documentation
  • From: Jack Nutting <email@hidden>
  • Date: Fri, 19 Aug 2005 15:18:09 +0200

On 8/19/05, Stephane Sudre <email@hidden> wrote:
> The strange point is the link to -compare:options:range:.
>
> The way I understand how the compare:options:range method is working
> "compared" to the rangeOfString;options: API and the way the
> documentation is presenting things, I would tend to believe that the
> link shall be to the -rangeOfString;options: instead.
>
> For instance, if I want to check if a string has a suffix with an
> insensitive case search, the shortest code (with the smallest number of
> arguments) could look like this:
>
> - (BOOL) hasCaseInsensitiveSuffix:(NSString *) inSuffix
> {
>         NSRange tRange;
>
>         tRange=[self rangeOfString: inSuffix options:
> NSCaseInsensitiveSearch+NSBackwardsSearch+NSAnchoredSearch];
>
>         return (tRange.location!=NSNotFound)
> }

That may be the shortest code, but it can also be terribly
inefficient, depending on the size of your string, since it will
search backwards through the *entire*string*.  Using
-compare:options:range:, you can compare just the ending which is much
more efficient.  It's probably done something like this (which is not
much longer than your example):

- (BOOL) hasCaseInsensitiveSuffix:(NSString *) inSuffix
{
    int suffixLength = [inSuffix length];
    int myLength = [self length];
    if ([self length] < [inSuffix length]) return NO;
    return [self compare:inSuffix options:NSCaseInsensitiveSuffix
range:NSMakeRange([self length] - suffixLength,
suffixLength]==NSOrderedSame;
}

--
// jack
// http://www.nuthole.com
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Something strange in the NSString documentation
      • From: Stephane Sudre <email@hidden>
References: 
 >Something strange in the NSString documentation (From: Stephane Sudre <email@hidden>)

  • Prev by Date: NSPopUpButton Crashing When NSBackgroundColorAttributeName Is Set
  • Next by Date: Re: Helper tool crashes(without crash logs) at log out
  • Previous by thread: Something strange in the NSString documentation
  • Next by thread: Re: Something strange in the NSString documentation
  • Index(es):
    • Date
    • Thread