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:
Fred Kiefer 2010-05-01 16:31:03 +00:00
parent 756db465e4
commit 5359aa0a77
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>
* TextConverters/RTF/rtfGrammer.y: Ignore the string parameter of

View file

@ -722,7 +722,8 @@
NSMutableData *resultData;
unichar *buffer;
int length, i;
BOOL uc_flagged = NO;
if (string == nil)
{
return nil;
@ -734,9 +735,6 @@
resultData = [[NSMutableData alloc]
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++)
{
unichar c;
@ -767,10 +765,10 @@
[resultData appendBytes: "\\}" length: 2];
break;
case '`':
[resultData appendBytes: "\\lquote }" length: 8];
[resultData appendBytes: "\\lquote " length: 8];
break;
case '\'':
[resultData appendBytes: "\\rquote }" length: 8];
[resultData appendBytes: "\\rquote " length: 8];
break;
default:
[resultData appendBytes: &ansiChar length: 1];
@ -780,28 +778,34 @@
else if (c < 0xFF)
{
char unicodeCommand[16];
unicodeCommand[15] = '\0';
sprintf(unicodeCommand, "\\'%X", (short)c);
snprintf(unicodeCommand, 16, "\\'%X ", (short)c);
unicodeCommand[15] = '\0';
[resultData appendBytes: unicodeCommand
length: strlen(unicodeCommand)];
}
else if (c == NSAttachmentCharacter)
{
[resultData appendBytes: "\\'AC}" length: 5];
}
else
{
// write unicode encoding
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';
sprintf(unicodeCommand, "\\u%d ", (short)c);
[resultData appendBytes: unicodeCommand
length: strlen(unicodeCommand)];
if (c == NSAttachmentCharacter)
{
[resultData appendBytes: "}" length: 1];
}
length: strlen(unicodeCommand)];
}
}
@ -1036,9 +1040,15 @@
RELEASE(attributesToRemove);
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]];