Re: strange behaviour of hasPrefix
Re: strange behaviour of hasPrefix
- Subject: Re: strange behaviour of hasPrefix
- From: Andy Lee <email@hidden>
- Date: Thu, 04 May 2017 17:30:08 -0400
On May 3, 2017, at 11:25 AM, Gerriet M. Denkmann <email@hidden> wrote:
> Why has test2 no prefix?
Seems like a subtle difference between the implementations of __NSCFConstantString/__NSCFString and NSPathStore2/NSString.
I ran your code and got the same results. I also added a bunch of sanity checks and they all returned 1 (YES) as expected.
NSLog(@"does test1 equal pintu? %d", [test1 isEqualToString:pintu]);
NSLog(@"does test1 equal test2? %d", [test1 isEqualToString:test2]);
NSLog(@"does test2 equal pintu? %d", [test2 isEqualToString:pintu]);
NSLog(@"does test2 have test1 as prefix? %d", [test2 hasPrefix:test1]);
NSLog(@"does test2 have pintu as prefix? %d", [test2 hasPrefix:pintu]);
NSLog(@"does test1 have test1 as prefix? %d", [test1 hasPrefix:test1]);
NSLog(@"does test2 have test1 all as prefix? %d", [test2 hasPrefix:[test1 substringToIndex:[test1 length]]]);
NSLog(@"do test1 and test2 have the same first character? %d", ([test1 characterAtIndex:0] == [test2 characterAtIndex:0]));
NSLog(@"do test1 and test2 have the same second character? %d", ([test1 characterAtIndex:1] == [test2 characterAtIndex:1]));
It seems to me if two NSStrings are the same according to isEqualToString:, then we should expect them to return the same YES/NO answer for any given hasPrefix: test, regardless of which classes from the NSString class cluster they happen to be. But maybe that's not true, for some subtle encoding reason I don't understand.
--Andy
_______________________________________________
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