diff --git a/ChangeLog b/ChangeLog index 6e610d832..8d352d78f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-12-25 Quentin Mathe + + * Headers/Foundation/NSString.h: + * Source/NSString.m: + Added -stringByReplacingCharactersInRange:withString: (Mac OS 10.5 + method). + 2010-12-25 12:13-EST Gregory John Casamento * Tools/pl2link.m: Changes to better integrate with the GNOME diff --git a/Headers/Foundation/NSString.h b/Headers/Foundation/NSString.h index 8dd68e9f9..1fac1cad6 100644 --- a/Headers/Foundation/NSString.h +++ b/Headers/Foundation/NSString.h @@ -314,6 +314,8 @@ typedef NSUInteger NSStringEncodingConversionOptions; range: (NSRange)searchRange; - (NSString*)stringByReplacingOccurrencesOfString: (NSString*)replace withString: (NSString*)by; +- (NSString*) stringByReplacingCharactersInRange: (NSRange)aRange + withString: (NSString*)by; #endif - (id) initWithCharactersNoCopy: (unichar*)chars length: (NSUInteger)length diff --git a/Source/NSString.m b/Source/NSString.m index 7cb25314c..61d034117 100644 --- a/Source/NSString.m +++ b/Source/NSString.m @@ -1786,6 +1786,7 @@ handle_printf_atsign (FILE *stream, range: searchRange]; return [copy makeImmutableCopyOnFail: NO]; } + - (NSString*)stringByReplacingOccurrencesOfString: (NSString*)replace withString: (NSString*)by { @@ -1796,6 +1797,18 @@ handle_printf_atsign (FILE *stream, range: NSMakeRange(0, [self length])]; } +/** + * Returns a new string where the substring in the given range is replaced by + * the passed string. + */ +- (NSString*) stringByReplacingCharactersInRange: (NSRange)aRange + withString: (NSString*)by +{ + id copy = [self mutableCopy]; + [copy replaceCharactersInRange: aRange withString: by]; + return [copy makeImmutableCopyOnFail: NO]; +} + /** * Returns a substring of the receiver from character at the specified * index to the end of the string.