Minor tidyup

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@13631 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2002-05-11 07:50:47 +00:00
parent 80cf1e3e72
commit 9fbec32045
2 changed files with 33 additions and 10 deletions

View file

@ -2,6 +2,9 @@
* Source/Unicode.m: Rationalise so that all conversion operations
go through the two new functions. Gets rid of a load of old code.
* Source/GSString.m: ([-replaceCharactersInRange:withString:])
minor performance enhancement when copying from a 16-bit string
to an 8-bit string.
2002-05-10 Adam Fedor <fedor@gnu.org>

View file

@ -2938,23 +2938,43 @@ transmute(ivars self, NSString *aString)
}
else
{
/*
* As we got here, intEnc == defEnc, so we can use standard
* CString methods to get the characters into our buffer,
* or may even be able to copy from another string directly.
*/
if (other == 0)
{
unsigned l;
/*
* Since getCString appends a '\0' terminator, we must ask for
* one character less than we actually want, then get the last
* character separately.
* Since getCString appends a '\0' terminator, we must handle
* that problem in copying data into our buffer. Either by
* saving and restoring the character which would be
* overwritten by the nul, or by getting a character less,
* and fetching the last character separately.
*/
l = length - 1;
if (l > 0)
if (aRange.location + length < _count)
{
unsigned char tmp = _contents.c[aRange.location + length];
[aString getCString: &_contents.c[aRange.location]
maxLength: l];
maxLength: length];
_contents.c[aRange.location + length] = tmp;
}
else
{
unsigned int l = length - 1;
unsigned int size = 1;
unichar u;
unsigned char *dst = &_contents.c[aRange.location + l];
if (l > 0)
{
[aString getCString: &_contents.c[aRange.location]
maxLength: l];
}
u = [aString characterAtIndex: l];
GSFromUnicode(&dst, &size, &u, 1, intEnc, 0, 0);
}
_contents.c[aRange.location + l]
= encode_unitochar([aString characterAtIndex: l], intEnc);
}
else
{