]> err.no Git - scalable-opengroupware.org/commitdiff
refactoring
authorznek <znek@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Thu, 14 Oct 2004 20:13:58 +0000 (20:13 +0000)
committerznek <znek@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Thu, 14 Oct 2004 20:13:58 +0000 (20:13 +0000)
git-svn-id: http://svn.opengroupware.org/SOGo/trunk@398 d1b88da0-ebda-0310-925b-ed51d893ca5b

SOGoLogic/ChangeLog
SOGoLogic/NSString+iCal.m
SOGoLogic/Version

index 815fa5be9193c4c9b83c6ed1e9d11e484aee1e35..bbb5df28fa7cb35011b8f3f3d47939b61b27b509 100644 (file)
@@ -1,5 +1,8 @@
 2004-10-14  Marcus Mueller  <znek@mulle-kybernetik.com>
 
+       * NSString+iCal.[hm]: uses new category from NGExtensions to do the
+         escaping (v0.9.18)
+
        * NSString+iCal.[hm]: new (private) method to strip off any unsafe
          characters from strings and bugfix for escaping (v0.9.17)
 
index 42fe41a7e5ab8395fb8d8f6a82a126e1584d30c0..c902b110e7615802af248a0a994e31507c8f2fd4 100644 (file)
 - (NSString *)iCalCleanString;
 @end
 
+#include "common.h"
+
+@interface SOGoICalStringEscaper : NSObject <NGStringEscaping>
+{
+}
++ (id)sharedEscaper;
+@end
+
+@implementation SOGoICalStringEscaper
++ (id)sharedEscaper {
+  static id sharedInstance = nil;
+  if(!sharedInstance) {
+    sharedInstance = [[self alloc] init];
+  }
+  return sharedInstance;
+}
+
+- (NSString *)stringByEscapingString:(NSString *)_s {
+  unichar c;
+
+  if(!_s || [_s length] == 0)
+    return nil;
+
+  c = [_s characterAtIndex:0];
+  if(c == '\n') {
+    return @"\\n";
+  }
+  else if(c == '\r') {
+    return nil; /* effectively remove char */
+  }
+  return [NSString stringWithFormat:@"\\%@", _s];
+}
+
+@end
+
 @implementation NSString (SOGoiCal)
 
 #if 0
 /* strip off any characters from string which are not allowed in iCal */
 - (NSString *)iCalCleanString {
   static NSCharacterSet *replaceSet = nil;
-  NSRange r, er;
-  NSMutableString *safeString;
-  BOOL needsReplacing;
-  unsigned length;
 
   if(replaceSet == nil) {
     replaceSet = [NSCharacterSet characterSetWithCharactersInString:@"\r"];
     [replaceSet retain];
   }
   
-  length = [self length];
-  r = NSMakeRange(0, length);
-  er = [self rangeOfCharacterFromSet:replaceSet options:0 range:r];
-  needsReplacing = er.length > 0 ? YES : NO;
-  if(!needsReplacing) {
-    return self; /* cheap */
-  }
-
-  safeString = [NSMutableString stringWithCapacity:length];
-  if(needsReplacing) {
-    NSRange todoRange;
-    /*
-     r         == previous range, upto er.location
-     er        == escape range
-     todoRange == what we still need to scan
-     */
-    length = r.length;
-    do {
-      r.length = er.location - r.location;
-      if(r.length > 0)
-        [safeString appendString:[self substringWithRange:r]];
-      r.location          = NSMaxRange(er);
-      todoRange.location  = r.location;
-      todoRange.length    = length - r.location;
-      er = [self rangeOfCharacterFromSet:replaceSet
-                 options:0
-                 range:todoRange];
-    }
-    while(er.length > 0);
-    if(todoRange.length > 0) {
-      [safeString appendString:[self substringWithRange:todoRange]];
-    }
-  }
-  return safeString;
+  return [self stringByEscapingCharactersFromSet:replaceSet
+               usingStringEscaping:[SOGoICalStringEscaper sharedEscaper]];
 }
 
 - (NSString *)iCalDQUOTESafeString {
 
 /* Escape unsafe characters */
 - (NSString *)iCalEscapedStringWithEscapeSet:(NSCharacterSet *)_es {
-  NSString *cleanString;
-  NSMutableString *safeString;
-  NSRange r, er;
-  BOOL needsEscaping;
-  unsigned length;
-  
-  cleanString = [self iCalCleanString];
-  length = [cleanString length];
-  r = NSMakeRange(0, length);
-  er = [cleanString rangeOfCharacterFromSet:_es options:0 range:r];
-  needsEscaping = er.length > 0 ? YES : NO;
-  if(!needsEscaping) {
-    return cleanString; /* cheap */
-  }
-  /* wild guess */
-  safeString = [NSMutableString stringWithCapacity:length + 10];
-  if(needsEscaping) {
-    NSRange todoRange;
-    /*
-     r         == previous range, upto er.location
-     er        == escape range
-     todoRange == what we still need to scan
-     */
-    length = r.length;
-    do {
-      NSString *s;
-      
-      r.length = er.location - r.location;
-      if(r.length > 0) {
-        s = [cleanString substringWithRange:r];
-        [safeString appendString:s];
-      }
-      [safeString appendString:@"\\"];
-      if([cleanString characterAtIndex:er.location] == '\n') {
-        s = @"n";
-      }
-      else {
-        s = [cleanString substringWithRange:er];
-      }
-      [safeString appendString:s];
-      r.location          = NSMaxRange(er);
-      todoRange.location  = r.location;
-      todoRange.length    = length - r.location;
-      er = [cleanString rangeOfCharacterFromSet:_es
-                        options:0
-                        range:todoRange];
-    }
-    while(er.length > 0);
-    if(todoRange.length > 0) {
-      [safeString appendString:[cleanString substringWithRange:todoRange]];
-    }
-  }
-  return safeString;
+  NSString *s;
+
+  s = [self iCalCleanString];
+  return [s stringByEscapingCharactersFromSet:_es
+            usingStringEscaping:[SOGoICalStringEscaper sharedEscaper]];
 }
 
 @end
index f120816ac0c54bf7773ee75b3b476c8d184dfcc3..d8b4b1b104b6d3ef3e0916c2e14bb341c33ee39e 100644 (file)
@@ -1,5 +1,6 @@
 # $Id$
 
-SUBMINOR_VERSION:=17
+SUBMINOR_VERSION:=18
 
+# v0.9.18 requires NGExtensions  v4.3.123
 # v0.9.13 requires libFoundation v1.0.62