Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Source/CFAttributedString.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,7 @@ ReplaceAttributesAtIndex (CFMutableAttributedStringRef str, CFIndex idx,
CFDictionaryRef repl)
{
CFAttributedStringUncacheAttribute (str->_attribs[idx].attrib);
str->_attribs[idx].attrib =
CFAttributedStringCacheAttribute (str->_attribs[idx].attrib);
str->_attribs[idx].attrib = CFAttributedStringCacheAttribute (repl);
}

static void
Expand Down
46 changes: 46 additions & 0 deletions Tests/CFAttributedString/set_clear.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "CoreFoundation/CFAttributedString.h"
#include "CoreFoundation/CFString.h"
#include "CoreFoundation/CFDictionary.h"

#include "../CFTesting.h"

static CFDictionaryRef
oneAttr (CFStringRef k, CFStringRef v)
{
const void *kk = k;
const void *vv = v;
return CFDictionaryCreate (NULL, &kk, &vv, 1,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
}

int
main (void)
{
CFRange er;
CFDictionaryRef d;
CFDictionaryRef repl;
CFTypeRef v;
CFMutableAttributedStringRef m;

m = CFAttributedStringCreateMutable (NULL, 0);
CFAttributedStringReplaceString (m, CFRangeMake (0, 0), CFSTR ("abc"));
CFAttributedStringSetAttribute (m, CFRangeMake (0, 3), CFSTR ("x"),
CFSTR ("1"));

repl = oneAttr (CFSTR ("y"), CFSTR ("2"));
CFAttributedStringSetAttributes (m, CFRangeMake (0, 3), repl, true);

d = CFAttributedStringGetAttributes (m, 1, &er);
PASS_CF(CFDictionaryGetValue (d, CFSTR ("x")) == NULL,
"Clearing other attributes removes the old attribute.");
v = CFDictionaryGetValue (d, CFSTR ("y"));
PASS_CF(v != NULL && CFEqual (v, CFSTR ("2")),
"Clearing other attributes sets the new attribute.");
PASS_CF(CFDictionaryGetCount (d) == 1, "Only the new attribute remains.");

CFRelease (repl);
CFRelease (m);

return 0;
}
Loading