2 // AINulRemovalPlugin.m
5 // Created by Evan Schoenberg on 9/10/06.
8 #import "AINulRemovalPlugin.h"
9 #import <Adium/AIContentControllerProtocol.h>
10 #import <AIUtilities/AIAttributedStringAdditions.h>
12 @implementation AINulRemovalPlugin
16 //Register us as a filter
17 [[adium contentController] registerContentFilter:self ofType:AIFilterContent direction:AIFilterIncoming];
18 [[adium contentController] registerContentFilter:self ofType:AIFilterContent direction:AIFilterOutgoing];
21 - (void)uninstallPlugin
23 [[adium contentController] unregisterContentFilter:self];
26 - (NSAttributedString *)filterAttributedString:(NSAttributedString *)inAttributedString context:(id)context
28 if (!inAttributedString || ![inAttributedString length]) return inAttributedString;
30 //Don't allow embedded NULs
31 static NSString *nulString = nil;
35 nulString = (NSString *)CFStringCreateWithBytes(kCFAllocatorDefault, bytes, 1, kCFStringEncodingASCII, false);
38 NSAttributedString *nulFreeAttributedString;
40 if ([[inAttributedString string] rangeOfString:nulString options:NSLiteralSearch].location != NSNotFound) {
41 NSMutableAttributedString *temporaryString = [inAttributedString mutableCopy];
42 [temporaryString replaceOccurrencesOfString:nulString
44 options:NSLiteralSearch
45 range:NSMakeRange(0, [temporaryString length])];
46 nulFreeAttributedString = [temporaryString autorelease];
49 nulFreeAttributedString = inAttributedString;
52 return nulFreeAttributedString;
56 * @brief When should this filter run?
58 * Run this filter as early as possible to remove NULs in case other filters want to use the UTF8String of the filtered string.
60 - (float)filterPriority
62 return HIGHEST_FILTER_PRIORITY;