From: helge Date: Thu, 31 May 2007 14:16:50 +0000 (+0000) Subject: exposed stringEncodingForEncodingNamed: X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=81461a1f01ce822d09e3978797f80add64dc981e;p=sope exposed stringEncodingForEncodingNamed: git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1492 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-core/NGExtensions/ChangeLog b/sope-core/NGExtensions/ChangeLog index 5afefe00..5e7f30fc 100644 --- a/sope-core/NGExtensions/ChangeLog +++ b/sope-core/NGExtensions/ChangeLog @@ -1,3 +1,9 @@ +2007-05-31 Helge Hess + + * FdExt.subproj/NSString+Encoding.m: added gnustep-base and + libFoundation implementations for + [NSString +stringEncodingForEncodingNamed:] (v4.7.194) + 2007-05-28 Helge Hess * NGCalendarDateRange.m: return nil for undefined KVC keys (v4.7.193) diff --git a/sope-core/NGExtensions/FdExt.subproj/NSString+Encoding.m b/sope-core/NGExtensions/FdExt.subproj/NSString+Encoding.m index b1812587..af77d2a6 100644 --- a/sope-core/NGExtensions/FdExt.subproj/NSString+Encoding.m +++ b/sope-core/NGExtensions/FdExt.subproj/NSString+Encoding.m @@ -1,5 +1,6 @@ /* - Copyright (C) 2000-2005 SKYRIX Software AG + Copyright (C) 2000-2007 SKYRIX Software AG + Copyright (C) 2007 Helge Hess This file is part of SOPE. @@ -30,6 +31,10 @@ # import #endif +#if GNUSTEP_BASE_LIBRARY +#import +#endif + // TODO: should move different implementations to different files ... @@ -79,6 +84,61 @@ @implementation NSString(Encoding) +#if GNUSTEP_BASE_LIBRARY + ++ (NSStringEncoding)stringEncodingForEncodingNamed:(NSString *)_encoding { + return [GSMimeDocument encodingFromCharset:_encoding]; +} + +#endif + +#if LIB_FOUNDATION_LIBRARY + ++ (NSStringEncoding)stringEncodingForEncodingNamed:(NSString *)_encoding { + NSString *s = [_encoding lowercaseString]; + unsigned len = [s length]; + + if (s == nil) + return 0; + + switch(len) { + case 4: + if ([s isEqualToString:@"utf8"]) + return NSUTF8StringEncoding; + break; + + case 5: + if ([s isEqualToString:@"utf-8"]) + return NSUTF8StringEncoding; + if ([s isEqualToString:@"ascii"]) + return NSASCIIStringEncoding; + break; + + case 6: + if ([s isEqualToString:@"latin1"]) + return NSISOLatin1StringEncoding; + if ([s isEqualToString:@"latin9"]) + return NSISOLatin9StringEncoding; + break; + + case 10: + if ([s isEqualToString:@"iso-8859-1"]) + return NSISOLatin1StringEncoding; + break; + + case 11: + if ([s isEqualToString:@"iso-8859-15"]) + return NSISOLatin9StringEncoding; + break; + } + + NSLog(@"%s: could not derive NSStringEncoding from name: '%@'", _encoding); + return 0; +} + +#endif + + #ifdef __linux__ static NSString *unicharEncoding = @"UCS-2LE"; #else diff --git a/sope-core/NGExtensions/NGExtensions/NSString+Encoding.h b/sope-core/NGExtensions/NGExtensions/NSString+Encoding.h index 8313fdc6..11d88116 100644 --- a/sope-core/NGExtensions/NGExtensions/NSString+Encoding.h +++ b/sope-core/NGExtensions/NGExtensions/NSString+Encoding.h @@ -36,10 +36,7 @@ + (NSString *)stringWithData:(NSData *)_da usingEncodingNamed:(NSString *)_enc; - (NSData *)dataUsingEncodingNamed:(NSString *)_encoding; -// TODO: fix this, do not use a define, implement a selector on all platforms! -#if NeXT_Foundation_LIBRARY || COCOA_Foundation_LIBRARY + (NSStringEncoding)stringEncodingForEncodingNamed:(NSString *)encoding; -#endif @end diff --git a/sope-core/NGExtensions/Version b/sope-core/NGExtensions/Version index 6e00eb25..ae5eadc4 100644 --- a/sope-core/NGExtensions/Version +++ b/sope-core/NGExtensions/Version @@ -1,6 +1,6 @@ # version -SUBMINOR_VERSION:=193 +SUBMINOR_VERSION:=194 # v4.3.115 requires libFoundation v1.0.59 # v4.2.72 requires libEOControl v4.2.39