Minor fixes and tidyups

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@7710 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 2000-10-05 15:17:18 +00:00
parent 886aa9fc59
commit 05fbf4a225
4 changed files with 90 additions and 34 deletions

View file

@ -1,3 +1,10 @@
2000-10-05 Richard Frith-Macdonald <rfm@gnu.org>
* Source/Makefile.preamble (ADDITIONAL_CPPFLAGS): Replace
DEFS (lost in last change) to set default paths for NSBundle etc.
* Source/NSString.m: Minor range fixes.
* Source/NSGString.m: initialisation fixes.
2000-10-04 Adam Fedor <fedor@gnu.org> 2000-10-04 Adam Fedor <fedor@gnu.org>
* Source/Makefile.preamble (ADDITIONAL_CPPFLAGS): Add * Source/Makefile.preamble (ADDITIONAL_CPPFLAGS): Add

View file

@ -39,7 +39,8 @@
# #
# Additional flags to pass to the preprocessor # Additional flags to pass to the preprocessor
ADDITIONAL_CPPFLAGS = $(CONFIG_SYSTEM_DEFS) -DHAVE_LIBXML=$(HAVE_LIBXML) -Wall ADDITIONAL_CPPFLAGS = $(DEFS) $(CONFIG_SYSTEM_DEFS) \
-DHAVE_LIBXML=$(HAVE_LIBXML) -Wall
# Additional flags to pass to the Objective-C compiler # Additional flags to pass to the Objective-C compiler
ADDITIONAL_OBJCFLAGS = ADDITIONAL_OBJCFLAGS =

View file

