Attributed string fixes

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@6208 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 2000-03-08 08:38:42 +00:00
parent 433d24fdb6
commit 2086baecd1
2 changed files with 200 additions and 175 deletions

View file

@ -1,3 +1,8 @@
Wed Mar 08 07:40:00 2000 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSAttributedString.m: Bugfix by fred Kiefer for extending
attributes. Related bugfixes by me, plus tidying up.
2000-03-06 Adam Fedor <fedor@gnu.org> 2000-03-06 Adam Fedor <fedor@gnu.org>
* config.guess: Better guess of NetBSD systems. * config.guess: Better guess of NetBSD systems.

View file

@ -138,8 +138,8 @@ static Class NSMutableAttributedString_concrete_class;
//NSCopying protocol //NSCopying protocol
- (id) copyWithZone: (NSZone*)zone - (id) copyWithZone: (NSZone*)zone
{ {
if ([self isKindOfClass: [NSMutableAttributedString class]] || if ([self isKindOfClass: [NSMutableAttributedString class]]
NSShouldRetainWithZone(self, zone) == NO) || NSShouldRetainWithZone(self, zone) == NO)
return [[[[self class] _concreteClass] allocWithZone: zone] return [[[[self class] _concreteClass] allocWithZone: zone]
initWithAttributedString: self]; initWithAttributedString: self];
else else
@ -220,6 +220,8 @@ static Class NSMutableAttributedString_concrete_class;
effectiveRange: &tmpRange]; effectiveRange: &tmpRange];
if ([tmpDictionary isEqualToDictionary: attrDictionary]) if ([tmpDictionary isEqualToDictionary: attrDictionary])
aRange->location = tmpRange.location; aRange->location = tmpRange.location;
else
break;
} }
while (NSMaxRange(*aRange) < NSMaxRange(rangeLimit)) while (NSMaxRange(*aRange) < NSMaxRange(rangeLimit))
{ {
@ -229,6 +231,8 @@ static Class NSMutableAttributedString_concrete_class;
effectiveRange: &tmpRange]; effectiveRange: &tmpRange];
if ([tmpDictionary isEqualToDictionary: attrDictionary]) if ([tmpDictionary isEqualToDictionary: attrDictionary])
aRange->length = NSMaxRange(tmpRange) - aRange->location; aRange->length = NSMaxRange(tmpRange) - aRange->location;
else
break;
} }
*aRange = NSIntersectionRange(*aRange,rangeLimit);//Clip to rangeLimit *aRange = NSIntersectionRange(*aRange,rangeLimit);//Clip to rangeLimit
return attrDictionary; return attrDictionary;
@ -257,7 +261,8 @@ static Class NSMutableAttributedString_concrete_class;
return attrValue; return attrValue;
} }
- (id) attribute: (NSString*)attributeName atIndex: (unsigned int)index longestEffectiveRange: (NSRange *)aRange inRange: (NSRange)rangeLimit - (id) attribute: (NSString*)attributeName atIndex: (unsigned int)index
longestEffectiveRange: (NSRange*)aRange inRange: (NSRange)rangeLimit
{ {
NSDictionary *tmpDictionary; NSDictionary *tmpDictionary;
id attrValue,tmpAttrValue; id attrValue,tmpAttrValue;
@ -286,6 +291,8 @@ static Class NSMutableAttributedString_concrete_class;
tmpAttrValue = [tmpDictionary objectForKey: attributeName]; tmpAttrValue = [tmpDictionary objectForKey: attributeName];
if (tmpAttrValue == attrValue) if (tmpAttrValue == attrValue)
aRange->location = tmpRange.location; aRange->location = tmpRange.location;
else
break;
} }
while (NSMaxRange(*aRange) < NSMaxRange(rangeLimit)) while (NSMaxRange(*aRange) < NSMaxRange(rangeLimit))
{ {
@ -296,6 +303,8 @@ static Class NSMutableAttributedString_concrete_class;
tmpAttrValue = [tmpDictionary objectForKey: attributeName]; tmpAttrValue = [tmpDictionary objectForKey: attributeName];
if (tmpAttrValue == attrValue) if (tmpAttrValue == attrValue)
aRange->length = NSMaxRange(tmpRange) - aRange->location; aRange->length = NSMaxRange(tmpRange) - aRange->location;
else
break;
} }
*aRange = NSIntersectionRange(*aRange,rangeLimit);//Clip to rangeLimit *aRange = NSIntersectionRange(*aRange,rangeLimit);//Clip to rangeLimit
return attrValue; return attrValue;
@ -326,8 +335,8 @@ static Class NSMutableAttributedString_concrete_class;
while (YES) while (YES)
{ {
if (NSIntersectionRange(ownEffectiveRange,otherEffectiveRange).length > 0 && if (NSIntersectionRange(ownEffectiveRange, otherEffectiveRange).length > 0
![ownDictionary isEqualToDictionary: otherDictionary]) && ![ownDictionary isEqualToDictionary: otherDictionary])
{ {
result = NO; result = NO;
break; break;
@ -458,7 +467,9 @@ static Class NSMutableAttributedString_concrete_class;
[self setAttributes: newDict range: effectiveRange]; [self setAttributes: newDict range: effectiveRange];
if (NSMaxRange(effectiveRange) >= NSMaxRange(aRange)) if (NSMaxRange(effectiveRange) >= NSMaxRange(aRange))
{
effectiveRange.location = NSMaxRange(aRange);//This stops the loop... effectiveRange.location = NSMaxRange(aRange);//This stops the loop...
}
else if (NSMaxRange(effectiveRange) < tmpLength) else if (NSMaxRange(effectiveRange) < tmpLength)
{ {
attrDict = [self attributesAtIndex: NSMaxRange(effectiveRange) attrDict = [self attributesAtIndex: NSMaxRange(effectiveRange)
@ -476,15 +487,16 @@ static Class NSMutableAttributedString_concrete_class;
if (!attributes) if (!attributes)
{ {
//I cannot use NSParameterAssert here, if is has to be an NSInvalidArgumentException
[NSException raise: NSInvalidArgumentException [NSException raise: NSInvalidArgumentException
format: @"attributes is nil in method -addAttributes: range: in class NSMutableAtrributedString"]; format: @"attributes is nil in method -addAttributes:range: "
@"in class NSMutableAtrributedString"];
} }
tmpLength = [self length]; tmpLength = [self length];
if (aRange.location <= 0 || NSMaxRange(aRange) > tmpLength) if (aRange.location <= 0 || NSMaxRange(aRange) > tmpLength)
{ {
[NSException raise: NSRangeException [NSException raise: NSRangeException
format: @"RangeError in method -addAttribute: value: range: in class NSMutableAttributedString"]; format: @"RangeError in method -addAttribute:value:range: "
@"in class NSMutableAttributedString"];
} }
attrDict = [self attributesAtIndex: aRange.location attrDict = [self attributesAtIndex: aRange.location
@ -500,7 +512,9 @@ static Class NSMutableAttributedString_concrete_class;
[self setAttributes: newDict range: effectiveRange]; [self setAttributes: newDict range: effectiveRange];
if (NSMaxRange(effectiveRange) >= NSMaxRange(aRange)) if (NSMaxRange(effectiveRange) >= NSMaxRange(aRange))
{
effectiveRange.location = NSMaxRange(aRange);//This stops the loop... effectiveRange.location = NSMaxRange(aRange);//This stops the loop...
}
else if (NSMaxRange(effectiveRange) < tmpLength) else if (NSMaxRange(effectiveRange) < tmpLength)
{ {
attrDict = [self attributesAtIndex: NSMaxRange(effectiveRange) attrDict = [self attributesAtIndex: NSMaxRange(effectiveRange)
@ -532,7 +546,9 @@ static Class NSMutableAttributedString_concrete_class;
[self setAttributes: newDict range: effectiveRange]; [self setAttributes: newDict range: effectiveRange];
if (NSMaxRange(effectiveRange) >= NSMaxRange(aRange)) if (NSMaxRange(effectiveRange) >= NSMaxRange(aRange))
{
effectiveRange.location = NSMaxRange(aRange);//This stops the loop... effectiveRange.location = NSMaxRange(aRange);//This stops the loop...
}
else if (NSMaxRange(effectiveRange) < tmpLength) else if (NSMaxRange(effectiveRange) < tmpLength)
{ {
attrDict = [self attributesAtIndex: NSMaxRange(effectiveRange) attrDict = [self attributesAtIndex: NSMaxRange(effectiveRange)
@ -548,21 +564,24 @@ static Class NSMutableAttributedString_concrete_class;
withAttributedString: attributedString]; withAttributedString: attributedString];
} }
- (void) insertAttributedString: (NSAttributedString *)attributedString atIndex: (unsigned int)index - (void) insertAttributedString: (NSAttributedString*)attributedString
atIndex: (unsigned int)index
{ {
[self replaceCharactersInRange: NSMakeRange(index,0) [self replaceCharactersInRange: NSMakeRange(index,0)
withAttributedString: attributedString]; withAttributedString: attributedString];
} }
- (void) replaceCharactersInRange: (NSRange)aRange withAttributedString: (NSAttributedString *)attributedString - (void) replaceCharactersInRange: (NSRange)aRange
withAttributedString: (NSAttributedString*)attributedString
{ {
NSRange effectiveRange,clipRange,ownRange; NSRange effectiveRange;
NSRange clipRange;
NSRange ownRange;
NSDictionary *attrDict; NSDictionary *attrDict;
NSString *tmpStr; NSString *tmpStr;
tmpStr = [attributedString string]; tmpStr = [attributedString string];
[self replaceCharactersInRange: aRange [self replaceCharactersInRange: aRange withString: tmpStr];
withString: tmpStr];
effectiveRange = NSMakeRange(0,0); effectiveRange = NSMakeRange(0,0);
clipRange = NSMakeRange(0,[tmpStr length]); clipRange = NSMakeRange(0,[tmpStr length]);
@ -576,7 +595,8 @@ static Class NSMutableAttributedString_concrete_class;
} }
} }
- (void) replaceCharactersInRange: (NSRange)aRange withString: (NSString *)aString - (void) replaceCharactersInRange: (NSRange)aRange
withString: (NSString*)aString
{ {
[self subclassResponsibility: _cmd];// Primitive method! [self subclassResponsibility: _cmd];// Primitive method!
} }