git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3659 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 1999-02-04 22:06:59 +00:00
parent fc08f546a8
commit 571d4548e7
2 changed files with 65 additions and 52 deletions

View file

@ -1,3 +1,9 @@
Thu Feb 4 13:10:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSString.m: ([-dataUsingEncoding:allowLossyConversion:])
Removed spurious trailing nul and other spurious code having no
effect - formatted to be readable.
Thu Feb 4 13:10:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
Deleted all the old property-list and strings-file parsing stuff.

View file

@ -2144,66 +2144,73 @@ else
// xxx incomplete
- (NSData*) dataUsingEncoding: (NSStringEncoding)encoding
allowLossyConversion: (BOOL)flag
allowLossyConversion: (BOOL)flag
{
int count=0;
int len = [self length];
if ((encoding==NSASCIIStringEncoding)
|| (encoding==NSISOLatin1StringEncoding)
|| (encoding==NSNEXTSTEPStringEncoding)
|| (encoding==NSNonLossyASCIIStringEncoding)
|| (encoding==NSSymbolStringEncoding)
|| (encoding==NSCyrillicStringEncoding))
{
char t;
unsigned char *buff;
|| (encoding==NSISOLatin1StringEncoding)
|| (encoding==NSNEXTSTEPStringEncoding)
|| (encoding==NSNonLossyASCIIStringEncoding)
|| (encoding==NSSymbolStringEncoding)
|| (encoding==NSCyrillicStringEncoding))
{
char t;
unsigned char *buff;
buff = (unsigned char*)NSZoneMalloc(NSDefaultMallocZone(), len+1);
if (!flag)
for(count=0; count<len; count++)
if ((t = encode_unitochar([self characterAtIndex: count], encoding)))
buff[count] = t;
else
{
NSZoneFree(NSDefaultMallocZone(), buff);
return nil;
}
else /* lossy */
for(count=0; count<len; count++)
if ((t = encode_unitochar([self characterAtIndex: count], encoding)))
buff[count] = t;
else
{
t=[[NSGSequence sequenceWithString: self
range:
[self rangeOfComposedCharacterSequenceAtIndex: count]]
baseCharacter];
if ((t = encode_unitochar([self characterAtIndex: count], encoding)))
buff[count] = t;
else
/* xxx should handle decomposed characters */
/* OpenStep documentation is unclear on what to do if there is no
simple replacement for character */
buff[count] = '*';
};
buff[count]=0;
return [NSData dataWithBytesNoCopy: buff length: count+1];
buff = (unsigned char*)NSZoneMalloc(NSDefaultMallocZone(), len);
if (!flag)
{
for (count = 0; count < len; count++)
{
t = encode_unitochar([self characterAtIndex: count], encoding);
if (t)
{
buff[count] = t;
}
else
{
NSZoneFree(NSDefaultMallocZone(), buff);
return nil;
}
}
}
else /* lossy */
{
for (count = 0; count < len; count++)
{
t = encode_unitochar([self characterAtIndex: count], encoding);
if (t)
{
buff[count] = t;
}
else
{
/* xxx should handle decomposed characters */
/* OpenStep documentation is unclear on what to do
* if there is no simple replacement for character
*/
buff[count] = '*';
}
}
return [NSData dataWithBytesNoCopy: buff length: count];
}
}
else
if (encoding==NSUnicodeStringEncoding)
{
unichar *buff;
else if (encoding == NSUnicodeStringEncoding)
{
unichar *buff;
buff = (unichar*)NSZoneMalloc(NSDefaultMallocZone(), 2*(len+2));
buff[0]=0xFEFF;
for(count=0; count<len; count++)
buff[count+1]=[self characterAtIndex: count];
buff[count+1]= (unichar)0;
return [NSData dataWithBytesNoCopy: buff length: 2*(len+2)];
}
else /* UTF8 or EUC */
[self notImplemented:_cmd];
buff = (unichar*)NSZoneMalloc(NSDefaultMallocZone(), 2*len+2);
buff[0]=0xFEFF;
for (count = 0; count < len; count++)
buff[count+1] = [self characterAtIndex: count];
return [NSData dataWithBytesNoCopy: buff length: 2*len+2];
}
else /* UTF8 or EUC */
{
[self notImplemented:_cmd];
}
return nil;
}