mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 00:11:26 +00:00
A couple of string fixes.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@13110 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
9c87dfaf28
commit
7026a16891
4 changed files with 155 additions and 149 deletions
|
@ -645,18 +645,20 @@ cString_c(ivars self)
|
|||
static inline char*
|
||||
cString_u(ivars self)
|
||||
{
|
||||
int l = self->_count;
|
||||
char *r = (char*)_fastMallocBuffer(l + 1);
|
||||
int l = self->_count;
|
||||
char *r = (char*)_fastMallocBuffer(l*2 + 1);
|
||||
unsigned limit = 0;
|
||||
|
||||
if (l > 0)
|
||||
{
|
||||
if (encode_ustrtocstr(r, l, self->_contents.u, l, defEnc, YES) == 0)
|
||||
limit = encode_ustrtocstr(r, l, self->_contents.u, l, defEnc, YES);
|
||||
if (limit == 0)
|
||||
{
|
||||
[NSException raise: NSCharacterConversionException
|
||||
format: @"Can't get cString from Unicode string."];
|
||||
}
|
||||
}
|
||||
r[l] = '\0';
|
||||
r[limit] = '\0';
|
||||
|
||||
return r;
|
||||
}
|
||||
|
@ -672,19 +674,21 @@ cStringLength_u(ivars self)
|
|||
{
|
||||
unsigned c;
|
||||
unsigned l = self->_count;
|
||||
unsigned limit = 0;
|
||||
|
||||
if (l > 0)
|
||||
{
|
||||
char *r;
|
||||
|
||||
r = (char*)NSZoneMalloc(NSDefaultMallocZone(), l + 1);
|
||||
if (encode_ustrtocstr(r, l, self->_contents.u, l, defEnc, NO) == 0)
|
||||
r = (char*)NSZoneMalloc(NSDefaultMallocZone(), l*2 + 1);
|
||||
limit = encode_ustrtocstr(r, l, self->_contents.u, l, defEnc, NO);
|
||||
if (limit == 0)
|
||||
{
|
||||
NSZoneFree(NSDefaultMallocZone(), r);
|
||||
[NSException raise: NSCharacterConversionException
|
||||
format: @"Can't get cStringLength from Unicode string."];
|
||||
}
|
||||
r[l] = '\0';
|
||||
r[limit] = '\0';
|
||||
c = strlen(r);
|
||||
NSZoneFree(NSDefaultMallocZone(), r);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue