MacOS-X stuff

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@15726 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2003-01-26 19:50:42 +00:00
parent 485132bf15
commit 82e19eb2a3
3 changed files with 80 additions and 20 deletions

View file

@ -1,3 +1,9 @@
2003-01-26 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSString.m: Added new MacOS-X method ...
([MSMutableString-replaceOccurrencesOfString:withString:options:range:])
* Source/Headers/gnustep/base/NSString.h: ditto
2003-01-26 Adam Fedor <fedor@gnu.org>
* Compiling gdl2 on MacOSX.

View file

@ -319,6 +319,10 @@ enum {
- (void) insertString: (NSString*)aString atIndex: (unsigned int)loc;
- (void) replaceCharactersInRange: (NSRange)range
withString: (NSString*)aString;
- (unsigned int) replaceOccurrencesOfString: (NSString*)replace
withString: (NSString*)by
options: (unsigned int)opts
range: (NSRange)searchRange;
- (void) setString: (NSString*)aString;
@end

View file

@ -4247,6 +4247,68 @@ handle_printf_atsign (FILE *stream,
[self subclassResponsibility: _cmd];
}
/**
* Replaces all occurrences of the replace string with the by string,
* for those cases where the entire replace string lies within the
* specified searchRange value.<br />
* The value of opts determines the direction of the search is and
* whether only leading/trailing occurrances (anchored search) of
* replace are substituted.<br />
* Raises NSInvalidArgumentException if either string argument is nil.<br />
* Raises NSRangeException if part of searchRange is beyond the end
* of the receiver.
*/
- (unsigned int) replaceOccurrencesOfString: (NSString*)replace
withString: (NSString*)by
options: (unsigned int)opts
range: (NSRange)searchRange
{
NSRange range;
unsigned int count = 0;
if (replace == nil)
{
[NSException raise: NSInvalidArgumentException
format: @"%@ nil search string", NSStringFromSelector(_cmd)];
}
if (by == nil)
{
[NSException raise: NSInvalidArgumentException
format: @"%@ nil replace string", NSStringFromSelector(_cmd)];
}
range = [self rangeOfString: replace options: opts range: searchRange];
if (range.length > 0)
{
unsigned byLen = [by length];
do
{
count++;
[self replaceCharactersInRange: range
withString: by];
if ((opts & NSBackwardsSearch) == NSBackwardsSearch)
{
searchRange.length = range.location - searchRange.location;
}
else
{
unsigned int newEnd;
newEnd = NSMaxRange(searchRange) + byLen - range.length;
searchRange.location = range.location + byLen;
searchRange.length = newEnd - searchRange.location;
}
range = [self rangeOfString: replace
options: opts
range: searchRange];
}
while (range.length > 0);
}
return count;
}
- (void) setString: (NSString*)aString
{
NSRange range = {0, [self length]};
@ -4419,31 +4481,19 @@ handle_printf_atsign (FILE *stream,
/**
* Replaces all occurrances of the string replace with the string by
* in the receiver.<br />
* Has no effect if <em>replace</em> does not occur within the
* Has no effect if replace does not occur within the
* receiver. NB. an empty string is not considered to exist within
* the receiver.
* the receiver.<br />
* Calls - replaceOccurrencesOfString:withString:options:range: passing
* zero for the options and a range from 0 with the length of the receiver.
*/
- (void) replaceString: (NSString*)replace
withString: (NSString*)by
{
NSRange range = [self rangeOfString: replace];
if (range.length > 0)
{
unsigned byLen = [by length];
do
{
[self replaceCharactersInRange: range
withString: by];
range.location += byLen;
range.length = [self length] - range.location;
range = [self rangeOfString: replace
options: 0
range: range];
}
while (range.length > 0);
}
[self replaceOccurrencesOfString: replace
withString: by
options: 0
range: NSMakeRange(0, [self length])];
}
/**