]> err.no Git - sope/commitdiff
rewrote _parseLine:
authorznek <znek@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Sat, 16 Oct 2004 22:04:19 +0000 (22:04 +0000)
committerznek <znek@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Sat, 16 Oct 2004 22:04:19 +0000 (22:04 +0000)
git-svn-id: http://svn.opengroupware.org/SOPE/trunk@268 e4a50df8-12e2-0310-a44c-efbce7f8a7e3

sope-ical/versitSaxDriver/ChangeLog
sope-ical/versitSaxDriver/VSSaxDriver.m
sope-ical/versitSaxDriver/Version

index a0657680a0c7911ec55fd6f39c823ec325ef52ca..8b1b091045019f2e286fdc1134068e6c3ed43316 100644 (file)
@@ -1,5 +1,12 @@
 2004-10-16  Marcus Mueller  <znek@mulle-kybernetik.com>
 
+       * 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'
index db359f995376f0d6ae5afa899c120210f3d9a065..252cb75de743ffa96571b021ecc1a7c502b1eb93 100644 (file)
@@ -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;
     
index 14e384e2ca48efdb17069d383b62aa0944f03335..5af8f0ced9b15cc96bd2f3b3de4719f147b6a3b8 100644 (file)
@@ -2,4 +2,4 @@
 
 MAJOR_VERSION=1
 MINOR_VERSION=0
-SUBMINOR_VERSION:=4
+SUBMINOR_VERSION:=5