Try to determine the encoding of the RTF data.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@29211 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2010-01-05 13:19:24 +00:00
parent 210a987660
commit 212696a5f8
2 changed files with 37 additions and 3 deletions

View file

@ -1,3 +1,8 @@
2010-01-05 Fred Kiefer <FredKiefer@gmx.de>
* TextConverters/RTF/RTFConsumer.m (-parseRTF:...class:): Try to
determine the encoding of the RTF data.
2010-01-05 03:39-EST Gregory John Casamento <greg.casamento@gmail.com>
* Source/NSMenu.m: Do not show the menu at the top of the screen in

View file

@ -539,11 +539,40 @@ static BOOL classInheritsFromNSMutableAttributedString (Class c)
CREATE_AUTORELEASE_POOL(pool);
RTFscannerCtxt scanner;
StringContext stringCtxt;
// We should read in the first few characters to find out which
NSString *rtfString;
char buffer[5];
NSStringEncoding encoding = NSASCIIStringEncoding;
// We read in the first few characters to find out which
// encoding we have
NSString *rtfString = [[NSString alloc]
if ([rtfData length] < 10)
{
// Too short to be an RTF
return nil;
}
[rtfData getBytes: buffer range: NSMakeRange(7, 3)];
if (strncmp(buffer, "mac", 3) == 0)
{
encoding = NSMacOSRomanStringEncoding;
}
else if (strncmp(buffer, "pc", 2) == 0)
{
// FIXME: Code page 437 kCFStringEncodingDOSLatinUS
encoding = NSASCIIStringEncoding;
}
else if (strncmp(buffer, "pca", 3) == 0)
{
// FIXME: Code page 850 kCFStringEncodingDOSLatin1
encoding = NSASCIIStringEncoding;
}
else if (strncmp(buffer, "ansi", 2) == 0)
{
encoding = NSASCIIStringEncoding;
}
rtfString = [[NSString alloc]
initWithData: rtfData
encoding: NSASCIIStringEncoding];
encoding: encoding];
// Reset this RFTConsumer, as it might already have been used!
_class = class;