mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 00:30:53 +00:00
Fix for substrings of mutable strings
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@8043 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
d653e380bb
commit
9a1c97fabb
3 changed files with 38 additions and 10 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2000-11-06 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* Source/GSString.m: ([GSMutableString substringWithRange:]) fix to
|
||||||
|
allocate inline string classes for substrings.
|
||||||
|
|
||||||
2000-11-04 Richard Frith-Macdonald <rfm@gnu.org>
|
2000-11-04 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Source/NSCalendarDate.m ([NSCalendarDate -initWithString:
|
* Source/NSCalendarDate.m ([NSCalendarDate -initWithString:
|
||||||
|
|
|
@ -2618,34 +2618,54 @@ transmute(ivars self, NSString *aString)
|
||||||
|
|
||||||
- (NSString*) substringFromRange: (NSRange)aRange
|
- (NSString*) substringFromRange: (NSRange)aRange
|
||||||
{
|
{
|
||||||
|
NSString *sub;
|
||||||
|
|
||||||
GS_RANGE_CHECK(aRange, _count);
|
GS_RANGE_CHECK(aRange, _count);
|
||||||
|
|
||||||
if (_flags.wide == 1)
|
if (_flags.wide == 1)
|
||||||
{
|
{
|
||||||
return [GSUnicodeStringClass stringWithCharacters:
|
sub = (NSString*)NSAllocateObject(GSUnicodeInlineStringClass,
|
||||||
self->_contents.u + aRange.location length: aRange.length];
|
_count*sizeof(unichar), NSDefaultMallocZone());
|
||||||
|
sub = [sub initWithCharactersNoCopy: self->_contents.u + aRange.location
|
||||||
|
length: aRange.length
|
||||||
|
freeWhenDone: NO];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return [GSCStringClass stringWithCString:
|
sub = (NSString*)NSAllocateObject(GSCInlineStringClass,
|
||||||
self->_contents.c + aRange.location length: aRange.length];
|
_count, NSDefaultMallocZone());
|
||||||
|
sub = [sub initWithCStringNoCopy: self->_contents.c + aRange.location
|
||||||
|
length: aRange.length
|
||||||
|
freeWhenDone: NO];
|
||||||
}
|
}
|
||||||
|
AUTORELEASE(sub);
|
||||||
|
return sub;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString*) substringWithRange: (NSRange)aRange
|
- (NSString*) substringWithRange: (NSRange)aRange
|
||||||
{
|
{
|
||||||
|
NSString *sub;
|
||||||
|
|
||||||
GS_RANGE_CHECK(aRange, _count);
|
GS_RANGE_CHECK(aRange, _count);
|
||||||
|
|
||||||
if (_flags.wide == 1)
|
if (_flags.wide == 1)
|
||||||
{
|
{
|
||||||
return [GSUnicodeStringClass stringWithCharacters:
|
sub = (NSString*)NSAllocateObject(GSUnicodeInlineStringClass,
|
||||||
self->_contents.u + aRange.location length: aRange.length];
|
_count*sizeof(unichar), NSDefaultMallocZone());
|
||||||
|
sub = [sub initWithCharactersNoCopy: self->_contents.u + aRange.location
|
||||||
|
length: aRange.length
|
||||||
|
freeWhenDone: NO];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return [GSCStringClass stringWithCString:
|
sub = (NSString*)NSAllocateObject(GSCInlineStringClass,
|
||||||
self->_contents.c + aRange.location length: aRange.length];
|
_count, NSDefaultMallocZone());
|
||||||
|
sub = [sub initWithCStringNoCopy: self->_contents.c + aRange.location
|
||||||
|
length: aRange.length
|
||||||
|
freeWhenDone: NO];
|
||||||
}
|
}
|
||||||
|
AUTORELEASE(sub);
|
||||||
|
return sub;
|
||||||
}
|
}
|
||||||
|
|
||||||
// private method for Unicode level 3 implementation
|
// private method for Unicode level 3 implementation
|
||||||
|
|
|
@ -24,6 +24,7 @@ int main()
|
||||||
id s = @"This is a test string";
|
id s = @"This is a test string";
|
||||||
id s2, s3;
|
id s2, s3;
|
||||||
int a;
|
int a;
|
||||||
|
unichar uc[6] = { '1', '2', '.', '3', '4', 0};
|
||||||
|
|
||||||
NSMutableString *fo = [NSMutableString stringWithString: @"abcdefg"];
|
NSMutableString *fo = [NSMutableString stringWithString: @"abcdefg"];
|
||||||
NS_DURING
|
NS_DURING
|
||||||
|
@ -37,6 +38,8 @@ int main()
|
||||||
s2 = NSStringFromPoint(NSMakePoint(1.374, 5.100));
|
s2 = NSStringFromPoint(NSMakePoint(1.374, 5.100));
|
||||||
print_string(s2);
|
print_string(s2);
|
||||||
|
|
||||||
|
printf("%f", [[NSString stringWithCharacters: uc length: 5] floatValue]);
|
||||||
|
|
||||||
s2 = [s copy];
|
s2 = [s copy];
|
||||||
print_string(s2);
|
print_string(s2);
|
||||||
s3 = [s2 mutableCopy];
|
s3 = [s2 mutableCopy];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue