Ignore:
Timestamp:
02/10/08 06:02:25 (16 years ago)
Author:
Nicholas Riley
Message:

ICeCoffEE.[hm]: Restore ICCF_CheckRange, moved in [322], as we don't
want the range limited in TestParser.

ICeCoffEEParser.m: Remove ICCF_CheckRange. Comment out expandFront
URL/parens stuff; it's as yet untested. Handle {...} in URLs. Don't
assert when )/} is last character in string. Fix indentation.

ICeCoffEE.xcodeproj: Link TestParser to Cocoa normally. Remove
obsolete build settings.

TestParser.m: Stub out ICCF_CheckRange. Test beginning with
one-character ranges all the way through the string. Output summary
stats at end.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ICeCoffEE/ICeCoffEE/ICeCoffEEParser.m

    r322 r375  
    99#import "ICeCoffEEParser.h"
    1010#import "ICeCoffEE.h"
    11 
    12 // RFC-ordained max URL length, just to avoid passing IC/LS multi-megabyte documents
    13 #if ICCF_DEBUG
    14 const long ICCF_MAX_URL_LEN = 120; // XXX change later
    15 #else
    16 const long ICCF_MAX_URL_LEN = 1024;
    17 #endif
    18 
    19 void ICCF_CheckRange(NSRange range) {
    20     NSCAssert(range.length > 0, ICCF_LocalizedString(@"No URL is selected"));
    21     NSCAssert1(range.length <= ICCF_MAX_URL_LEN, ICCF_LocalizedString(@"The potential URL is longer than %lu characters"), ICCF_MAX_URL_LEN);
    22 }
    2311
    2412void ICCF_Delimiters(NSCharacterSet **leftPtr, NSCharacterSet **rightPtr) {
     
    136124   
    137125expandFront:
    138         // XXX instead of 0, make this stop at the max URL length to prevent protracted searches
    139        
    140         // XXX here's how this is supposed to work:
    141         // (http://web.sabi.net/) and <http://web.sabi.net/> should work if they are the entire document, even if clicking at the end/beginning of the document, not barfing with "no URL" (correct, as now) or selecting the final >, or ) (what would happen if we remove this "add 1" accommodation).  But how about "http://web.sabi.net/(foo)"?  That should work too, as long as it's not preceded by a (.
    142         // Should probably backport to ICeCoffEETerminal, now I finally understand the method to this madness.
    143         // add 1 to range to trap delimiters that are on the edge of the selection (i.e., <...)
    144         delimiterRange = [s rangeOfCharacterFromSet: urlLeftDelimiters
    145                                             options: NSLiteralSearch | NSBackwardsSearch
    146                                               range: NSMakeRange(0, range.location + (range.location != [s length]))];
     126    // XXX instead of 0, make this stop at the max URL length to prevent protracted searches
     127   
     128    // XXX here's how this is supposed to work:
     129    // (http://web.sabi.net/) and <http://web.sabi.net/> should work if they are the entire document, even if clicking at the end/beginning of the document, not barfing with "no URL" (correct, as now) or selecting the final >, or ) (what would happen if we remove this "add 1" accommodation).  But how about "http://web.sabi.net/(foo)"?  That should work too, as long as it's not preceded by a (.
     130    // Should probably backport to ICeCoffEETerminal, now I finally understand the method to this madness.
     131    // add 1 to range to trap delimiters that are on the edge of the selection (i.e., <...)
     132    delimiterRange = [s rangeOfCharacterFromSet: urlLeftDelimiters
     133                                        options: NSLiteralSearch | NSBackwardsSearch
     134                                          range: NSMakeRange(0, range.location + (range.location != [s length]))];
    147135    if (delimiterRange.location == NSNotFound) {
    148136        // extend to beginning of string
     
    155143       
    156144        // in url/(parens)stuff, handle clicking inside or after (parens).
    157         if ([s characterAtIndex: delimiterRange.location] == '(' &&
    158             range.location > 2 /* prevent wrapping, ordinarily not necessary */) {
     145        /*if ([s characterAtIndex: delimiterRange.location] == '(' &&
     146            range.location > 2) { // prevent wrapping, ordinarily not necessary
    159147            if ([s rangeOfString: @")" options: NSLiteralSearch range: range].location != NSNotFound ||
    160148                [s rangeOfCharacterFromSet: [NSCharacterSet characterSetWithCharactersInString: @"/."]
     
    165153                goto expandFront;
    166154            }
    167         }        
     155        } */       
    168156    }
    169157   
     
    171159   
    172160expandBack:
    173         // XXX instead of length of string, make this stop at the max URL length to prevent protracted searches
    174         // add 1 to range to trap delimiters that are on the edge of the selection (i.e., ...>)
    175         extraLen = [s length] - range.location - range.length;
     161    // XXX instead of length of string, make this stop at the max URL length to prevent protracted searches
     162    // add 1 to range to trap delimiters that are on the edge of the selection (i.e., ...>)
     163    extraLen = [s length] - range.location - range.length;
    176164    delimiterRange = [s rangeOfCharacterFromSet: urlRightDelimiters
    177165                                        options: NSLiteralSearch
     
    185173        range.length += delimiterRange.location - range.location - range.length;
    186174       
    187         // grow URL past closing paren if we've seen an open paren
    188         if ([s characterAtIndex: delimiterRange.location] == ')' &&
    189             [s rangeOfString: @"(" options: NSLiteralSearch range: range].location != NSNotFound) {
     175        // grow URL past closing paren/brace if we've seen an open paren/brace
     176        unichar closing = [s characterAtIndex: delimiterRange.location];
     177        NSString *opening;
     178        if (closing == ')') opening = @"(";
     179        else if (closing == '}') opening = @"{";
     180        else goto checkRange;
     181        if ([s rangeOfString: opening options: NSLiteralSearch range: range].location == NSNotFound)
     182            goto checkRange;
     183       
     184        if (extraLen == 0) {
     185            range.length += 1;
     186            ICLog(@"expanding past %c, now |%@|", closing, [s substringWithRange: range]);
     187        } else {
    190188            range.length += 2;
    191             ICLog(@"expanding past ), now |%@|", [s substringWithRange: range]);
     189            ICLog(@"expanding past %c, now |%@|", closing, [s substringWithRange: range]);
    192190            goto expandBack;
    193191        }
    194192    }
    195193   
     194checkRange:
    196195    ICCF_CheckRange(range);
    197196   
Note: See TracChangeset for help on using the changeset viewer.