Re: strange behaviour of hasPrefix

2017-05-04 Thread Andy Lee
On May 3, 2017, at 11:25 AM, Gerriet M. Denkmann  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 (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: strange behaviour of hasPrefix

2017-05-03 Thread Ben Kennedy

> On 03 May 2017, at 8:25 am, Gerriet M. Denkmann  wrote:
> 
> NSString *test2 = [ @"/some/path" stringByAppendingPathComponent: pintu 
> ].lastPathComponent;  
> [ self printTestString: test2 ];  
> //  prints:   length 2 0x2d 0xe3a “-ฺ” BAD: has no prefix "-" NSPathStore2 ← 
> NSString

> Why has test2 no prefix?

If I'm reading your code right, I would imagine this is because test2 obviously 
begins with a slash ("/some/path/...") and not "-".

-[NSString hasPrefix:] :

> Returns a Boolean value that indicates whether a given string matches the 
> beginning characters of the receiver.

-ben

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com