Changeset 4382

Show
Ignore:
Timestamp:
09/25/06 20:16:54 (2 years ago)
Author:
morris
Message:

Be more stringent about ranges

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Footagehead/trunk/FHRangeHandler.m

    r3400 r4382  
    3131#import "FHRangeHandler.h" 
    3232 
     33@interface FHRangeHandler(Private) 
     34 
     35+ (NSArray *)_getLinksForURL:(WIURL *)url; 
     36 
     37@end 
     38 
     39 
     40@implementation FHRangeHandler(Private) 
     41 
     42+ (NSArray *)_getLinksForURL:(WIURL *)url { 
     43        NSMutableArray  *links; 
     44        NSArray                 *array; 
     45        NSString                *string, *prefix, *suffix, *rangeString; 
     46        NSRange                 prefixRange, suffixRange; 
     47        unsigned int    i, length, start, stop; 
     48         
     49        string = [url humanReadableString]; 
     50        prefixRange = [string rangeOfString:@"["]; 
     51         
     52        if(prefixRange.location == NSNotFound) 
     53                return NULL; 
     54         
     55        prefix = [string substringWithRange:NSMakeRange(0, prefixRange.location)]; 
     56 
     57        suffixRange = [string rangeOfString:@"]"]; 
     58 
     59        if(suffixRange.location == NSNotFound) 
     60                return NULL; 
     61 
     62        suffix = [string substringWithRange:NSMakeRange(suffixRange.location + 1, [string length] - suffixRange.location - 1)]; 
     63         
     64        rangeString = [string substringWithRange:NSMakeRange(prefixRange.location + 1, suffixRange.location - prefixRange.location - 1)]; 
     65        array = [rangeString componentsSeparatedByString:@"-"]; 
     66         
     67        if([array count] != 2) 
     68                return NULL; 
     69         
     70        start = [[array objectAtIndex:0] unsignedIntValue]; 
     71        stop = [[array objectAtIndex:1] unsignedIntValue]; 
     72         
     73        if(start == 0 && stop == 0) 
     74                return NULL; 
     75         
     76        links = [NSMutableArray arrayWithCapacity:stop - start + 1]; 
     77        length = [[array objectAtIndex:0] length]; 
     78 
     79        for(i = start; i <= stop; i++) 
     80                [links addObject:[NSSWF:@"%@%0.*u%@", prefix, length, i, suffix]]; 
     81         
     82        return links; 
     83} 
     84 
     85@end 
     86 
     87 
    3388@implementation FHRangeHandler 
    3489 
    3590+ (BOOL)handlesURL:(WIURL *)url isPrimary:(BOOL)primary { 
    36         NSString                *string; 
    37          
    3891        if(primary && ![url isFileURL]) { 
    39                 string = [url path]; 
    40                  
    41                 if(![[NSImage FHImageFileTypes] containsObject:[string pathExtension]])  
     92                if(![[NSImage FHImageFileTypes] containsObject:[url pathExtension]])  
    4293                        return NO; 
    4394 
    44                 if(([string containsSubstring:@"["] && [string containsSubstring:@"]"]) || 
    45                    ([string containsSubstring:@"%5B"] && [string containsSubstring:@"%5D"])) 
    46                         return YES; 
     95                if(![self _getLinksForURL:url]) 
     96                        return NO; 
     97                 
     98                return YES; 
    4799        } 
    48100                 
     
    55107 
    56108- (id)initHandlerWithURL:(WIURL *)url { 
    57         NSArray                 *array; 
    58         NSString                *string, *preString, *postString, *rangeString; 
    59         NSRange                 preRange, postRange; 
    60         unsigned int    i, length, start, stop; 
    61          
    62109        self = [super initHandlerWithURL:url]; 
    63110         
    64         string = [[self URL] humanReadableString]; 
     111        _links = [[[self class] _getLinksForURL:url] retain]; 
    65112         
    66         preRange = [string rangeOfString:@"["]; 
    67         preString = [string substringWithRange:NSMakeRange(0, preRange.location)]; 
    68          
    69         postRange = [string rangeOfString:@"]"]; 
    70         postString = [string substringWithRange:NSMakeRange(postRange.location + 1, [string length] - postRange.location - 1)]; 
    71  
    72         rangeString = [string substringWithRange:NSMakeRange(preRange.location + 1, postRange.location - preRange.location - 1)]; 
    73          
    74         array = [rangeString componentsSeparatedByString:@"-"]; 
    75          
    76         if([array count] != 2) { 
     113        if(!_links) { 
    77114                [self release]; 
    78  
     115                 
    79116                return NULL; 
    80117        } 
    81          
    82         start = [[array objectAtIndex:0] unsignedIntValue]; 
    83         stop = [[array objectAtIndex:1] unsignedIntValue]; 
    84          
    85         if(start == 0 && stop == 0) { 
    86                 [self release]; 
    87  
    88                 return NULL; 
    89         } 
    90          
    91         _links = [[NSMutableArray alloc] initWithCapacity:stop - start + 1]; 
    92         length = [(NSString *) [array objectAtIndex:0] length]; 
    93  
    94         for(i = start; i <= stop; i++) 
    95                 [_links addObject:[NSSWF:@"%@%0.*u%@", preString, length, i, postString]]; 
    96118         
    97119        return self; 
  • Footagehead/trunk/Footagehead.xcodeproj/project.pbxproj

    r4263 r4382  
    998998                                }, 
    999999                        ); 
     1000                        projectRoot = ""; 
    10001001                        targets = ( 
    10011002                                8D1107260486CEB800E47090 /* Footagehead */,