discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bug in -[NSString pathExtension]


From: Roland Schwingel
Subject: Bug in -[NSString pathExtension]
Date: Fri, 26 Sep 2003 12:02:37 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624

Hi...

Apparently there is a bug in -[NSString pathExtension].

If you have a string @"/path/to/folder.dir/aFile" pathExtension returns @".dir/aFile" which is a bit wrong I guess. There should be @"" as return value. The attached patch fixes this.

Hope you can apply it

Roland

--- NSString.m  2003-09-26 11:19:45.000000000 +0200
+++ NSString.m.new      2003-09-26 11:48:34.000000000 +0200
@@ -2868,7 +2868,7 @@
  */
 - (NSString*) pathExtension
 {
-  NSRange      range;
+  NSRange      range,range2;
   NSString     *substring;
   unsigned int length = [self length];
 
@@ -2880,8 +2880,14 @@
       length--;
     }
   range = NSMakeRange(0, length);
-  range = [self rangeOfString: @"." options: NSBackwardsSearch range: range];
-  if (range.length == 0)
+  
+  // search for last pathSep
+  range2 = [self rangeOfCharacterFromSet: pathSeps() options: 
NSBackwardsSearch range:range];
+  // search for last @"."
+  range = [self rangeOfString: @"." options: NSBackwardsSearch range: range];
+  
+  // if @"." not found or before last pathSep
+  if (range.location == NSNotFound || (range2.location != NSNotFound && 
range.location < range2.location) )
     {
       substring = @"";
     }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]