Inverted CPCharacterSet characterSetWithCharactersInString now archive properly.

This commit is contained in:
Alexander Ljungberg
2011-08-12 19:27:02 -04:00
parent 0789f49b94
commit 6f6bfc667b
2 changed files with 34 additions and 4 deletions
+24 -4
View File
@@ -174,6 +174,27 @@ var _builtInCharacterSets = {};
@end
var CPCharacterSetInvertedKey = @"CPCharacterSetInvertedKey";
@implementation CPCharacterSet (CPCoding)
- (id)initWithCoder:(CPCoder)aCoder
{
if (self = [super init])
{
_inverted = [aCoder decodeBoolForKey:CPCharacterSetInvertedKey];
}
return self;
}
- (void)encodeWithCoder:(CPCoder)aCoder
{
[aCoder encodeBool:_inverted forKey:CPCharacterSetInvertedKey];
}
@end
// A character set that stores a list of ranges of
// acceptable characters.
@implementation _CPRangeCharacterSet : CPCharacterSet
@@ -369,9 +390,7 @@ var _CPStringContentCharacterSetStringKey = @"_CPStringContentCharacterSetString
- (id)initWithCoder:(CPCoder)aCoder
{
// TODO Replace with self = [super initWithCoder:] when super supports it, to get
// "inverted" flag.
if (self)
if (self = [super initWithCoder:aCoder])
{
_string = [aCoder decodeObjectForKey:_CPStringContentCharacterSetStringKey]
}
@@ -381,7 +400,8 @@ var _CPStringContentCharacterSetStringKey = @"_CPStringContentCharacterSetString
- (void)encodeWithCoder:(CPCoder)aCoder
{
// TODO When supported, call super encodeWithCoder:.
[super encodeWithCoder:aCoder];
[aCoder encodeObject:_string forKey:_CPStringContentCharacterSetStringKey];
}
+10
View File
@@ -24,6 +24,16 @@
[self assertTrue:[unarchived characterIsMember:'b']];
[self assertTrue:[unarchived characterIsMember:'c']];
[self assertFalse:[unarchived characterIsMember:'d']];
var invertedSet = [charSet invertedSet];
archived = [CPKeyedArchiver archivedDataWithRootObject:invertedSet];
unarchived = [CPKeyedUnarchiver unarchiveObjectWithData:archived];
[self assertFalse:[unarchived characterIsMember:'a'] message:"in unarchived inverted set 'a' is not a member"];
[self assertFalse:[unarchived characterIsMember:'b'] message:"in unarchived inverted set 'b' is not a member"];
[self assertFalse:[unarchived characterIsMember:'c'] message:"in unarchived inverted set 'c' is not a member"];
[self assertTrue:[unarchived characterIsMember:'d'] message:"in unarchived inverted set 'd' is a member"];
}
@end