mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 16:50:58 +00:00
Fix for unicode data returned as cstring.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@21199 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
d5e0804ab0
commit
04bfaf2fb5
3 changed files with 31 additions and 3 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
2005-05-08 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* Source/NSString.m: nul terminate properly when a returned 'C string'
|
||||||
|
is actually unicode.
|
||||||
|
* Source/GSString.m: ditto.
|
||||||
|
|
||||||
2005-05-08 Fred Kiefer <FredKiefer@gmx.de>
|
2005-05-08 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
* Source/NSPropertyList.m: Added class BinaryPLGenerator to export
|
* Source/NSPropertyList.m: Added class BinaryPLGenerator to export
|
||||||
|
|
|
@ -927,7 +927,7 @@ cString_c(GSStr self, NSStringEncoding enc)
|
||||||
|
|
||||||
if (self->_count == 0)
|
if (self->_count == 0)
|
||||||
{
|
{
|
||||||
return "";
|
return "\0";
|
||||||
}
|
}
|
||||||
if (enc == intEnc)
|
if (enc == intEnc)
|
||||||
{
|
{
|
||||||
|
@ -976,7 +976,16 @@ cString_u(GSStr self, NSStringEncoding enc)
|
||||||
|
|
||||||
if (c == 0)
|
if (c == 0)
|
||||||
{
|
{
|
||||||
return "";
|
return "\0";
|
||||||
|
}
|
||||||
|
else if (enc == NSUnicodeStringEncoding)
|
||||||
|
{
|
||||||
|
unichar *tmp = (unichar*)NSZoneMalloc(NSDefaultMallocZone(), (c + 1)*2);
|
||||||
|
|
||||||
|
memcpy(tmp, self->_contents.u, c*2);
|
||||||
|
tmp[c] = 0;
|
||||||
|
[NSData dataWithBytesNoCopy: tmp length: (c + 1)*2 freeWhenDone: YES];
|
||||||
|
return (char*)tmp;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -2849,7 +2849,16 @@ handle_printf_atsign (FILE *stream,
|
||||||
format: @"unable to convert to cString"];
|
format: @"unable to convert to cString"];
|
||||||
}
|
}
|
||||||
m = [d mutableCopy];
|
m = [d mutableCopy];
|
||||||
[m appendBytes: "" length: 1];
|
if (encoding == NSUnicodeStringEncoding)
|
||||||
|
{
|
||||||
|
unichar c = 0;
|
||||||
|
|
||||||
|
[m appendBytes: &c length: 2];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
[m appendBytes: "" length: 1];
|
||||||
|
}
|
||||||
AUTORELEASE(m);
|
AUTORELEASE(m);
|
||||||
return (const char*)[m bytes];
|
return (const char*)[m bytes];
|
||||||
}
|
}
|
||||||
|
@ -2974,6 +2983,10 @@ handle_printf_atsign (FILE *stream,
|
||||||
|
|
||||||
if (len > maxLength) len = maxLength;
|
if (len > maxLength) len = maxLength;
|
||||||
memcpy(buffer, [d bytes], len);
|
memcpy(buffer, [d bytes], len);
|
||||||
|
if (encoding == NSUnicodeStringEncoding)
|
||||||
|
{
|
||||||
|
buffer[len++] = '\0';
|
||||||
|
}
|
||||||
buffer[len] = '\0';
|
buffer[len] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue