]> err.no Git - sope/blobdiff - sope-core/NGExtensions/FdExt.subproj/NSString+misc.m
fixed a gstep-base issue
[sope] / sope-core / NGExtensions / FdExt.subproj / NSString+misc.m
index 190de2d10302ea022b5a8a2e501ccf19f3405b16..f7a6ffa7c08b66818108692de139a62042fef00f 100644 (file)
@@ -1,24 +1,24 @@
 /*
-  Copyright (C) 2000-2004 SKYRIX Software AG
+  Copyright (C) 2000-2006 SKYRIX Software AG
+  Copyright (C) 2006      Helge Hess
 
-  This file is part of OpenGroupware.org.
+  This file is part of SOPE.
 
-  OGo is free software; you can redistribute it and/or modify it under
+  SOPE is free software; you can redistribute it and/or modify it under
   the terms of the GNU Lesser General Public License as published by the
   Free Software Foundation; either version 2, or (at your option) any
   later version.
 
-  OGo is distributed in the hope that it will be useful, but WITHOUT ANY
+  SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
   WARRANTY; without even the implied warranty of MERCHANTABILITY or
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
   License for more details.
 
   You should have received a copy of the GNU Lesser General Public
-  License along with OGo; see the file COPYING.  If not, write to the
+  License along with SOPE; see the file COPYING.  If not, write to the
   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
   02111-1307, USA.
 */
-// $Id$
 
 #include "NSString+misc.h"
 #include "common.h"
 
 - (NSString *)valueForStringBinding:(NSString *)_key {
   if (_key == nil) return nil;
-  return [[self valueForKey:_key] stringValue];
+  return [[self valueForKeyPath:_key] stringValue];
 }
 
 @end /* NSObject(StringBindings) */
 
-@implementation NSDictionary(StringBindings)
-
-- (NSString *)valueForStringBinding:(NSString *)_key {
-  if (_key == nil) return nil;
-  return [[self objectForKey:_key] stringValue];
-}
-
-@end /* NSDictionary(StringBindings) */
-
 @implementation NSString(misc)
 
 - (NSSet *)bindingVariables
   if (r.length > 0) {
     return ([self length] > r.location)
       ? [self substringFromIndex:(r.location + r.length)]
-      : @"";
+      : (NSString *)@"";
   }
   return nil;
 }
     }
     else if ([quotes characterIsMember:c]) {
       /* skip quotes */
-      for (i++; i < len && ![quotes characterIsMember:c]; i++) {
+      i++;
+      c = [self characterAtIndex:i];
+      for (; i < len && ![quotes characterIsMember:c]; i++) {
+       c = [self characterAtIndex:i];
         if (c == _escape) {
           i++; /* skip next char (eg \') */
           continue;
 
 @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' && (i + 1 != len)) {
+      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) {