From ce828f5acf95cc239f08eadd39dfbe8b4b4241bd Mon Sep 17 00:00:00 2001 From: Richard Frith-Macdonald Date: Fri, 26 Sep 2003 15:39:14 +0000 Subject: [PATCH] Minor bugfix .. pathExtension git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@17729 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 6 ++++++ Source/NSString.m | 29 ++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 49c5a7741..97c3b0daa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2003-09-26 Richard Frith-Macdonald + + * Source/NSString.m: Fix pathExtension bug reported by Roland + Schwingel. Was failing to handle the case when a dot appears + inside a path component properly. + 2003-09-25 Richard Frith-Macdonald * Source/NSConnection.m: Fix obscure bug releasing in-progress diff --git a/Source/NSString.m b/Source/NSString.m index def39aa0e..b98a660d9 100644 --- a/Source/NSString.m +++ b/Source/NSString.m @@ -2869,7 +2869,7 @@ handle_printf_atsign (FILE *stream, - (NSString*) pathExtension { NSRange range; - NSString *substring; + NSString *substring = @""; unsigned int length = [self length]; /* @@ -2880,16 +2880,31 @@ handle_printf_atsign (FILE *stream, length--; } range = NSMakeRange(0, length); + + /* + * Look for a dot in the path ... if there isn't one, there is no extension. + */ range = [self rangeOfString: @"." options: NSBackwardsSearch range: range]; - if (range.length == 0) - { - substring = @""; - } - else + if (range.length > 0) { + NSRange sepRange; + + /* + * Found a dot, so we determine the range of the (possible) + * path extension, then cvheck to see if we have a path + * separator within it ... if we have a path separator then + * the dot is inside the last path component and there is + * thereofore no extension. + */ range.location++; range.length = length - range.location; - substring = [self substringFromRange: range]; + sepRange = [self rangeOfCharacterFromSet: pathSeps() + options: NSBackwardsSearch + range: range]; + if (sepRange.length == 0) + { + substring = [self substringFromRange: range]; + } } return substring;