* Source/NSAttributedString.m: Fix keyeded encodgin decoding for

both NSAttributedString and NSMutableAttributedString.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@28453 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
fredkiefer 2009-08-11 17:01:50 +00:00
parent f1d2144948
commit 523ae77842
2 changed files with 63 additions and 34 deletions

View file

@ -1,3 +1,8 @@
2009-08-11 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSAttributedString.m: Fix keyeded encodgin decoding for
both NSAttributedString and NSMutableAttributedString.
2009-08-11 Richard Frith-Macdonald <rfm@gnu.org> 2009-08-11 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSData.m: Fix memory leak introduced with GC changes. * Source/NSData.m: Fix memory leak introduced with GC changes.

View file

@ -152,19 +152,32 @@ static Class GSMutableAttributedStringClass;
- (void) encodeWithCoder: (NSCoder*)aCoder - (void) encodeWithCoder: (NSCoder*)aCoder
{ {
NSRange r = NSMakeRange(0, 0); if ([aCoder allowsKeyedCoding])
unsigned index = NSMaxRange(r);
unsigned length = [self length];
NSString *string = [self string];
NSDictionary *attrs;
[aCoder encodeObject: string];
while (index < length)
{ {
attrs = [self attributesAtIndex: index effectiveRange: &r]; [aCoder encodeObject: [self string] forKey: @"NSString"];
index = NSMaxRange(r); if ([self length] > 0)
[aCoder encodeValueOfObjCType: @encode(unsigned) at: &index]; {
[aCoder encodeObject: attrs]; NSDictionary* attrs = [self attributesAtIndex: 0 effectiveRange: NULL];
[aCoder encodeObject: attrs forKey: @"NSAttributes"];
}
}
else
{
NSRange r = NSMakeRange(0, 0);
unsigned index = NSMaxRange(r);
unsigned length = [self length];
NSString *string = [self string];
NSDictionary *attrs;
[aCoder encodeObject: string];
while (index < length)
{
attrs = [self attributesAtIndex: index effectiveRange: &r];
index = NSMaxRange(r);
[aCoder encodeValueOfObjCType: @encode(unsigned) at: &index];
[aCoder encodeObject: attrs];
}
} }
} }
@ -188,7 +201,7 @@ static Class GSMutableAttributedStringClass;
} }
else else
{ {
unsigned index; unsigned index;
NSDictionary *attrs; NSDictionary *attrs;
[aDecoder decodeValueOfObjCType: @encode(unsigned) at: &index]; [aDecoder decodeValueOfObjCType: @encode(unsigned) at: &index];
@ -627,42 +640,53 @@ static Class GSMutableAttributedStringClass;
- (id) initWithCoder: (NSCoder*)aDecoder - (id) initWithCoder: (NSCoder*)aDecoder
{ {
NSString *string = [aDecoder decodeObject]; if ([aDecoder allowsKeyedCoding])
unsigned length = [string length];
if (length == 0)
{ {
self = [self initWithString: string attributes: nil]; NSString *string = [aDecoder decodeObjectForKey: @"NSString"];
NSDictionary *attributes = [aDecoder decodeObjectForKey: @"NSAttributes"];
self = [self initWithString: string attributes: attributes];
} }
else else
{ {
unsigned index; NSString *string = [aDecoder decodeObject];
NSDictionary *attrs; unsigned length = [string length];
[aDecoder decodeValueOfObjCType: @encode(unsigned) at: &index]; if (length == 0)
attrs = [aDecoder decodeObject];
if (index == length)
{ {
self = [self initWithString: string attributes: attrs]; self = [self initWithString: string attributes: nil];
} }
else else
{ {
NSRange r = NSMakeRange(0, index); unsigned index;
unsigned last = index; NSDictionary *attrs;
self = [self initWithString: string attributes: nil]; [aDecoder decodeValueOfObjCType: @encode(unsigned) at: &index];
[self setAttributes: attrs range: r]; attrs = [aDecoder decodeObject];
while (index < length) if (index == length)
{ {
[aDecoder decodeValueOfObjCType: @encode(unsigned) self = [self initWithString: string attributes: attrs];
at: &index]; }
attrs = [aDecoder decodeObject]; else
r = NSMakeRange(last, index - last); {
NSRange r = NSMakeRange(0, index);
unsigned last = index;
self = [self initWithString: string attributes: nil];
[self setAttributes: attrs range: r]; [self setAttributes: attrs range: r];
last = index; while (index < length)
{
[aDecoder decodeValueOfObjCType: @encode(unsigned)
at: &index];
attrs = [aDecoder decodeObject];
r = NSMakeRange(last, index - last);
[self setAttributes: attrs range: r];
last = index;
}
} }
} }
} }
return self; return self;
} }