Changeset 5180
- Timestamp:
- 01/18/08 06:07:16 (1 year ago)
- Files:
-
- WiredClient/trunk/NSString-WCAdditions.m (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
WiredClient/trunk/NSString-WCAdditions.m
r5041 r5180 33 33 34 34 - (void)filterWiredChat:(WITextFilter *)filter { 35 static NSCharacterSet *whitespaceSet, *non whitespaceSet, *nontimestampSet;35 static NSCharacterSet *whitespaceSet, *nonWhitespaceSet, *nonTimestampSet, *nonHighlightSet; 36 36 NSMutableCharacterSet *characterSet; 37 37 NSEnumerator *enumerator; … … 42 42 NSColor *color, *eventsTextColor, *timestampEveryLineColor; 43 43 NSRange range, nickRange, patternRange; 44 NSUInteger i, style, highlightCount ;44 NSUInteger i, style, highlightCount, length; 45 45 BOOL running = YES; 46 46 47 47 if(!whitespaceSet) { 48 48 whitespaceSet = [[NSCharacterSet whitespaceAndNewlineCharacterSet] retain]; 49 non whitespaceSet = [[whitespaceSet invertedSet] retain];49 nonWhitespaceSet = [[whitespaceSet invertedSet] retain]; 50 50 51 51 characterSet = [[NSMutableCharacterSet decimalDigitCharacterSet] mutableCopy]; 52 52 [characterSet addCharactersInString:@":."]; 53 53 [characterSet invert]; 54 non timestampSet = [characterSet copy];54 nonTimestampSet = [characterSet copy]; 55 55 [characterSet release]; 56 57 nonHighlightSet = [[NSCharacterSet alphanumericCharacterSet] retain]; 56 58 } 57 59 … … 77 79 while(running) { 78 80 // --- extract word 79 [scanner skipUpToCharactersFromSet:non whitespaceSet];81 [scanner skipUpToCharactersFromSet:nonWhitespaceSet]; 80 82 range.location = [scanner scanLocation]; 81 83 … … 89 91 90 92 // --- scan timestamps patterns 91 if([word rangeOfCharacterFromSet:non timestampSet].location == NSNotFound ||93 if([word rangeOfCharacterFromSet:nonTimestampSet].location == NSNotFound || 92 94 [word isEqualToString:@"PM"] || [word isEqualToString:@"AM"]) { 93 95 [self addAttribute:NSForegroundColorAttributeName value:timestampEveryLineColor range:range]; … … 143 145 // --- scan rest of line 144 146 if([scanner scanUpToString:@"\n" intoString:&chat]) { 147 length = [chat length]; 148 145 149 // --- scan chat line for highlight patterns 146 150 for(i = 0; i < highlightCount; i++) { … … 148 152 149 153 if(patternRange.location != NSNotFound) { 150 color = [highlightColors objectAtIndex:i]; 151 152 if(![color isKindOfClass:[NSColor class]]) { 153 color = NSColorFromString([highlightStrings objectAtIndex:i]); 154 [highlightColors replaceObjectAtIndex:i withObject:color]; 154 if(patternRange.location + patternRange.length == length || 155 ![[NSCharacterSet alphanumericCharacterSet] characterIsMember: 156 [chat characterAtIndex:patternRange.location + patternRange.length]]) { 157 color = [highlightColors objectAtIndex:i]; 158 159 if(![color isKindOfClass:[NSColor class]]) { 160 color = NSColorFromString([highlightStrings objectAtIndex:i]); 161 [highlightColors replaceObjectAtIndex:i withObject:color]; 162 } 163 164 [self addAttribute:NSForegroundColorAttributeName value:color range:nickRange]; 165 166 break; 155 167 } 156 157 [self addAttribute:NSForegroundColorAttributeName value:color range:nickRange];158 159 break;160 168 } 161 169 }
