mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +00:00
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:
parent
433d24fdb6
commit
2086baecd1
2 changed files with 200 additions and 175 deletions
|
@ -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>
|
||||
|
||||
* config.guess: Better guess of NetBSD systems.
|
||||
|
|
|
@ -138,8 +138,8 @@ static Class NSMutableAttributedString_concrete_class;
|
|||
//NSCopying protocol
|
||||
- (id) copyWithZone: (NSZone*)zone
|
||||
{
|
||||
if ([self isKindOfClass: [NSMutableAttributedString class]] ||
|
||||
NSShouldRetainWithZone(self, zone) == NO)
|
||||
if ([self isKindOfClass: [NSMutableAttributedString class]]
|
||||
|| NSShouldRetainWithZone(self, zone) == NO)
|
||||
return [[[[self class] _concreteClass] allocWithZone: zone]
|
||||
initWithAttributedString: self];
|
||||
else
|
||||
|
@ -182,7 +182,7 @@ static Class NSMutableAttributedString_concrete_class;
|
|||
return [[self string] length];
|
||||
}
|
||||
|
||||
- (NSString *) string
|
||||
- (NSString*) string
|
||||
{
|
||||
[self subclassResponsibility: _cmd];/* Primitive method! */
|
||||
return nil;
|
||||
|
@ -212,7 +212,7 @@ static Class NSMutableAttributedString_concrete_class;
|
|||
if (!aRange)
|
||||
return attrDictionary;
|
||||
|
||||
while(aRange->location > rangeLimit.location)
|
||||
while (aRange->location > rangeLimit.location)
|
||||
{
|
||||
//Check extend range backwards
|
||||
tmpDictionary =
|
||||
|
@ -220,8 +220,10 @@ static Class NSMutableAttributedString_concrete_class;
|
|||
effectiveRange: &tmpRange];
|
||||
if ([tmpDictionary isEqualToDictionary: attrDictionary])
|
||||
aRange->location = tmpRange.location;
|
||||
else
|
||||
break;
|
||||
}
|
||||
while(NSMaxRange(*aRange) < NSMaxRange(rangeLimit))
|
||||
while (NSMaxRange(*aRange) < NSMaxRange(rangeLimit))
|
||||
{
|
||||
//Check extend range forwards
|
||||
tmpDictionary =
|
||||
|
@ -229,6 +231,8 @@ static Class NSMutableAttributedString_concrete_class;
|
|||
effectiveRange: &tmpRange];
|
||||
if ([tmpDictionary isEqualToDictionary: attrDictionary])
|
||||
aRange->length = NSMaxRange(tmpRange) - aRange->location;
|
||||
else
|
||||
break;
|
||||
}
|
||||
*aRange = NSIntersectionRange(*aRange,rangeLimit);//Clip to rangeLimit
|
||||
return attrDictionary;
|
||||
|
@ -257,7 +261,8 @@ static Class NSMutableAttributedString_concrete_class;
|
|||
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;
|
||||
id attrValue,tmpAttrValue;
|
||||
|
@ -277,7 +282,7 @@ static Class NSMutableAttributedString_concrete_class;
|
|||
if (!aRange)
|
||||
return attrValue;
|
||||
|
||||
while(aRange->location > rangeLimit.location)
|
||||
while (aRange->location > rangeLimit.location)
|
||||
{
|
||||
//Check extend range backwards
|
||||
tmpDictionary =
|
||||
|
@ -286,8 +291,10 @@ static Class NSMutableAttributedString_concrete_class;
|
|||
tmpAttrValue = [tmpDictionary objectForKey: attributeName];
|
||||
if (tmpAttrValue == attrValue)
|
||||
aRange->location = tmpRange.location;
|
||||
else
|
||||
break;
|
||||
}
|
||||
while(NSMaxRange(*aRange) < NSMaxRange(rangeLimit))
|
||||
while (NSMaxRange(*aRange) < NSMaxRange(rangeLimit))
|
||||
{
|
||||
//Check extend range forwards
|
||||
tmpDictionary =
|
||||
|
@ -296,13 +303,15 @@ static Class NSMutableAttributedString_concrete_class;
|
|||
tmpAttrValue = [tmpDictionary objectForKey: attributeName];
|
||||
if (tmpAttrValue == attrValue)
|
||||
aRange->length = NSMaxRange(tmpRange) - aRange->location;
|
||||
else
|
||||
break;
|
||||
}
|
||||
*aRange = NSIntersectionRange(*aRange,rangeLimit);//Clip to rangeLimit
|
||||
return attrValue;
|
||||
}
|
||||
|
||||
//Comparing attributed strings
|
||||
- (BOOL) isEqualToAttributedString: (NSAttributedString *)otherString
|
||||
- (BOOL) isEqualToAttributedString: (NSAttributedString*)otherString
|
||||
{
|
||||
NSRange ownEffectiveRange,otherEffectiveRange;
|
||||
unsigned int length;
|
||||
|
@ -324,10 +333,10 @@ static Class NSMutableAttributedString_concrete_class;
|
|||
effectiveRange: &otherEffectiveRange];
|
||||
result = YES;
|
||||
|
||||
while(YES)
|
||||
while (YES)
|
||||
{
|
||||
if (NSIntersectionRange(ownEffectiveRange,otherEffectiveRange).length > 0 &&
|
||||
![ownDictionary isEqualToDictionary: otherDictionary])
|
||||
if (NSIntersectionRange(ownEffectiveRange, otherEffectiveRange).length > 0
|
||||
&& ![ownDictionary isEqualToDictionary: otherDictionary])
|
||||
{
|
||||
result = NO;
|
||||
break;
|
||||
|
@ -361,7 +370,7 @@ static Class NSMutableAttributedString_concrete_class;
|
|||
|
||||
|
||||
//Extracting a substring
|
||||
- (NSAttributedString *) attributedSubstringFromRange: (NSRange)aRange
|
||||
- (NSAttributedString*) attributedSubstringFromRange: (NSRange)aRange
|
||||
{
|
||||
NSAttributedString *newAttrString;
|
||||
NSString *newSubstring;
|
||||
|
@ -418,7 +427,7 @@ static Class NSMutableAttributedString_concrete_class;
|
|||
}
|
||||
|
||||
//Retrieving character information
|
||||
- (NSMutableString *) mutableString
|
||||
- (NSMutableString*) mutableString
|
||||
{
|
||||
return [GSMutableAttributedStringTracker stringWithOwner: self];
|
||||
}
|
||||
|
@ -430,12 +439,12 @@ static Class NSMutableAttributedString_concrete_class;
|
|||
}
|
||||
|
||||
//Changing attributes
|
||||
- (void) setAttributes: (NSDictionary *)attributes range: (NSRange)aRange
|
||||
- (void) setAttributes: (NSDictionary*)attributes range: (NSRange)aRange
|
||||
{
|
||||
[self subclassResponsibility: _cmd];// Primitive method!
|
||||
}
|
||||
|
||||
- (void) addAttribute: (NSString *)name value: (id)value range: (NSRange)aRange
|
||||
- (void) addAttribute: (NSString*)name value: (id)value range: (NSRange)aRange
|
||||
{
|
||||
NSRange effectiveRange;
|
||||
NSDictionary *attrDict;
|
||||
|
@ -448,9 +457,9 @@ static Class NSMutableAttributedString_concrete_class;
|
|||
attrDict = [self attributesAtIndex: aRange.location
|
||||
effectiveRange: &effectiveRange];
|
||||
|
||||
while(effectiveRange.location < NSMaxRange(aRange))
|
||||
while (effectiveRange.location < NSMaxRange(aRange))
|
||||
{
|
||||
effectiveRange = NSIntersectionRange(aRange,effectiveRange);
|
||||
effectiveRange = NSIntersectionRange(aRange, effectiveRange);
|
||||
|
||||
newDict = [[NSMutableDictionary alloc] initWithDictionary: attrDict];
|
||||
IF_NO_GC(AUTORELEASE(newDict));
|
||||
|
@ -458,7 +467,9 @@ static Class NSMutableAttributedString_concrete_class;
|
|||
[self setAttributes: newDict range: effectiveRange];
|
||||
|
||||
if (NSMaxRange(effectiveRange) >= NSMaxRange(aRange))
|
||||
{
|
||||
effectiveRange.location = NSMaxRange(aRange);//This stops the loop...
|
||||
}
|
||||
else if (NSMaxRange(effectiveRange) < tmpLength)
|
||||
{
|
||||
attrDict = [self attributesAtIndex: NSMaxRange(effectiveRange)
|
||||
|
@ -467,7 +478,7 @@ static Class NSMutableAttributedString_concrete_class;
|
|||
}
|
||||
}
|
||||
|
||||
- (void) addAttributes: (NSDictionary *)attributes range: (NSRange)aRange
|
||||
- (void) addAttributes: (NSDictionary*)attributes range: (NSRange)aRange
|
||||
{
|
||||
NSRange effectiveRange;
|
||||
NSDictionary *attrDict;
|
||||
|
@ -476,21 +487,22 @@ static Class NSMutableAttributedString_concrete_class;
|
|||
|
||||
if (!attributes)
|
||||
{
|
||||
//I cannot use NSParameterAssert here, if is has to be an 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];
|
||||
if (aRange.location <= 0 || NSMaxRange(aRange) > tmpLength)
|
||||
{
|
||||
[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
|
||||
effectiveRange: &effectiveRange];
|
||||
|
||||
while(effectiveRange.location < NSMaxRange(aRange))
|
||||
while (effectiveRange.location < NSMaxRange(aRange))
|
||||
{
|
||||
effectiveRange = NSIntersectionRange(aRange,effectiveRange);
|
||||
|
||||
|
@ -500,7 +512,9 @@ static Class NSMutableAttributedString_concrete_class;
|
|||
[self setAttributes: newDict range: effectiveRange];
|
||||
|
||||
if (NSMaxRange(effectiveRange) >= NSMaxRange(aRange))
|
||||
{
|
||||
effectiveRange.location = NSMaxRange(aRange);//This stops the loop...
|
||||
}
|
||||
else if (NSMaxRange(effectiveRange) < tmpLength)
|
||||
{
|
||||
attrDict = [self attributesAtIndex: NSMaxRange(effectiveRange)
|
||||
|
@ -509,7 +523,7 @@ static Class NSMutableAttributedString_concrete_class;
|
|||
}
|
||||
}
|
||||
|
||||
- (void) removeAttribute: (NSString *)name range: (NSRange)aRange
|
||||
- (void) removeAttribute: (NSString*)name range: (NSRange)aRange
|
||||
{
|
||||
NSRange effectiveRange;
|
||||
NSDictionary *attrDict;
|
||||
|
@ -522,7 +536,7 @@ static Class NSMutableAttributedString_concrete_class;
|
|||
attrDict = [self attributesAtIndex: aRange.location
|
||||
effectiveRange: &effectiveRange];
|
||||
|
||||
while(effectiveRange.location < NSMaxRange(aRange))
|
||||
while (effectiveRange.location < NSMaxRange(aRange))
|
||||
{
|
||||
effectiveRange = NSIntersectionRange(aRange,effectiveRange);
|
||||
|
||||
|
@ -532,7 +546,9 @@ static Class NSMutableAttributedString_concrete_class;
|
|||
[self setAttributes: newDict range: effectiveRange];
|
||||
|
||||
if (NSMaxRange(effectiveRange) >= NSMaxRange(aRange))
|
||||
{
|
||||
effectiveRange.location = NSMaxRange(aRange);//This stops the loop...
|
||||
}
|
||||
else if (NSMaxRange(effectiveRange) < tmpLength)
|
||||
{
|
||||
attrDict = [self attributesAtIndex: NSMaxRange(effectiveRange)
|
||||
|
@ -542,31 +558,34 @@ static Class NSMutableAttributedString_concrete_class;
|
|||
}
|
||||
|
||||
//Changing characters and attributes
|
||||
- (void) appendAttributedString: (NSAttributedString *)attributedString
|
||||
- (void) appendAttributedString: (NSAttributedString*)attributedString
|
||||
{
|
||||
[self replaceCharactersInRange: NSMakeRange([self length],0)
|
||||
withAttributedString: attributedString];
|
||||
}
|
||||
|
||||
- (void) insertAttributedString: (NSAttributedString *)attributedString atIndex: (unsigned int)index
|
||||
- (void) insertAttributedString: (NSAttributedString*)attributedString
|
||||
atIndex: (unsigned int)index
|
||||
{
|
||||
[self replaceCharactersInRange: NSMakeRange(index,0)
|
||||
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;
|
||||
NSString *tmpStr;
|
||||
|
||||
tmpStr = [attributedString string];
|
||||
[self replaceCharactersInRange: aRange
|
||||
withString: tmpStr];
|
||||
[self replaceCharactersInRange: aRange withString: tmpStr];
|
||||
|
||||
effectiveRange = NSMakeRange(0,0);
|
||||
clipRange = NSMakeRange(0,[tmpStr length]);
|
||||
while(NSMaxRange(effectiveRange) < NSMaxRange(clipRange))
|
||||
while (NSMaxRange(effectiveRange) < NSMaxRange(clipRange))
|
||||
{
|
||||
attrDict = [attributedString attributesAtIndex: effectiveRange.location
|
||||
effectiveRange: &effectiveRange];
|
||||
|
@ -576,12 +595,13 @@ static Class NSMutableAttributedString_concrete_class;
|
|||
}
|
||||
}
|
||||
|
||||
- (void) replaceCharactersInRange: (NSRange)aRange withString: (NSString *)aString
|
||||
- (void) replaceCharactersInRange: (NSRange)aRange
|
||||
withString: (NSString*)aString
|
||||
{
|
||||
[self subclassResponsibility: _cmd];// Primitive method!
|
||||
}
|
||||
|
||||
- (void) setAttributedString: (NSAttributedString *)attributedString
|
||||
- (void) setAttributedString: (NSAttributedString*)attributedString
|
||||
{
|
||||
[self replaceCharactersInRange: NSMakeRange(0,[self length])
|
||||
withAttributedString: attributedString];
|
||||
|
@ -647,7 +667,7 @@ static Class NSMutableAttributedString_concrete_class;
|
|||
return [[_owner string] getCharacters: buffer range: aRange];
|
||||
}
|
||||
|
||||
- (const char *) cString
|
||||
- (const char*) cString
|
||||
{
|
||||
return [[_owner string] cString];
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue