From fc60476d530ec7212621c30a72819831dcc27d40 Mon Sep 17 00:00:00 2001 From: Wolfgang Lux Date: Fri, 18 Jun 2010 07:49:26 +0000 Subject: [PATCH] Attempt to auto detect the document type when initializing an attributed string and the type wasn't specified by the caller. Carefully add base URL to the document importing options only when it is not nil. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@30774 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 11 ++++++++ Source/NSAttributedString.m | 56 ++++++++++++++++++++++++++++++------- 2 files changed, 57 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 215a6377a..3917e071b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2010-06-18 Wolfgang Lux + + * Source/NSAttributedString.m + (-initWithData:options:documentAttributes:error:): Attempt to auto + detect the document type if it wasn't specified by the caller. + Currently works for RTF and HTML documents. + + * Source/NSAttributedString.m (-initWithURL:documentAttributes:, + -initWithURL:options:documentAttributes:error:): Add base URL to + the document importing options only if it is not nil. + 2010-06-15 Wolfgang Lux * Source/NSMenu.m (-performKeyEquivalent:): Fix Doug's previous diff --git a/Source/NSAttributedString.m b/Source/NSAttributedString.m index 70935b662..096ea5e15 100644 --- a/Source/NSAttributedString.m +++ b/Source/NSAttributedString.m @@ -32,6 +32,7 @@ #import #import #import +#import #import #import #import @@ -765,7 +766,31 @@ create_error(int code, NSString* desc) if (type == nil) { - // FIXME: try to determine type + const void *dataBytes = [data bytes]; + + // The list of file types below was derived from Apache's conf/magic file + // FIXME extend the list + if (strncmp(dataBytes, "{\\rtf", 5) == 0) + { + type = NSRTFTextDocumentType; + } + else if (strncmp(dataBytes, "