Avoid unneeded space characters in RTF data.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@30273 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
fredkiefer 2010-05-01 16:31:03 +00:00
parent 56d321274c
commit 2cd8ea83fe
2 changed files with 35 additions and 18 deletions

View file

@ -1,3 +1,10 @@
2010-05-01 Fred Kiefer <FredKiefer@gmx.de>
* TextConverters/RTF/RTFProducer.m
(-_runStringForString:attributes:): Only add a delimiter when needed.
* TextConverters/RTF/RTFProducer.m (-_stringWithRTFCharacters:):
Only add the \uc0 flag when needed. Use \'AC as attachment character.
2010-05-01 Wolfgang Lux <wolfgang.lux@gmail.com> 2010-05-01 Wolfgang Lux <wolfgang.lux@gmail.com>
* TextConverters/RTF/rtfGrammer.y: Ignore the string parameter of * TextConverters/RTF/rtfGrammer.y: Ignore the string parameter of

View file

@ -722,7 +722,8 @@
NSMutableData *resultData; NSMutableData *resultData;
unichar *buffer; unichar *buffer;
int length, i; int length, i;
BOOL uc_flagged = NO;
if (string == nil) if (string == nil)
{ {
return nil; return nil;
@ -734,9 +735,6 @@
resultData = [[NSMutableData alloc] resultData = [[NSMutableData alloc]
initWithCapacity: (int)(length * 1.2)]; initWithCapacity: (int)(length * 1.2)];
// We don't supply an ANSI representation for Unicode characters
[resultData appendBytes: "\\uc0 " length: 5];
for (i = 0; i < length; i++) for (i = 0; i < length; i++)
{ {
unichar c; unichar c;
@ -767,10 +765,10 @@
[resultData appendBytes: "\\}" length: 2]; [resultData appendBytes: "\\}" length: 2];
break; break;
case '`': case '`':
[resultData appendBytes: "\\lquote }" length: 8]; [resultData appendBytes: "\\lquote " length: 8];
break; break;
case '\'': case '\'':
[resultData appendBytes: "\\rquote }" length: 8]; [resultData appendBytes: "\\rquote " length: 8];
break; break;
default: default:
[resultData appendBytes: &ansiChar length: 1]; [resultData appendBytes: &ansiChar length: 1];
@ -780,28 +778,34 @@
else if (c < 0xFF) else if (c < 0xFF)
{ {
char unicodeCommand[16]; char unicodeCommand[16];
unicodeCommand[15] = '\0';
sprintf(unicodeCommand, "\\'%X", (short)c); snprintf(unicodeCommand, 16, "\\'%X ", (short)c);
unicodeCommand[15] = '\0';
[resultData appendBytes: unicodeCommand [resultData appendBytes: unicodeCommand
length: strlen(unicodeCommand)]; length: strlen(unicodeCommand)];
} }
else if (c == NSAttachmentCharacter)
{
[resultData appendBytes: "\\'AC}" length: 5];
}
else else
{ {
// write unicode encoding // write unicode encoding
char unicodeCommand[16]; char unicodeCommand[16];
if (!uc_flagged)
{
// We don't supply an ANSI representation for Unicode characters
[resultData appendBytes: "\\uc0 " length: 5];
uc_flagged = YES;
}
snprintf(unicodeCommand, 16, "\\u%d ", (short)c);
unicodeCommand[15] = '\0'; unicodeCommand[15] = '\0';
sprintf(unicodeCommand, "\\u%d ", (short)c);
[resultData appendBytes: unicodeCommand [resultData appendBytes: unicodeCommand
length: strlen(unicodeCommand)]; length: strlen(unicodeCommand)];
if (c == NSAttachmentCharacter)
{
[resultData appendBytes: "}" length: 1];
}
} }
} }
@ -1036,9 +1040,15 @@
RELEASE(attributesToRemove); RELEASE(attributesToRemove);
RELEASE(attributesToAdd); RELEASE(attributesToAdd);
if ([result length]) // ensure delimiter if ([result length])
{ {
[result appendString: @" "]; unichar c = [result characterAtIndex: [result length] - 1];
if ((c != '}') && (c != ' '))
{
// ensure delimiter
[result appendString: @" "];
}
} }
[result appendString: [self _stringWithRTFCharacters: string]]; [result appendString: [self _stringWithRTFCharacters: string]];