Changeset 5180

Show
Ignore:
Timestamp:
01/18/08 06:07:16 (1 year ago)
Author:
morris
Message:

Don't highlight in substrings, only in words

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • WiredClient/trunk/NSString-WCAdditions.m

    r5041 r5180  
    3333 
    3434- (void)filterWiredChat:(WITextFilter *)filter { 
    35         static NSCharacterSet           *whitespaceSet, *nonwhitespaceSet, *nontimestampSet; 
     35        static NSCharacterSet           *whitespaceSet, *nonWhitespaceSet, *nonTimestampSet, *nonHighlightSet; 
    3636        NSMutableCharacterSet           *characterSet; 
    3737        NSEnumerator                            *enumerator; 
     
    4242        NSColor                                         *color, *eventsTextColor, *timestampEveryLineColor; 
    4343        NSRange                                         range, nickRange, patternRange; 
    44         NSUInteger                                      i, style, highlightCount
     44        NSUInteger                                      i, style, highlightCount, length
    4545        BOOL                                            running = YES; 
    4646 
    4747        if(!whitespaceSet) { 
    4848                whitespaceSet           = [[NSCharacterSet whitespaceAndNewlineCharacterSet] retain]; 
    49                 nonwhitespaceSet      = [[whitespaceSet invertedSet] retain]; 
     49                nonWhitespaceSet      = [[whitespaceSet invertedSet] retain]; 
    5050                 
    5151                characterSet            = [[NSMutableCharacterSet decimalDigitCharacterSet] mutableCopy]; 
    5252                [characterSet addCharactersInString:@":."]; 
    5353                [characterSet invert]; 
    54                 nontimestampSet               = [characterSet copy]; 
     54                nonTimestampSet               = [characterSet copy]; 
    5555                [characterSet release]; 
     56                 
     57                nonHighlightSet         = [[NSCharacterSet alphanumericCharacterSet] retain]; 
    5658        } 
    5759 
     
    7779        while(running) { 
    7880                // --- extract word 
    79                 [scanner skipUpToCharactersFromSet:nonwhitespaceSet]; 
     81                [scanner skipUpToCharactersFromSet:nonWhitespaceSet]; 
    8082                range.location = [scanner scanLocation]; 
    8183                 
     
    8991                 
    9092                // --- scan timestamps patterns 
    91                 if([word rangeOfCharacterFromSet:nontimestampSet].location == NSNotFound || 
     93                if([word rangeOfCharacterFromSet:nonTimestampSet].location == NSNotFound || 
    9294                   [word isEqualToString:@"PM"] || [word isEqualToString:@"AM"]) { 
    9395                        [self addAttribute:NSForegroundColorAttributeName value:timestampEveryLineColor range:range]; 
     
    143145                // --- scan rest of line 
    144146                if([scanner scanUpToString:@"\n" intoString:&chat]) { 
     147                        length = [chat length]; 
     148                         
    145149                        // --- scan chat line for highlight patterns 
    146150                        for(i = 0; i < highlightCount; i++) { 
     
    148152                                 
    149153                                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; 
    155167                                        } 
    156                                          
    157                                         [self addAttribute:NSForegroundColorAttributeName value:color range:nickRange]; 
    158                                          
    159                                         break; 
    160168                                } 
    161169                        }