* Source/NSAttributedString.m

(-initWithData:options:documentAttributes:error:): Fixes for TextEdit.
If no type is provided, assume plain text. If no encoding is provided,
assume UTF-8 unless a UTF-16 BOM is detected.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@34985 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Eric Wasylishen 2012-03-23 01:40:11 +00:00
parent 93ca7c0e0e
commit 9345069a14
2 changed files with 32 additions and 5 deletions

View file

@ -1,3 +1,10 @@
2012-03-22 Eric Wasylishen <ewasylishen@gmail.com>
* Source/NSAttributedString.m
(-initWithData:options:documentAttributes:error:): Fixes for TextEdit.
If no type is provided, assume plain text. If no encoding is provided,
assume UTF-8 unless a UTF-16 BOM is detected.
2012-03-22 Eric Wasylishen <ewasylishen@gmail.com>
* Source/GSThemeDrawing.m (-toolbarBorderColor): Change default to

View file

@ -797,11 +797,7 @@ create_error(int code, NSString* desc)
}
if (type == nil)
{
if (error)
*error = create_error(0, NSLocalizedString(@"No type specified for data.",
@"Error description"));
RELEASE(self);
return nil;
type = NSPlainTextDocumentType;
}
converter = converter_class(type, NO);
@ -829,6 +825,30 @@ create_error(int code, NSString* desc)
NSDictionary *defaultAttrs = [options objectForKey: @"DefaultAttributes"];
NSString *str;
if (encoding == GSUndefinedEncoding)
{
encoding = NSUTF8StringEncoding;
if ([data length] >= 2)
{
static const unichar byteOrderMark = 0xFEFF;
static const unichar byteOrderMarkSwapped = 0xFFFE;
const unichar firstChar = ((const unichar *)[data bytes])[0];
if (firstChar == byteOrderMark
|| firstChar == byteOrderMarkSwapped)
{
encoding = NSUnicodeStringEncoding;
}
}
}
if (dict != NULL)
{
*dict = [NSDictionary dictionaryWithObjectsAndKeys:
NSPlainTextDocumentType, NSDocumentTypeDocumentAttribute,
nil];
}
str = [[NSString alloc] initWithData: data
encoding: encoding];
self = [self initWithString: str