From: helge Date: Sat, 9 Feb 2008 20:03:34 +0000 (+0000) Subject: rewrote a few things to use unicode methods X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b963fea57efd5a37311ae24093b54caad1f6befd;p=sope rewrote a few things to use unicode methods git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1602 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-core/NGExtensions/ChangeLog b/sope-core/NGExtensions/ChangeLog index 5160bd4b..f23c72ce 100644 --- a/sope-core/NGExtensions/ChangeLog +++ b/sope-core/NGExtensions/ChangeLog @@ -1,3 +1,21 @@ +2008-02-09 Helge Hess + + * v4.7.197 + + * FdExt.subproj/NSString+misc.m: rewrote -bindingVariables and + stringByReplacingVariablesWithBindings:stringForUnknownBindings: + to use unichar (needs testing, might be buggy) + + * NGQuotedPrintableCoding.m: rewritten to use -dataUsingEncoding: + methods instead of working on -cString buffers (Note: encoding + selection is dubious) + + * FdExt.subproj/NSString+Escaping.m: rewrote -stringByApplyingCEscaping + to work on unichars + + * added EOExt.subproj/EOGlobalID+Ext.m category to streamline KVC on + non-lF environments + 2007-12-03 Helge Hess * NGExtensions/NSString+Formatting.h: replaced usage of deprecated diff --git a/sope-core/NGExtensions/EOExt.subproj/EOGlobalID+Ext.m b/sope-core/NGExtensions/EOExt.subproj/EOGlobalID+Ext.m new file mode 100644 index 00000000..1b94c754 --- /dev/null +++ b/sope-core/NGExtensions/EOExt.subproj/EOGlobalID+Ext.m @@ -0,0 +1,36 @@ +/* + Copyright (C) 2008 Helge Hess + + This file is part of SOPE. + + 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. + + 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 SOPE; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ + +#import + +@implementation EOGlobalID(SOPEExt) + +#if !LIB_FOUNDATION_LIBRARY + +- (id)valueForUndefinedKey:(NSString *)_key { + NSLog(@"WARNING: tried to access undefined KVC key '%@' on GID object: %@", + _key, self); + return nil; +} + +#endif + +@end /* EOGlobalID(SOPEExt) */ diff --git a/sope-core/NGExtensions/EOExt.subproj/GNUmakefile b/sope-core/NGExtensions/EOExt.subproj/GNUmakefile index 1e6ad7e6..170d1e08 100644 --- a/sope-core/NGExtensions/EOExt.subproj/GNUmakefile +++ b/sope-core/NGExtensions/EOExt.subproj/GNUmakefile @@ -23,6 +23,7 @@ EOExt_OBJC_FILES = \ EOSortOrdering+plist.m \ EOTrueQualifier.m \ NSArray+EOGrouping.m \ + EOGlobalID+Ext.m \ ADDITIONAL_INCLUDE_DIRS += -I. -I.. -I../NGExtensions/ \ -I../FdExt.subproj/ \ diff --git a/sope-core/NGExtensions/FdExt.subproj/NSString+Escaping.m b/sope-core/NGExtensions/FdExt.subproj/NSString+Escaping.m index f73def38..e31957e4 100644 --- a/sope-core/NGExtensions/FdExt.subproj/NSString+Escaping.m +++ b/sope-core/NGExtensions/FdExt.subproj/NSString+Escaping.m @@ -1,5 +1,6 @@ /* - Copyright (C) 2000-2005 SKYRIX Software AG + Copyright (C) 2000-2008 SKYRIX Software AG + Copyright (C) 2008 Helge Hess This file is part of SOPE. @@ -26,15 +27,22 @@ - (NSString *)stringByApplyingCEscaping { // Unicode! - const char *cstr; - char *buffer; - register int pos = 0; + unichar *src; + unichar *buffer; + int pos = 0; + NSString *s; - cstr = [self cString]; - buffer = malloc([self cStringLength] * 2 + 1); + if ((pos = [self length]) == 0) + return @""; + + src = malloc(sizeof(unichar) * (pos + 2)); + [self getCharacters:src]; + src[pos] = 0; // zero-terminate + + buffer = malloc(sizeof(unichar) * ((pos * 2) + 1)); - while (*cstr) { - switch (*cstr) { + for (pos = 0; *src != 0; pos++, src++) { + switch (*src) { case '\n': buffer[pos] = '\\'; pos++; buffer[pos] = 'n'; @@ -49,25 +57,16 @@ break; default: - buffer[pos] = *cstr; + buffer[pos] = *src; break; } - cstr++; - pos++; } buffer[pos] = '\0'; -#if NeXT_Foundation_LIBRARY || GNUSTEP_BASE_LIBRARY - { - NSString *s; - - s = buffer ? [NSString stringWithCString:buffer] : nil; - if (buffer) free(buffer); - return s; - } -#else - return [NSString stringWithCStringNoCopy:buffer freeWhenDone:YES]; -#endif + s = [NSString stringWithCharacters:buffer length:pos]; + free(buffer); buffer = NULL; + free(src); src = NULL; + return s; } - (NSString *)stringByEscapingCharactersFromSet:(NSCharacterSet *)_escSet diff --git a/sope-core/NGExtensions/FdExt.subproj/NSString+Ext.m b/sope-core/NGExtensions/FdExt.subproj/NSString+Ext.m index fdf9f5d3..e6b59563 100644 --- a/sope-core/NGExtensions/FdExt.subproj/NSString+Ext.m +++ b/sope-core/NGExtensions/FdExt.subproj/NSString+Ext.m @@ -220,6 +220,7 @@ @end /* NSString(lfNSURLUtilities) */ + #if !LIB_FOUNDATION_LIBRARY @implementation NSString(KVCCompatibility) diff --git a/sope-core/NGExtensions/FdExt.subproj/NSString+misc.m b/sope-core/NGExtensions/FdExt.subproj/NSString+misc.m index f7a6ffa7..4093b284 100644 --- a/sope-core/NGExtensions/FdExt.subproj/NSString+misc.m +++ b/sope-core/NGExtensions/FdExt.subproj/NSString+misc.m @@ -1,6 +1,6 @@ /* - Copyright (C) 2000-2006 SKYRIX Software AG - Copyright (C) 2006 Helge Hess + Copyright (C) 2000-2008 SKYRIX Software AG + Copyright (C) 2006-2008 Helge Hess This file is part of SOPE. @@ -43,30 +43,31 @@ - (NSSet *)bindingVariables { unsigned len, pos = 0; - const char *buf = NULL; + unichar *wbuf = NULL; NSMutableSet *result = nil; - - result = [NSMutableSet set]; - len = [self cStringLength]; - buf = [self cString]; + + result = [NSMutableSet setWithCapacity:16]; + len = [self length]; + wbuf = malloc(sizeof(unichar) * (len + 4)); + [self getCharacters:wbuf]; while (pos < len) { unsigned startPos; if (pos + 1 == len) { /* last entry */ - if (buf[pos] == '$') { /* found $ without end-char */ + if (wbuf[pos] == '$') { /* found $ without end-char */ [[[NSStringVariableBindingException alloc] initWithFormat:@"did not find end of variable for string %@", self] raise]; } break; } - if (buf[pos] != '$') { + if (wbuf[pos] != '$') { pos++; continue; } - if (buf[pos + 1] == '$') { /* found $$ --> ignore*/ + if (wbuf[pos + 1] == '$') { /* found $$ --> ignore*/ pos += 2; continue; } @@ -75,31 +76,31 @@ startPos = pos; - pos += 2; /* buf[pos + 1] != '$' */ + pos += 2; /* wbuf[pos + 1] != '$' */ while (pos < len) { - if (buf[pos] != '$') + if (wbuf[pos] != '$') pos++; else break; } if (pos == len) { /* end of string was reached */ [[[NSStringVariableBindingException alloc] - initWithFormat:@"didn`t find end of " - @"variable for string %@", self] - raise]; + initWithFormat:@"did not find end of variable for string %@", self] + raise]; } else { - NSString *key = nil; - + NSString *key = nil; + key = [[NSString alloc] - initWithCStringNoCopy:(char*)buf + startPos + 1 - length:pos - startPos - 1 - freeWhenDone:NO]; + initWithCharacters:(unichar *)wbuf + startPos + 1 + length:(pos - startPos - 1)]; [result addObject:key]; [key release]; } pos++; } + if (wbuf != NULL) { free(wbuf); wbuf = NULL; } + return [[result copy] autorelease]; } @@ -107,34 +108,38 @@ stringForUnknownBindings:(NSString *)_unknown { unsigned len, pos = 0; - const char *buf = NULL; + unichar *wbuf = NULL; NSMutableString *str = nil; str = [self mutableCopy]; - len = [str cStringLength]; - buf = [str cString]; + len = [str length]; + wbuf = malloc(sizeof(unichar) * (len + 4)); + [self getCharacters:wbuf]; while (pos < len) { if (pos + 1 == len) { /* last entry */ - if (buf[pos] == '$') { /* found $ without end-char */ + if (wbuf[pos] == '$') { /* found $ without end-char */ [[[NSStringVariableBindingException alloc] initWithFormat:@"did not find end of variable for string %@", self] raise]; } break; } - if (buf[pos] == '$') { - if (buf[pos + 1] == '$') { /* found $$ --> $ */ + if (wbuf[pos] == '$') { + if (wbuf[pos + 1] == '$') { /* found $$ --> $ */ [str deleteCharactersInRange:NSMakeRange(pos, 1)]; - buf = [str cString]; - len = [str cStringLength]; + + if (wbuf != NULL) { free(wbuf); wbuf = NULL; } + len = [str length]; + wbuf = malloc(sizeof(unichar) * (len + 4)); + [str getCharacters:wbuf]; } else { unsigned startPos = pos; - pos += 2; /* buf[pos + 1] != '$' */ + pos += 2; /* wbuf[pos + 1] != '$' */ while (pos < len) { - if (buf[pos] != '$') + if (wbuf[pos] != '$') pos++; else break; @@ -149,9 +154,8 @@ NSString *value; key = [[NSString alloc] - initWithCStringNoCopy:(char*)buf + startPos + 1 - length:pos - startPos - 1 - freeWhenDone:NO]; + initWithCharacters:(wbuf + startPos + 1) + length:(pos - startPos - 1)]; if ((value = [_bindings valueForStringBinding:key]) == nil) { if (_unknown == nil) { @@ -164,17 +168,23 @@ value = _unknown; } [key release]; key = nil; + [str replaceCharactersInRange: NSMakeRange(startPos, pos - startPos + 1) withString:value]; - buf = [str cString]; - len = [str cStringLength]; + + if (wbuf != NULL) { free(wbuf); wbuf = NULL; } + len = [str length]; + wbuf = malloc(sizeof(unichar) * (len + 4)); + [str getCharacters:wbuf]; + pos = startPos - 1 + [value length]; } } } pos++; } + if (wbuf != NULL) { free(wbuf); wbuf = NULL; } { id tmp = str; str = [str copy]; diff --git a/sope-core/NGExtensions/NGQuotedPrintableCoding.m b/sope-core/NGExtensions/NGQuotedPrintableCoding.m index d1c2efb7..b169c8da 100644 --- a/sope-core/NGExtensions/NGQuotedPrintableCoding.m +++ b/sope-core/NGExtensions/NGQuotedPrintableCoding.m @@ -1,6 +1,6 @@ /* - Copyright (C) 2000-2006 SKYRIX Software AG - Copyright (C) 2006 Helge Hess + Copyright (C) 2000-2008 SKYRIX Software AG + Copyright (C) 2006-2008 Helge Hess This file is part of SOPE. @@ -28,43 +28,32 @@ @implementation NSString(QuotedPrintableCoding) - (NSString *)stringByDecodingQuotedPrintable { - NSData *data; - unsigned len; + NSData *data; - if ((len = [self cStringLength]) > 0) { - void *buf; - buf = malloc(len + 10); - [self getCString:buf]; - data = [NSData dataWithBytes:buf length:len]; - if (buf != NULL) free(buf); - } - else - data = [NSData data]; + data = ([self length] > 0) + ? [self dataUsingEncoding:NSASCIIStringEncoding] + : [NSData data]; data = [data dataByDecodingQuotedPrintable]; - + // TODO: should we default to some specific charset instead? (either // Latin1 or UTF-8 + // or the charset of the receiver? return [NSString stringWithCString:[data bytes] length:[data length]]; } - (NSString *)stringByEncodingQuotedPrintable { NSData *data; - unsigned len; - if ((len = [self cStringLength])) { - void *buf; - buf = malloc(len + 10); - [self getCString:buf]; - data = [NSData dataWithBytes:buf length:len]; - free(buf); - } - else - data = [NSData data]; + // TBD: which encoding to use? + data = ([self length] > 0) + ? [self dataUsingEncoding:[NSString defaultCStringEncoding]] + : [NSData data]; data = [data dataByEncodingQuotedPrintable]; - return [NSString stringWithCString:[data bytes] length:[data length]]; + return [[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding] + autorelease]; } @end /* NSString(QuotedPrintableCoding) */ diff --git a/sope-core/NGExtensions/Version b/sope-core/NGExtensions/Version index 0b7786b9..03c62acb 100644 --- a/sope-core/NGExtensions/Version +++ b/sope-core/NGExtensions/Version @@ -1,6 +1,6 @@ # version -SUBMINOR_VERSION:=196 +SUBMINOR_VERSION:=197 # v4.3.115 requires libFoundation v1.0.59 # v4.2.72 requires libEOControl v4.2.39