From: znek Date: Sat, 16 Oct 2004 22:04:19 +0000 (+0000) Subject: rewrote _parseLine: X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e7f7bb53507133a1159b4bfcfcc17df75d15f735;p=sope rewrote _parseLine: git-svn-id: http://svn.opengroupware.org/SOPE/trunk@268 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-ical/versitSaxDriver/ChangeLog b/sope-ical/versitSaxDriver/ChangeLog index a0657680..8b1b0910 100644 --- a/sope-ical/versitSaxDriver/ChangeLog +++ b/sope-ical/versitSaxDriver/ChangeLog @@ -1,5 +1,12 @@ 2004-10-16 Marcus Mueller + * v1.0.5 + + * VSSaxDriver.m: rewrote _parseLine: to properly parse content lines + according to RFC2445. + + * README: updated + * v1.0.4 * VSStringFormatter.m: properly unescape '\N' diff --git a/sope-ical/versitSaxDriver/VSSaxDriver.m b/sope-ical/versitSaxDriver/VSSaxDriver.m index db359f99..252cb75d 100644 --- a/sope-ical/versitSaxDriver/VSSaxDriver.m +++ b/sope-ical/versitSaxDriver/VSSaxDriver.m @@ -34,6 +34,7 @@ static NSCharacterSet *dotCharSet = nil; static NSCharacterSet *equalSignCharSet = nil; static NSCharacterSet *commaCharSet = nil; static NSCharacterSet *colonAndSemicolonCharSet = nil; +static NSCharacterSet *colonSemicolonAndDquoteCharSet = nil; static NSCharacterSet *whitespaceCharSet = nil; static VSStringFormatter *stringFormatter = nil; @@ -57,6 +58,8 @@ static VSStringFormatter *stringFormatter = nil; [[NSCharacterSet characterSetWithCharactersInString:@","] retain]; colonAndSemicolonCharSet = [[NSCharacterSet characterSetWithCharactersInString:@":;"] retain]; + colonSemicolonAndDquoteCharSet = + [[NSCharacterSet characterSetWithCharactersInString:@":;\""] retain]; whitespaceCharSet = [[NSCharacterSet whitespaceCharacterSet] retain]; @@ -407,29 +410,66 @@ static VSStringFormatter *stringFormatter = nil; } - (void)_parseLine:(NSString *)_line { - NSScanner *scanner; - NSString *tagName, *tagAttribute, *tagValue; + NSString *tagName, *tagValue; NSMutableArray *tagAttributes; + NSRange r, todoRange; + unsigned length; - scanner = [NSScanner scannerWithString:_line]; + length = [_line length]; tagAttributes = [[NSMutableArray alloc] init]; - - tagName = @""; - [scanner scanUpToCharactersFromSet:colonAndSemicolonCharSet - intoString:&tagName]; - - while ([scanner scanString:@";" intoString:NULL]) { - [scanner scanUpToCharactersFromSet:colonAndSemicolonCharSet - intoString:&tagAttribute]; - [tagAttributes addObject:tagAttribute]; + todoRange = NSMakeRange(0, length); + r = [_line rangeOfCharacterFromSet:colonAndSemicolonCharSet + options:0 + range:todoRange]; + tagName = [[_line substringToIndex:r.location] uppercaseString]; + if([_line characterAtIndex:r.location] != ':') { + BOOL isAtEnd = NO, isInDquote = NO; + unsigned start = NSMaxRange(r); + + todoRange = NSMakeRange(start, length - start); + while(!isAtEnd) { + BOOL skip = YES; + + /* scan for parameters */ + r = [_line rangeOfCharacterFromSet:colonSemicolonAndDquoteCharSet + options:0 + range:todoRange]; + /* first check if delimiter candidate is escaped */ + if([_line characterAtIndex:(r.location - 1)] != '\\') { + unichar delimiter; + NSRange copyRange; + + delimiter = [_line characterAtIndex:r.location]; + if(delimiter == '\"') { + /* not a real delimiter - toggle isInDquote for proper escaping */ + isInDquote = !isInDquote; + } + else { + if(!isInDquote) { + /* is a delimiter, which one? */ + skip = NO; + if(delimiter == ':') { + isAtEnd = YES; + } + copyRange = NSMakeRange(start, r.location - start); + [tagAttributes addObject:[_line substringWithRange:copyRange]]; + if(!isAtEnd) { + /* adjust start, todoRange */ + start = NSMaxRange(r); + todoRange = NSMakeRange(start, length - start); + } + } + } + } + if(skip) { + /* adjust todoRange */ + unsigned offset = NSMaxRange(r); + todoRange = NSMakeRange(offset, length - offset); + } + } } - [scanner scanString:@":" intoString:NULL]; - tagValue = [_line substringFromIndex:[scanner scanLocation]]; - - //NSLog (@"%@ %@ %@",tagName,tagAttributes, tagValue); - - tagName = [tagName uppercaseString]; - + tagValue = [_line substringFromIndex:NSMaxRange(r)]; + if ([tagName isEqualToString:@"BEGIN"]) { id tag; diff --git a/sope-ical/versitSaxDriver/Version b/sope-ical/versitSaxDriver/Version index 14e384e2..5af8f0ce 100644 --- a/sope-ical/versitSaxDriver/Version +++ b/sope-ical/versitSaxDriver/Version @@ -2,4 +2,4 @@ MAJOR_VERSION=1 MINOR_VERSION=0 -SUBMINOR_VERSION:=4 +SUBMINOR_VERSION:=5