mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +00:00
Improved -description writing/reading. Bug fixes to NSString.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@2429 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
8066576c56
commit
5f4545a79a
10 changed files with 139 additions and 44 deletions
24
ChangeLog
24
ChangeLog
|
@ -1,3 +1,27 @@
|
|||
Tue Sep 16 15:50:39 1997 Adam Fedor <fedor@doc.com>
|
||||
|
||||
* src/Dictionary.m ([Dictionary -descriptionWithIndent:]): Rewrite
|
||||
to pretty-print description.
|
||||
* src/NSDictionary.m ([NSDictionary -description]): Remove
|
||||
redundant method implementation.
|
||||
([NSDictionary -descriptionWithIndent:]): Likewise.
|
||||
* src/NSArray.m ([NSArray -descriptionWithIndent:]): Implement.
|
||||
|
||||
* src/NSCTemplateValue ([NSCTemplateValue description]): Add
|
||||
semicolon to last value.
|
||||
* src/NSValue: ([NSValue valueFromString:]): New method.
|
||||
* src/NSNumber: ([NSValue valueFromString:]): Likewise.
|
||||
* src/include/NSValue.h: Define new method.
|
||||
|
||||
* src/NSCharacterSet.m ([NSCharacterSet -_bitmapForSet:]): Fix
|
||||
test path name.
|
||||
|
||||
* src/NSString ([NSString initWithFormat:arguments:]): Take care
|
||||
of formatted string case "%*s".
|
||||
([NSString -stringByAppendingPathComponent:]): Exception only if
|
||||
string starts with '/'.
|
||||
([NSString -stringByAppendingPathExtension:]): Likewise.
|
||||
|
||||
Mon Sep 15 21:27:00 1997 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
* src/NSHData.m: Fixed a couple of bugs occurring when allocation of
|
||||
|
|
|
@ -40,6 +40,10 @@
|
|||
+ (NSValue*) valueWithRect: (NSRect)rect;
|
||||
+ (NSValue*) valueWithSize: (NSSize)size;
|
||||
|
||||
#ifndef STRICT_OPENSTEP
|
||||
+ valueFromString: (NSString *)string;
|
||||
#endif
|
||||
|
||||
// Accessing Data
|
||||
|
||||
- (void) getValue: (void*)value;
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
#include <gnustep/base/Dictionary.h>
|
||||
#include <gnustep/base/CollectionPrivate.h>
|
||||
#include <Foundation/NSCharacterSet.h>
|
||||
|
||||
#define DEFAULT_DICTIONARY_CAPACITY 32
|
||||
|
||||
|
@ -204,30 +205,57 @@
|
|||
OBJC_FREE (*enumState);
|
||||
}
|
||||
|
||||
- (NSString*) description
|
||||
- (NSString*) descriptionWithIndent: (unsigned)level
|
||||
{
|
||||
int dict_count;
|
||||
id desc;
|
||||
id keyenum = [self keyEnumerator];
|
||||
id key;
|
||||
NSCharacterSet *quotables;
|
||||
|
||||
quotables = [[NSCharacterSet alphanumericCharacterSet] invertedSet];
|
||||
|
||||
dict_count = [self count];
|
||||
desc = [NSMutableString stringWithCapacity: 2];
|
||||
[desc appendString: @"{"];
|
||||
if (dict_count > 0)
|
||||
[desc appendString: @"\n"];
|
||||
while ((key = [keyenum nextObject]))
|
||||
{
|
||||
/* I wish appendString: returned self*/
|
||||
[desc appendString: [key description]];
|
||||
[desc appendString: @" = "];
|
||||
[desc appendString: [[self objectAtKey: key] description]];
|
||||
[desc appendString: @"; "];
|
||||
NSString *string;
|
||||
id object;
|
||||
string = [key description];
|
||||
if ([string rangeOfCharacterFromSet: quotables].length > 0)
|
||||
[desc appendFormat: @"%*s \"%@\" = ", level, "", string];
|
||||
else
|
||||
[desc appendFormat: @"%*s %@ = ", level, "", string];
|
||||
object = [self objectAtKey: key];
|
||||
if ([object respondsToSelector: @selector(descriptionWithIndent:)])
|
||||
{
|
||||
/* This a dictionary or array, so don't quote it */
|
||||
string = [object descriptionWithIndent: level+2];
|
||||
[desc appendFormat: @"%@;\n", string];
|
||||
}
|
||||
else
|
||||
{
|
||||
/* This should be a string or number, so decide if we need to
|
||||
quote it */
|
||||
string = [object description];
|
||||
if ([string rangeOfCharacterFromSet: quotables].length > 0)
|
||||
[desc appendFormat: @"\"%@\";\n", string];
|
||||
else
|
||||
[desc appendFormat: @"%@;\n", string];
|
||||
}
|
||||
}
|
||||
[desc appendString: @"}"];
|
||||
if (dict_count == 0)
|
||||
level = 0;
|
||||
[desc appendFormat: @"%*s}", level, ""];
|
||||
return desc;
|
||||
}
|
||||
|
||||
- (NSString*) descriptionWithIndent: (unsigned)level
|
||||
- (NSString*) description
|
||||
{
|
||||
return [NSString stringWithFormat:@"%*s%s",
|
||||
level, "", [[self description] cStringNoCopy]];
|
||||
return [self descriptionWithIndent: 0];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -407,8 +407,7 @@ static Class NSMutableArray_concrete_class;
|
|||
|
||||
- (NSString*) descriptionWithIndent: (unsigned)level
|
||||
{
|
||||
[self notImplemented:_cmd];
|
||||
return nil;
|
||||
return [self description];
|
||||
}
|
||||
|
||||
/* The NSCopying Protocol */
|
||||
|
|
|
@ -90,17 +90,17 @@
|
|||
- (NSString *) description
|
||||
{
|
||||
#if TYPE_ORDER == 0
|
||||
return [NSString stringWithFormat: @"{object = %@}", [data description]];
|
||||
return [NSString stringWithFormat: @"{object = %@;}", [data description]];
|
||||
#elif TYPE_ORDER == 1
|
||||
return [NSString stringWithFormat: @"{x = %g; y = %g}", data.x, data.y];
|
||||
return [NSString stringWithFormat: @"{x = %g; y = %g;}", data.x, data.y];
|
||||
#elif TYPE_ORDER == 2
|
||||
return [NSString stringWithFormat: @"{pointer = %p}", data];
|
||||
return [NSString stringWithFormat: @"{pointer = %p;}", data];
|
||||
#elif TYPE_ORDER == 3
|
||||
return [NSString stringWithFormat:
|
||||
@"{x = %g; y = %g; width = %g; height = %g}", NSMinX(data), NSMinY(data),
|
||||
@"{x = %g; y = %g; width = %g; height = %g;}", NSMinX(data), NSMinY(data),
|
||||
NSWidth(data), NSHeight(data)];
|
||||
#elif TYPE_ORDER == 4
|
||||
return [NSString stringWithFormat: @"{width = %g; height = %g}",
|
||||
return [NSString stringWithFormat: @"{width = %g; height = %g;}",
|
||||
data.width, data.height];
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include <Foundation/NSLock.h>
|
||||
|
||||
static NSString* NSCharacterSet_PATH = @"NSCharacterSets";
|
||||
|
||||
static NSString* gnustep_libdir =
|
||||
#ifdef GNUSTEP_INSTALL_LIBDIR
|
||||
@GNUSTEP_INSTALL_LIBDIR;
|
||||
|
@ -80,12 +81,12 @@ static NSLock* cache_lock = nil;
|
|||
path = [gstep_base_bundle pathForResource:setname
|
||||
ofType:@"dat"
|
||||
inDirectory:NSCharacterSet_PATH];
|
||||
/* This is for testing purposes */
|
||||
/* This is for testing purposes only! Look in uninstalled dir */
|
||||
if (path == nil || [path length] == 0)
|
||||
{
|
||||
path = [gstep_base_bundle pathForResource:setname
|
||||
ofType:@"dat"
|
||||
inDirectory:@"../NSCharacterSets"];
|
||||
path = [@"../NSCharacterSets" stringByAppendingPathComponent:
|
||||
setname];
|
||||
path = [path stringByAppendingPathExtension: @"dat"];
|
||||
}
|
||||
|
||||
if (path == nil || [path length] == 0)
|
||||
|
|
|
@ -244,28 +244,14 @@ static Class NSMutableDictionary_concrete_class;
|
|||
|
||||
- (NSString*) description
|
||||
{
|
||||
id desc;
|
||||
id keyenum = [self keyEnumerator];
|
||||
id key;
|
||||
|
||||
desc = [NSMutableString stringWithCapacity: 2];
|
||||
[desc appendString: @"{"];
|
||||
while ((key = [keyenum nextObject]))
|
||||
{
|
||||
/* I wish appendString: returned self*/
|
||||
[desc appendString: [key description]];
|
||||
[desc appendString: @" = "];
|
||||
[desc appendString: [[self objectForKey: key] description]];
|
||||
[desc appendString: @"; "];
|
||||
}
|
||||
[desc appendString: @"}"];
|
||||
return desc;
|
||||
/* This method is overridden by [Dictionary -description] */
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSString*) descriptionWithIndent: (unsigned)level
|
||||
{
|
||||
return [NSString stringWithFormat:@"%*s%s",
|
||||
level, "", [[self description] cStringNoCopy]];
|
||||
/* This method is overridden by [Dictionary -descriptionWithIndent:] */
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSArray*) allKeys
|
||||
|
|
|
@ -165,6 +165,22 @@
|
|||
autorelease];
|
||||
}
|
||||
|
||||
+ valueFromString: (NSString *)string
|
||||
{
|
||||
/* FIXME: implement this better */
|
||||
const char *str;
|
||||
|
||||
str = [string cString];
|
||||
if (strchr(str, '.') >= 0 || strchr(str, 'e') >= 0
|
||||
|| strchr(str, 'E') >= 0)
|
||||
return [NSNumber numberWithDouble: atof(str)];
|
||||
else if (strchr(str, '-') >= 0)
|
||||
return [NSNumber numberWithInt: atoi(str)];
|
||||
else
|
||||
return [NSNumber numberWithUnsignedInt: atoi(str)];
|
||||
return [NSNumber numberWithInt: 0];
|
||||
}
|
||||
|
||||
/* All the rest of these methods must be implemented by a subclass */
|
||||
- (BOOL)boolValue
|
||||
{
|
||||
|
|
|
@ -404,6 +404,8 @@ handle_printf_atsign (FILE *stream,
|
|||
va_arg(arg_list, int);
|
||||
break;
|
||||
case 's':
|
||||
if (*(spec_pos - 1) == '*')
|
||||
va_arg(arg_list, int*);
|
||||
va_arg(arg_list, char*);
|
||||
break;
|
||||
case 'f': case 'e': case 'E': case 'g': case 'G':
|
||||
|
@ -1672,7 +1674,7 @@ else
|
|||
int len, count;
|
||||
|
||||
/* xxx check to make sure aRange is within self; raise NSStringBoundsError */
|
||||
assert(aRange.location + aRange.length <= [self cStringLength]);
|
||||
assert(NSMaxRange(aRange) <= [self cStringLength]);
|
||||
if (maxLength < aRange.length)
|
||||
{
|
||||
len = maxLength;
|
||||
|
@ -1904,7 +1906,7 @@ else
|
|||
}
|
||||
|
||||
/* Returns a new string with the path component given in aString
|
||||
appended to the receiver. Raises an exception if aString contains
|
||||
appended to the receiver. Raises an exception if aString starts with
|
||||
a '/'. Checks the receiver to see if the last letter is a '/', if it
|
||||
is not, a '/' is appended before appending aString */
|
||||
- (NSString*) stringByAppendingPathComponent: (NSString*)aString
|
||||
|
@ -1916,7 +1918,7 @@ else
|
|||
return [[self copy] autorelease];
|
||||
|
||||
range = [aString rangeOfString:@"/"];
|
||||
if (range.length != 0)
|
||||
if (range.length != 0 && range.location == 0)
|
||||
[NSException raise: NSGenericException
|
||||
format: @"attempt to append illegal path component"];
|
||||
|
||||
|
@ -1931,7 +1933,7 @@ else
|
|||
}
|
||||
|
||||
/* Returns a new string with the path extension given in aString
|
||||
appended to the receiver. Raises an exception if aString contains
|
||||
appended to the receiver. Raises an exception if aString starts with
|
||||
a '.'. Checks the receiver to see if the last letter is a '.', if it
|
||||
is not, a '.' is appended before appending aString */
|
||||
- (NSString*) stringByAppendingPathExtension: (NSString*)aString
|
||||
|
@ -1943,7 +1945,7 @@ else
|
|||
return [[self copy] autorelease];
|
||||
|
||||
range = [aString rangeOfString:@"."];
|
||||
if (range.length != 0)
|
||||
if (range.length != 0 && range.location == 0)
|
||||
[NSException raise: NSGenericException
|
||||
format: @"attempt to append illegal path extension"];
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <gnustep/base/preface.h>
|
||||
#include <Foundation/NSConcreteValue.h>
|
||||
#include <Foundation/NSCoder.h>
|
||||
#include <Foundation/NSDictionary.h>
|
||||
|
||||
/* NSValueDecoder is a Class whose only purpose is to decode coded NSValue
|
||||
objects. The only method(s) that should ever be called are +newWithCoder:
|
||||
|
@ -160,6 +161,40 @@
|
|||
autorelease];
|
||||
}
|
||||
|
||||
+ valueFromString: (NSString *)string
|
||||
{
|
||||
NSDictionary *dict = [string propertyList];
|
||||
if (!dict)
|
||||
return nil;
|
||||
|
||||
if ([dict objectForKey: @"width"] && [dict objectForKey: @"x"])
|
||||
{
|
||||
NSRect rect;
|
||||
rect = NSMakeRect([[dict objectForKey: @"x"] floatValue],
|
||||
[[dict objectForKey: @"y"] floatValue],
|
||||
[[dict objectForKey: @"width"] floatValue],
|
||||
[[dict objectForKey: @"height"] floatValue]);
|
||||
return [NSValue valueWithRect: rect];
|
||||
}
|
||||
else if ([dict objectForKey: @"width"])
|
||||
{
|
||||
NSSize size;
|
||||
size = NSMakeSize([[dict objectForKey: @"width"] floatValue],
|
||||
[[dict objectForKey: @"height"] floatValue]);
|
||||
return [NSValue valueWithSize: size];
|
||||
}
|
||||
else if ([dict objectForKey: @"x"])
|
||||
{
|
||||
NSPoint point;
|
||||
point = NSMakePoint([[dict objectForKey: @"x"] floatValue],
|
||||
[[dict objectForKey: @"y"] floatValue]);
|
||||
return [NSValue valueWithPoint: point];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Accessing Data
|
||||
/* All the rest of these methods must be implemented by a subclass */
|
||||
- (void)getValue:(void *)value
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue