X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=sope-core%2FNGExtensions%2FFdExt.subproj%2FNSString%2Bmisc.m;h=f7a6ffa7c08b66818108692de139a62042fef00f;hb=2afe19d91f4d52c499e4772bd2f5f8290874c649;hp=190de2d10302ea022b5a8a2e501ccf19f3405b16;hpb=13317e77452e2da1fdd8a7675b63fc12316a92e9;p=sope diff --git a/sope-core/NGExtensions/FdExt.subproj/NSString+misc.m b/sope-core/NGExtensions/FdExt.subproj/NSString+misc.m index 190de2d1..f7a6ffa7 100644 --- a/sope-core/NGExtensions/FdExt.subproj/NSString+misc.m +++ b/sope-core/NGExtensions/FdExt.subproj/NSString+misc.m @@ -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" @@ -33,20 +33,11 @@ - (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 @@ -212,7 +203,7 @@ if (r.length > 0) { return ([self length] > r.location) ? [self substringFromIndex:(r.location + r.length)] - : @""; + : (NSString *)@""; } return nil; } @@ -272,7 +263,10 @@ } 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; @@ -290,6 +284,53 @@ @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) {