Permalink
Browse files

Mega confusion with NS/CF text encodings. Fixed. (Fixes #32)

  • Loading branch information...
1 parent 76b5689 commit 7406a3ad03bb98c6a312f04e9872746f65868fdb Matt Wright committed Apr 8, 2009
@@ -779,7 +779,7 @@ - (void)channelModeChanged:(CHANNEL_REC *)rec setBy:(char *)setter
//-------------------------------------------------------------------
- (void)printText:(char *)text forground:(int)fg background:(int)bg flags:(int)flags
{
- CFStringEncoding enc = [[MITextEncoding irssiEncoding] encoding];
+ CFStringEncoding enc = [[MITextEncoding irssiEncoding] CFStringEncoding];
NSString *decodedString = (NSString *)CFStringCreateWithCStringNoCopy(NULL, text, enc, kCFAllocatorNull);
line = [line attributedStringByAppendingString:decodedString foreground:fg background:bg flags:flags attributes:textAttributes];
[decodedString release];
@@ -1480,7 +1480,7 @@ - (NSAttributedString *)parseTopic:(char *)str
[topicAttributes release];
#endif
- CFStringEncoding enc = [[MITextEncoding irssiEncoding] encoding];
+ CFStringEncoding enc = CFStringConvertNSStringEncodingToEncoding([[MITextEncoding irssiEncoding] encoding]);
NSMutableAttributedString *attributedTopic = [[NSMutableAttributedString alloc] initWithString:[IrssiBridge stringWithIrssiCStringNoCopy:strip_codes(str) encoding:enc] attributes:topicAttributes];
[attributedTopic detectURLs:[NSColor blueColor]];
@@ -262,7 +262,7 @@ - (void)initTextEncodingPopUpButton
*/
- (void)updateTextEncodingPopUpButton
{
- CFStringEncoding textEncoding = [[MITextEncoding irssiEncoding] encoding];
+ NSStringEncoding textEncoding = [[MITextEncoding irssiEncoding] encoding];
[textEncodingPopUpButton selectItemWithTag:textEncoding];
[textEncodingPopUpButton setNeedsDisplay:YES];
}
@@ -24,6 +24,7 @@
#import "servers.h"
#import "signals.h"
#import "IrssiBridge.h"
+#import "TextEncodings.h"
char *word_complete(WINDOW_REC *window, const char *line, int *pos, int erase);
@@ -159,7 +160,7 @@ - (bool)handleSpecialKey:(unichar)uchar withModifierFlags:(unsigned int)flags
if (!new_s)
return TRUE;
- NSString *decodedString = [[NSString alloc] initWithData:[NSData dataWithBytesNoCopy:new_s length:strlen(new_s) freeWhenDone:FALSE] encoding:NSISOLatin1StringEncoding];
+ NSString *decodedString = [[IrssiBridge stringWithIrssiCString:new_s] retain];
[(NSTextView *)[self firstResponder] setString:decodedString];
[decodedString release];
@@ -30,7 +30,7 @@
@class ChannelController;
@interface IrssiBridge : NSObject {}
-+ (char *)irssiCStringWithString:(NSString *)string encoding:(CFStringEncoding)encoding;
++ (char *)irssiCStringWithString:(NSString *)string encoding:(NSStringEncoding)encoding;
+ (char *)irssiCStringWithString:(NSString *)string;
+ (NSString *)stringWithIrssiCString:(char *)string;
+ (NSString *)stringWithIrssiCStringNoCopy:(char *)string;
@@ -8,6 +8,7 @@
#import "IrssiBridge.h"
#import "AppController.h"
#import "ChannelController.h"
+#import "TextEncodings.h"
//#define G_LOG_DOMAIN "MacIrssi"
#define printf(...)
@@ -26,9 +27,9 @@ @implementation IrssiBridge
// Returns: A C-string representation of the string, which the sender
// is responsible to release.
//-------------------------------------------------------------------
-+ (char *)irssiCStringWithString:(NSString *)string encoding:(CFStringEncoding)encoding
++ (char *)irssiCStringWithString:(NSString *)string encoding:(NSStringEncoding)encoding
{
- NSData *data = [string dataUsingEncoding:CFStringConvertEncodingToNSStringEncoding(encoding) allowLossyConversion:TRUE];
+ NSData *data = [string dataUsingEncoding:encoding allowLossyConversion:NO];
int length = [data length];
char *str = malloc(length + 1);
@@ -43,7 +44,7 @@ + (char *)irssiCStringWithString:(NSString *)string encoding:(CFStringEncoding)e
/* Wrapper TODO: this should never be used (fix callers of this method) */
+ (char *)irssiCStringWithString:(NSString *)string
{
- return [self irssiCStringWithString:string encoding:kCFStringEncodingISOLatin1];
+ return [self irssiCStringWithString:string encoding:[[MITextEncoding irssiEncoding] encoding]];
}
//-------------------------------------------------------------------
@@ -59,7 +60,7 @@ + (NSString *)stringWithIrssiCString:(char *)string
if (!string)
return @"";
- return [(NSString *)CFStringCreateWithCString(NULL, string, kCFStringEncodingISOLatin1) autorelease];
+ return [NSString stringWithCString:string encoding:[[MITextEncoding irssiEncoding] encoding]];
}
//-------------------------------------------------------------------
@@ -8,7 +8,7 @@
@interface MITextEncoding : NSObject
{
- NSStringEncoding enc;
+ CFStringEncoding enc;
}
+ (NSArray*)encodings;
@@ -20,6 +20,7 @@
- (id)initWithEncoding:(NSStringEncoding)encoding;
- (id)initWithIANAString:(NSString*)string;
+- (CFStringEncoding)CFStringEncoding;
- (NSStringEncoding)encoding;
- (NSString*)IANAString;
@@ -55,7 +55,6 @@ + (MITextEncoding*)textEncodingWithEncoding:(NSStringEncoding)encoding
return [[[MITextEncoding alloc] initWithEncoding:encoding] autorelease];
}
-
+ (MITextEncoding*)irssiEncoding;
{
return [[[MITextEncoding alloc] initWithIANAString:[NSString stringWithCString:settings_get_str("term_charset") encoding:NSASCIIStringEncoding]] autorelease];
@@ -89,19 +88,24 @@ - (id)initWithIANAString:(NSString*)string
return self;
}
-- (NSStringEncoding)encoding
+- (CFStringEncoding)CFStringEncoding
{
return enc;
}
+- (NSStringEncoding)encoding
+{
+ return CFStringConvertEncodingToNSStringEncoding(enc);
+}
+
- (NSString*)IANAString
{
- return (NSString*)CFStringConvertEncodingToIANACharSetName((CFStringEncoding)enc);
+ return (NSString*)CFStringConvertEncodingToIANACharSetName(enc);
}
- (NSString*)description
{
- return (NSString*)CFStringGetNameOfEncoding((CFStringEncoding)enc);
+ return (NSString*)CFStringGetNameOfEncoding(enc);
}
@end

0 comments on commit 7406a3a

Please sign in to comment.