mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-25 09:41:15 +00:00
Implement -mutableCopyWithZone: for tiny strings.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@38543 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
8d31d3a100
commit
3accb5c02c
1 changed files with 27 additions and 7 deletions
|
@ -1002,6 +1002,26 @@ tsbytes(uintptr_t s, char *buf)
|
||||||
return strtoll(buf, 0, 10);
|
return strtoll(buf, 0, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (id) mutableCopyWithZone: (NSZone*)z
|
||||||
|
{
|
||||||
|
uintptr_t s = (uintptr_t)self;
|
||||||
|
NSUInteger i;
|
||||||
|
NSUInteger l;
|
||||||
|
GSMutableString *obj;
|
||||||
|
char bytes[8];
|
||||||
|
|
||||||
|
l = (s >> TINY_STRING_LENGTH_SHIFT) & TINY_STRING_LENGTH_MASK;
|
||||||
|
for (i = 0; i < l; i++)
|
||||||
|
{
|
||||||
|
bytes[i] = (unichar)TINY_STRING_CHAR(s, i);
|
||||||
|
}
|
||||||
|
obj = (GSMutableString*)NSAllocateObject(GSMutableStringClass, 0, z);
|
||||||
|
obj = [obj initWithBytes: bytes
|
||||||
|
length: l
|
||||||
|
encoding: internalEncoding];
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
- (NSRange) rangeOfComposedCharacterSequenceAtIndex: (NSUInteger)anIndex
|
- (NSRange) rangeOfComposedCharacterSequenceAtIndex: (NSUInteger)anIndex
|
||||||
{
|
{
|
||||||
uintptr_t s = (uintptr_t)self;
|
uintptr_t s = (uintptr_t)self;
|
||||||
|
@ -1679,6 +1699,7 @@ fixBOM(unsigned char **bytes, NSUInteger*length, BOOL *owned,
|
||||||
|
|
||||||
- (id) initWithUTF8String: (const char*)bytes
|
- (id) initWithUTF8String: (const char*)bytes
|
||||||
{
|
{
|
||||||
|
const unsigned char *b = (const unsigned char*)bytes;
|
||||||
BOOL ascii = YES;
|
BOOL ascii = YES;
|
||||||
NSUInteger length;
|
NSUInteger length;
|
||||||
GSStr me;
|
GSStr me;
|
||||||
|
@ -1690,19 +1711,19 @@ fixBOM(unsigned char **bytes, NSUInteger*length, BOOL *owned,
|
||||||
}
|
}
|
||||||
/* Skip leading BOM
|
/* Skip leading BOM
|
||||||
*/
|
*/
|
||||||
if (bytes[0] == 0xEF && bytes[1] == 0xBB && bytes[2] == 0xBF)
|
if (b[0] == 0xEF && b[1] == 0xBB && b[2] == 0xBF)
|
||||||
{
|
{
|
||||||
bytes = &bytes[3];
|
b = &b[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
length = 0;
|
length = 0;
|
||||||
while ((c = bytes[length]))
|
while ((c = b[length]))
|
||||||
{
|
{
|
||||||
length++;
|
length++;
|
||||||
if (c > 127)
|
if (c > 127)
|
||||||
{
|
{
|
||||||
ascii = NO;
|
ascii = NO;
|
||||||
while (bytes[length])
|
while (b[length])
|
||||||
{
|
{
|
||||||
length++;
|
length++;
|
||||||
}
|
}
|
||||||
|
@ -1712,19 +1733,18 @@ fixBOM(unsigned char **bytes, NSUInteger*length, BOOL *owned,
|
||||||
|
|
||||||
if (YES == ascii)
|
if (YES == ascii)
|
||||||
{
|
{
|
||||||
id o = createTinyString(bytes, length);
|
id o = createTinyString((const char*)b, length);
|
||||||
|
|
||||||
if (nil == o)
|
if (nil == o)
|
||||||
{
|
{
|
||||||
me = (GSStr)newCInline(length, myZone);
|
me = (GSStr)newCInline(length, myZone);
|
||||||
memcpy(me->_contents.c, bytes, length);
|
memcpy(me->_contents.c, b, length);
|
||||||
o = (id)me;
|
o = (id)me;
|
||||||
}
|
}
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const unsigned char *b = (const unsigned char*)bytes;
|
|
||||||
unichar *u = 0;
|
unichar *u = 0;
|
||||||
unsigned l = 0;
|
unsigned l = 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue