mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
merge best of David's code and mine to form efficient -dataUsingEncoding:...
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@23296 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
db36f7c15d
commit
a7243126e1
1 changed files with 43 additions and 12 deletions
|
@ -2767,11 +2767,34 @@ handle_printf_atsign (FILE *stream,
|
|||
{
|
||||
d = [NSDataClass data];
|
||||
}
|
||||
else if (encoding == NSUnicodeStringEncoding)
|
||||
{
|
||||
unichar *u;
|
||||
unsigned l;
|
||||
|
||||
u = (unichar*)NSZoneMalloc(NSDefaultMallocZone(),
|
||||
(len + 1) * sizeof(unichar));
|
||||
*u = byteOrderMark;
|
||||
[self getCharacters: u + 1];
|
||||
l = GSUnicode(u, len, 0, 0);
|
||||
if (l == len || flag == YES)
|
||||
{
|
||||
d = [NSDataClass dataWithBytesNoCopy: u
|
||||
length: (l + 1) * sizeof(unichar)];
|
||||
}
|
||||
else
|
||||
{
|
||||
d = nil;
|
||||
NSZoneFree(NSDefaultMallocZone(), u);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
unichar buf[8192];
|
||||
unichar *u = buf;
|
||||
GSStr_t s;
|
||||
unichar buf[8192];
|
||||
unichar *u = buf;
|
||||
unsigned int options;
|
||||
unsigned char *b = 0;
|
||||
unsigned int l = 0;
|
||||
|
||||
/* Build a fake object on the stack and copy unicode characters
|
||||
* into its buffer from the receiver.
|
||||
|
@ -2783,15 +2806,23 @@ handle_printf_atsign (FILE *stream,
|
|||
u = objc_malloc(len * sizeof(unichar));
|
||||
}
|
||||
[self getCharacters: u];
|
||||
s.isa = GSMutableStringClass;
|
||||
s._zone = 0;
|
||||
s._contents.u = u;
|
||||
s._capacity = len;
|
||||
s._count = len;
|
||||
s._flags.wide = 1;
|
||||
s._flags.free = 0;
|
||||
d = [(NSString*)&s dataUsingEncoding: encoding
|
||||
allowLossyConversion: flag];
|
||||
if (flag == NO)
|
||||
{
|
||||
options = GSUniStrict;
|
||||
}
|
||||
else
|
||||
{
|
||||
options = 0;
|
||||
}
|
||||
if (GSFromUnicode(&b, &l, u, len, encoding, NSDefaultMallocZone(),
|
||||
options) == YES)
|
||||
{
|
||||
d = [NSDataClass dataWithBytesNoCopy: b length: l];
|
||||
}
|
||||
else
|
||||
{
|
||||
d = nil;
|
||||
}
|
||||
if (u != buf)
|
||||
{
|
||||
objc_free(u);
|
||||
|
|
Loading…
Reference in a new issue