r = [_attr rangeOfCharacterFromSet:equalSignCharSet];
if (r.length > 0) {
+ unsigned left, right;
+
attrName = [[_attr substringToIndex:r.location] uppercaseString];
- attrValue = [_attr substringFromIndex:(r.location + 1)];
+ left = NSMaxRange(r);
+ right = [_attr length] - 1;
+ if(left != right) {
+ if(([_attr characterAtIndex:left] == '"') &&
+ ([_attr characterAtIndex:right] == '"'))
+ {
+ left += 1;
+ r = NSMakeRange(left, right - left);
+ attrValue = [_attr substringWithRange:r];
+ }
+ else {
+ attrValue = [_attr substringFromIndex:left];
+ }
+ }
+ else {
+ attrValue = @"";
+ }
}
else {
attrName = @"TYPE";
r = [_line rangeOfCharacterFromSet:colonAndSemicolonCharSet
options:0
range:todoRange];
+ /* is line well-formed? */
if(r.length == 0) {
if(debugOn) {
NSLog(@"%s got an improper content line! ->\n%@",
tagName = [[_line substringToIndex:r.location] uppercaseString];
tagAttributes = [[NSMutableArray alloc] init];
+ /* possible shortcut: if we spotted a ':', we don't have to do "expensive"
+ argument scanning/processing.
+ */
if([_line characterAtIndex:r.location] != ':') {
BOOL isAtEnd = NO, isInDquote = NO;
unsigned start = NSMaxRange(r);
r = [_line rangeOfCharacterFromSet:colonSemicolonAndDquoteCharSet
options:0
range:todoRange];
- /* is line well-formed ? */
+ /* is line well-formed? */
if(r.length == 0 || r.location == 0) {
if(debugOn) {
NSLog(@"%s got an improper content line! ->\n%@",
[self->cardStack addObject:tag];
}
else if ([tagName isEqualToString:@"END"]) {
- [self _endTag:[self _mapTagName:tagValue]];
+ NSString *mtName;
+
+ mtName = [self _mapTagName:tagValue];
+ if([self->cardStack count] > 0) {
+ NSString *expectedName;
+
+ expectedName = [[self->cardStack lastObject] objectAtIndex:1];
+ if(![expectedName isEqualToString:mtName]) {
+ if(debugOn) {
+ NSLog(@"%s found end tag '%@' which doesn't match expected name "
+ @"'%@'! Tag '%@' hasn't been closed properly. Given iCal "
+ @"document contains errors!",
+ __PRETTY_FUNCTION__,
+ mtName,
+ expectedName,
+ expectedName);
+ }
+ /* probably futile attempt to parse anyways */
+ if(debugOn) {
+ NSLog(@"%s trying to fix previous error by inserting bogus end "
+ @"tag.",
+ __PRETTY_FUNCTION__);
+ }
+ [self _endTag:expectedName];
+ [self->cardStack removeLastObject];
+ }
+ }
+ else {
+ if(debugOn) {
+ NSLog(@"%s found end tag '%@' without any open tags left?!",
+ __PRETTY_FUNCTION__,
+ mtName);
+ }
+ }
+ [self _endTag:mtName];
[self->cardStack removeLastObject];
if ([self->cardStack count] == 0)
[self _eventsForElements];
[self _parseLine:line];
}
+ if([self->cardStack count] != 0) {
+ if(debugOn) {
+ NSLog(@"%s found elements on cardStack. This indicates an improper "
+ @"iCal structure! Not all required events will have been "
+ @"generated, leading to unpredictable results!",
+ __PRETTY_FUNCTION__);
+ }
+ }
+
[line release];
[self->contentHandler endPrefixMapping:@""];
[self->contentHandler endDocument];