+2007-05-31 Helge Hess <helge.hess@opengroupware.org>
+
+ * FdExt.subproj/NSString+Encoding.m: added gnustep-base and
+ libFoundation implementations for
+ [NSString +stringEncodingForEncodingNamed:] (v4.7.194)
+
2007-05-28 Helge Hess <helge.hess@opengroupware.org>
* NGCalendarDateRange.m: return nil for undefined KVC keys (v4.7.193)
/*
- 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.
# import <Foundation/NSByteOrder.h>
#endif
+#if GNUSTEP_BASE_LIBRARY
+#import <GNUstepBase/GSMime.h>
+#endif
+
// TODO: should move different implementations to different files ...
@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
+ (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