]> err.no Git - sope/commitdiff
added a method to mail-quote a string
authorhelge <helge@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Wed, 9 Feb 2005 11:16:48 +0000 (11:16 +0000)
committerhelge <helge@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Wed, 9 Feb 2005 11:16:48 +0000 (11:16 +0000)
git-svn-id: http://svn.opengroupware.org/SOPE/trunk@544 e4a50df8-12e2-0310-a44c-efbce7f8a7e3

sope-core/NGExtensions/ChangeLog
sope-core/NGExtensions/FdExt.subproj/NSString+misc.m
sope-core/NGExtensions/NGExtensions/NSString+misc.h
sope-core/NGExtensions/Version

index 3db55f0456d206266968168367c099b89dcca811..3b6e4ab514cf441ab34c27027b8280673c013509 100644 (file)
@@ -1,3 +1,9 @@
+2005-02-08  Helge Hess  <helge.hess@opengroupware.org>
+
+       * FdExt.subproj/NSString+misc.m: added new method
+         -stringByApplyingMailQuoting for placing "> " in front of each line
+         contained in the string (v4.5.142)
+
 2005-01-09  Helge Hess  <helge.hess@opengroupware.org>
 
        * NGExtensions/AutoDefines.h, common.h: fixed defines on MacOSX (fixes
index 602a8944839333ec9f276fe3a392c6dbbc764307..ebb30279b9d7e3b6c4b8bf06234b145c53182572 100644 (file)
 
 @end /* NSString(NGScanning) */
 
+
+@implementation NSString(MailQuoting)
+
+- (NSString *)stringByApplyingMailQuoting {
+  NSString *s;
+  unsigned i, len, nl;
+  unichar  *sourceBuf, *targetBuf;
+  
+  if ((len = [self length]) == 0)
+    return @"";
+  
+  sourceBuf = malloc((len + 4) * sizeof(unichar));
+  [self getCharacters:sourceBuf];
+  
+  for (nl = 0, i = 0; i < len; i++) {
+    if (sourceBuf[i] == '\n') 
+      nl++;
+  }
+  
+  if (nl == 0) {
+    if (sourceBuf) free(sourceBuf);
+    return [@"> " stringByAppendingString:self];
+  }
+  
+  targetBuf = malloc((len + 8 + (nl * 3)) * sizeof(unichar));
+  targetBuf[0] = '>';
+  targetBuf[1] = ' ';
+  nl = 2;
+  
+  for (i = 0; i < len; i++) {
+    targetBuf[nl] = sourceBuf[i];
+    nl++;
+    
+    if (sourceBuf[i] == '\n') {
+      targetBuf[nl] = '>'; nl++;
+      targetBuf[nl] = ' '; nl++;
+    }
+  }
+  
+  s = [[NSString alloc] initWithCharacters:targetBuf length:nl];
+  if (targetBuf) free(targetBuf);
+  if (sourceBuf) free(sourceBuf);
+  return [s autorelease];
+}
+
+@end /* NSString(MailQuoting) */
+
 // linking
 
 void __link_NSString_misc(void) {
index 1e710ba5e78845101e31bbde37ac9c2c85ff3942..689fb51f8426d00ac166b2d08e1390ff2eb4c555 100644 (file)
 
 @end
 
+@interface NSString(MailQuoting)
+
+- (NSString *)stringByApplyingMailQuoting;
+
+@end
+
 #endif /* __NGExtensions_NSString_misc_H__ */
index 6be8e2eddea21b67e142d490bc099ff0346228df..639e30fcfd4f9abd5944293813a309271a5e8093 100644 (file)
@@ -1,6 +1,6 @@
 # version
 
-SUBMINOR_VERSION:=141
+SUBMINOR_VERSION:=142
 
 # v4.3.115 requires libFoundation v1.0.59
 # v4.2.72  requires libEOControl  v4.2.39