@ -179,23 +179,19 @@
length: (unsigned int)length length: (unsigned int)length
freeWhenDone: (BOOL)flag freeWhenDone: (BOOL)flag
{ {
self = [super init]; _count = length;
if (self != nil) _contents_chars = chars;
if (flag == YES && chars != 0)
{ {
_count = length;
_contents_chars = chars;
if (flag == YES && chars != 0)
{
#if GS_WITH_GC #if GS_WITH_GC
_zone = GSAtomicMallocZone(); _zone = GSAtomicMallocZone();
#else #else
_zone = NSZoneFromPointer(chars); _zone = NSZoneFromPointer(chars);
#endif #endif
} }
else else
{ {
_zone = 0; _zone = 0;
}
} }
return self; return self;
} }
@ -663,24 +659,20 @@ stringDecrementCountAndFillHoleAt(NSGMutableStringStruct *self,
length: (unsigned int)length length: (unsigned int)length
freeWhenDone: (BOOL)flag freeWhenDone: (BOOL)flag
{ {
self = [super init]; _count = length;
if (self != nil) _capacity = length;
_contents_chars = chars;
if (flag == YES && chars != 0)
{ {
_count = length;
_capacity = length;
_contents_chars = chars;
if (flag == YES && chars != 0)
{
#if GS_WITH_GC #if GS_WITH_GC
_zone = GSAtomicMallocZone(); _zone = GSAtomicMallocZone();
#else #else
_zone = NSZoneFromPointer(chars); _zone = NSZoneFromPointer(chars);
#endif #endif
} }
else else
{ {
_zone = 0; _zone = 0;
}
} }
return self; return self;
} }

View file

@ -213,6 +213,24 @@ handle_printf_atsign (FILE *stream,
} }
#endif /* HAVE_REGISTER_PRINTF_FUNCTION */ #endif /* HAVE_REGISTER_PRINTF_FUNCTION */
static NSRange
rangeOfSequence(NSString *self, unichar (*caiImp)(NSString*, SEL, unsigned),
unsigned index)
{
unsigned count = [self length];
unsigned start;
unsigned end;
start = index;
while (uni_isnonsp((*caiImp)(self, caiSel, start)) && start > 0)
start--;
end = start + 1;
if (end < count)
while ((end < count) && (uni_isnonsp((*caiImp)(self, caiSel, end))))
end++;
return (NSRange){start, end-start};
}
+ (void) initialize + (void) initialize
{ {
if (self == [NSString class]) if (self == [NSString class])
@ -908,7 +926,7 @@ handle_printf_atsign (FILE *stream,
- (id) init - (id) init
{ {
self = [super init]; self = [self initWithCharactersNoCopy: 0 length: 0 freeWhenDone: 0];
return self; return self;
} }
@ -931,7 +949,7 @@ handle_printf_atsign (FILE *stream,
/* Inefficient. Should be overridden */ /* Inefficient. Should be overridden */
- (void) getCharacters: (unichar*)buffer - (void) getCharacters: (unichar*)buffer
{ {
[self getCharacters: buffer range: ((NSRange){0,[self length]})]; [self getCharacters: buffer range: ((NSRange){0, [self length]})];
return; return;
} }
@ -942,10 +960,26 @@ handle_printf_atsign (FILE *stream,
unsigned l = [self length]; unsigned l = [self length];
unsigned i; unsigned i;
unichar (*caiImp)(NSString*, SEL, unsigned); unichar (*caiImp)(NSString*, SEL, unsigned);
NSRange boundary;
GS_RANGE_CHECK(aRange, l); GS_RANGE_CHECK(aRange, l);
caiImp = (unichar (*)())[self methodForSelector: caiSel]; caiImp = (unichar (*)())[self methodForSelector: caiSel];
/*
* Handle composed character sequences.
*/
if (aRange.location > 0)
{
boundary = rangeOfSequence(self, caiImp, aRange.location);
aRange.location = boundary.location;
}
if (NSMaxRange(aRange) < l)
{
boundary = rangeOfSequence(self, caiImp, NSMaxRange(aRange));
aRange.length = NSMaxRange(boundary) - aRange.location;
}
for (i = 0; i < aRange.length; i++) for (i = 0; i < aRange.length; i++)
{ {
buffer[i] = (*caiImp)(self, caiSel, aRange.location + i); buffer[i] = (*caiImp)(self, caiSel, aRange.location + i);
@ -1237,6 +1271,11 @@ handle_printf_atsign (FILE *stream,
return NO; return NO;
} }
/*
* Return 28-bit hash value (in 32-bit integer). The top few bits are used
* for other purposes in a bitfield in the concrete string subclasses, so we
* must not use the full unsigned integer.
*/
- (unsigned) hash - (unsigned) hash
{ {
unsigned ret = 0; unsigned ret = 0;
@ -1267,11 +1306,13 @@ handle_printf_atsign (FILE *stream,
* an empty cache value, so we MUST NOT return a hash of zero. * an empty cache value, so we MUST NOT return a hash of zero.
*/ */
if (ret == 0) if (ret == 0)
ret = 0xffffffff; ret = 0x0fffffff;
else
ret &= 0x0fffffff;
return ret; return ret;
} }
else else
return 0xfffffffe; /* Hash for an empty string. */ return 0x0ffffffe; /* Hash for an empty string. */
} }
// Getting a Shared Prefix // Getting a Shared Prefix
@ -1704,7 +1745,6 @@ handle_printf_atsign (FILE *stream,
remainingRange: NULL]; remainingRange: NULL];
} }
// xxx FIXME adjust range for composite sequence
- (void) getCString: (char*)buffer - (void) getCString: (char*)buffer
maxLength: (unsigned)maxLength maxLength: (unsigned)maxLength
range: (NSRange)aRange range: (NSRange)aRange
@ -1713,10 +1753,27 @@ handle_printf_atsign (FILE *stream,
unsigned len; unsigned len;
unsigned count; unsigned count;
unichar (*caiImp)(NSString*, SEL, unsigned); unichar (*caiImp)(NSString*, SEL, unsigned);
NSRange boundary;
len = [self cStringLength]; len = [self cStringLength];
GS_RANGE_CHECK(aRange, len); GS_RANGE_CHECK(aRange, len);
caiImp = (unichar (*)())[self methodForSelector: caiSel];
/*
* Handle composed character sequences.
*/
if (aRange.location > 0)
{
boundary = rangeOfSequence(self, caiImp, aRange.location);
aRange.location = boundary.location;
}
if (NSMaxRange(aRange) < [self length])
{
boundary = rangeOfSequence(self, caiImp, NSMaxRange(aRange));
aRange.length = NSMaxRange(boundary) - aRange.location;
}
if (maxLength < aRange.length) if (maxLength < aRange.length)
{ {
len = maxLength; len = maxLength;
@ -1735,7 +1792,6 @@ handle_printf_atsign (FILE *stream,
leftoverRange->length = aRange.length - maxLength; leftoverRange->length = aRange.length - maxLength;
} }
} }
caiImp = (unichar (*)())[self methodForSelector: caiSel];
count = 0; count = 0;
while (count < len) while (count < len)
{ {