Attributed string bugfix

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@13018 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2002-03-06 09:44:48 +00:00
parent d5afdf3009
commit 1c66398a64
2 changed files with 64 additions and 13 deletions

View file

@ -1,3 +1,10 @@
2002-03-06 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSAttributedString.m: Applied fix for left-over attributes
at end of string. Patch supplied by Alexander Malmberg
<alexander@malmberg.org>. Reformatting to conform to GNUstep
standards, and optimisation by me.
2002-03-04 Richard Frith-Macdonald <rfm@gnu.org> 2002-03-04 Richard Frith-Macdonald <rfm@gnu.org>
* Tools/autogsdoc.m: Output gsdoc as UTF8 as we should. * Tools/autogsdoc.m: Output gsdoc as UTF8 as we should.

View file

@ -57,6 +57,8 @@
#define SANITY_CHECKS 0 #define SANITY_CHECKS 0
static NSDictionary *blank;
@interface GSAttributedString : NSAttributedString @interface GSAttributedString : NSAttributedString
{ {
NSString *_textChars; NSString *_textChars;
@ -268,6 +270,7 @@ static void _setup()
if (infCls == 0) if (infCls == 0)
{ {
NSMutableArray *a; NSMutableArray *a;
NSDictionary *d;
GSIMapInitWithZoneAndCapacity(&attrMap, NSDefaultMallocZone(), 32); GSIMapInitWithZoneAndCapacity(&attrMap, NSDefaultMallocZone(), 32);
@ -289,6 +292,9 @@ static void _setup()
oatImp = [a methodForSelector: oatSel]; oatImp = [a methodForSelector: oatSel];
remImp = (void (*)())[a methodForSelector: remSel]; remImp = (void (*)())[a methodForSelector: remSel];
RELEASE(a); RELEASE(a);
d = [NSDictionary new];
blank = cacheAttributes(d);
RELEASE(d);
} }
} }
@ -311,7 +317,7 @@ _setAttributesFrom(
if (aRange.length == 0) if (aRange.length == 0)
{ {
attr = [NSDictionary dictionary]; attr = blank;
} }
else else
{ {
@ -469,7 +475,7 @@ _attributesAtIndexEffectiveRange(
if (attributes == nil) if (attributes == nil)
{ {
attributes = [NSDictionary dictionary]; attributes = blank;
} }
attributes = cacheAttributes(attributes); attributes = cacheAttributes(attributes);
info = NEWINFO(z, attributes, 0); info = NEWINFO(z, attributes, 0);
@ -533,7 +539,7 @@ _attributesAtIndexEffectiveRange(
{ {
info = OBJECTAT(i); info = OBJECTAT(i);
NSAssert(info->loc > l, NSInternalInconsistencyException); NSAssert(info->loc > l, NSInternalInconsistencyException);
NSAssert(info->loc <= len, NSInternalInconsistencyException); NSAssert(info->loc < len, NSInternalInconsistencyException);
l = info->loc; l = info->loc;
} }
} }
@ -565,7 +571,7 @@ _attributesAtIndexEffectiveRange(
if (attributes == nil) if (attributes == nil)
{ {
attributes = [NSDictionary dictionary]; attributes = blank;
} }
attributes = cacheAttributes(attributes); attributes = cacheAttributes(attributes);
info = NEWINFO(z, attributes, 0); info = NEWINFO(z, attributes, 0);
@ -625,7 +631,7 @@ SANITY();
} }
if (attributes == nil) if (attributes == nil)
{ {
attributes = [NSDictionary dictionary]; attributes = blank;
} }
attributes = cacheAttributes(attributes); attributes = cacheAttributes(attributes);
SANITY(); SANITY();
@ -783,6 +789,8 @@ SANITY();
attrs = _attributesAtIndexEffectiveRange(start, &effectiveRange, attrs = _attributesAtIndexEffectiveRange(start, &effectiveRange,
tmpLength, _infoArray, &arrayIndex); tmpLength, _infoArray, &arrayIndex);
moveLocations = [aString length] - range.length;
arrayIndex++; arrayIndex++;
if (NSMaxRange(effectiveRange) < NSMaxRange(range)) if (NSMaxRange(effectiveRange) < NSMaxRange(range))
{ {
@ -811,10 +819,32 @@ SANITY();
} }
} }
} }
info->loc = NSMaxRange(range); if (NSMaxRange(range) < [_textChars length])
{
info->loc = NSMaxRange(range);
}
else
{
if (arrayIndex != 0)
{
REMOVEAT(arrayIndex);
arraySize--;
}
else
{
NSDictionary *d = blank;
unCacheAttributes(info->attrs);
DESTROY(info->attrs);
d = cacheAttributes(d);
info->attrs = d;
/* set location so it will be correct after being modified
below */
info->loc = NSMaxRange(range);
}
}
} }
moveLocations = [aString length] - range.length;
/* /*
* If we are replacing a range with a zero length string and the * If we are replacing a range with a zero length string and the
* range we are using matches the range replaced, then we must * range we are using matches the range replaced, then we must
@ -827,12 +857,26 @@ SANITY();
arrayIndex++; arrayIndex++;
if (effectiveRange.location == range.location if (effectiveRange.location == range.location
&& effectiveRange.length == range.length) && effectiveRange.length == range.length)
{ {
arrayIndex--; arrayIndex--;
REMOVEAT(arrayIndex); if (arrayIndex!=0)
arraySize--; {
} REMOVEAT(arrayIndex);
arraySize--;
}
else
{
NSDictionary *d = blank;
info = OBJECTAT(0);
unCacheAttributes(info->attrs);
DESTROY(info->attrs);
d = cacheAttributes(d);
info->attrs = d;
info->loc = NSMaxRange(range);
}
}
} }
/* /*