mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Move more additional methods to the Additions libtrary.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@16299 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
21b9c31602
commit
e596a161f2
16 changed files with 511 additions and 258 deletions
15
ChangeLog
15
ChangeLog
|
@ -1,3 +1,18 @@
|
|||
2003-03-30 Adam Fedor <fedor@gnu.org>
|
||||
|
||||
* Headers/gnustep/base/NSString.h: (stringByTrimmingLeadSpaces,
|
||||
stringByTrimmingTailSpaces, stringByTrimmingSpaces,
|
||||
stringByReplacingString:withString:, replaceString:withString:,
|
||||
trimLeadSpaces, trimTailSpaces, trimSpaces): Move to GSCategories.h
|
||||
* Headers/gnustep/base/NSValue.h (valueFromString): Idem.
|
||||
* Source/NSNumber.m (valueFromString:): Move to GSCategories.m
|
||||
* Source/NSString.m: Idem as above.
|
||||
* Source/Additions/GSCategories.m: Methods moved here.
|
||||
* Source/Additions/GSCompatibility.h: Rearrange, add
|
||||
NSDistantObject, NSFileHandle category, GSCurrentThreadDictionary().
|
||||
* Source/Additions/GSCompatibility.m: Add GSCurrentThreadDictionary
|
||||
NSDistantObject, and NSFileHandle methods.
|
||||
|
||||
2003-03-28 20:48 Alexander Malmberg <alexander@malmberg.org>
|
||||
|
||||
* configure.ac: Fail the configure if neither ffcall nor ffi is
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include <Foundation/NSCalendarDate.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
#else
|
||||
#include <Foundation/Foundation.h>
|
||||
#endif
|
||||
|
@ -53,11 +54,25 @@
|
|||
@interface NSString (GSCategories)
|
||||
- (NSString*) stringByDeletingPrefix: (NSString*)prefix;
|
||||
- (NSString*) stringByDeletingSuffix: (NSString*)suffix;
|
||||
- (NSString*) stringByTrimmingLeadSpaces;
|
||||
- (NSString*) stringByTrimmingTailSpaces;
|
||||
- (NSString*) stringByTrimmingSpaces;
|
||||
- (NSString*) stringByReplacingString: (NSString*)replace
|
||||
withString: (NSString*)by;
|
||||
@end
|
||||
|
||||
@interface NSMutableString (GSCategories)
|
||||
- (void) deleteSuffix: (NSString*)suffix;
|
||||
- (void) deletePrefix: (NSString*)prefix;
|
||||
- (void) replaceString: (NSString*)replace
|
||||
withString: (NSString*)by;
|
||||
- (void) trimLeadSpaces;
|
||||
- (void) trimTailSpaces;
|
||||
- (void) trimSpaces;
|
||||
@end
|
||||
|
||||
@interface NSNumber(GSCategories)
|
||||
+ (NSValue*) valueFromString: (NSString *)string;
|
||||
@end
|
||||
|
||||
/* This is also defined in NSObject.h, but added here for use with the
|
||||
|
|
|
@ -366,21 +366,8 @@ extern struct objc_class _NSConstantStringClassReference;
|
|||
|
||||
#ifndef NO_GNUSTEP
|
||||
|
||||
@interface NSString (GNUstep)
|
||||
- (NSString*) stringByReplacingString: (NSString*)replace
|
||||
withString: (NSString*)by;
|
||||
- (NSString*) stringByTrimmingLeadSpaces;
|
||||
- (NSString*) stringByTrimmingTailSpaces;
|
||||
- (NSString*) stringByTrimmingSpaces;
|
||||
@end
|
||||
|
||||
@interface NSMutableString (GNUstep)
|
||||
- (NSString*) immutableProxy;
|
||||
- (void) replaceString: (NSString*)replace
|
||||
withString: (NSString*)by;
|
||||
- (void) trimLeadSpaces;
|
||||
- (void) trimTailSpaces;
|
||||
- (void) trimSpaces;
|
||||
@end
|
||||
#endif /* NO_GNUSTEP */
|
||||
|
||||
|
|
|
@ -43,7 +43,6 @@
|
|||
|
||||
#ifndef STRICT_OPENSTEP
|
||||
+ (NSValue*) valueWithBytes: (const void*)value objCType: (const char*)type;
|
||||
+ (NSValue*) valueFromString: (NSString*)string;
|
||||
/* Designated initializer for all concrete subclasses */
|
||||
- (id) initWithBytes: (const void*)data objCType: (const char*)type;
|
||||
- (BOOL) isEqualToValue: (NSValue*)other;
|
||||
|
|
|
@ -507,6 +507,31 @@ static void MD5Transform (unsigned long buf[4], unsigned long const in[16])
|
|||
|
||||
@end
|
||||
|
||||
/**
|
||||
* GNUstep specific (non-standard) additions to the NSNumber class.
|
||||
*/
|
||||
@implementation NSNumber(GSCategories)
|
||||
|
||||
+ (NSValue*) 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];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Extension methods for the NSObject class
|
||||
*/
|
||||
|
@ -579,8 +604,8 @@ static void MD5Transform (unsigned long buf[4], unsigned long const in[16])
|
|||
|
||||
@end
|
||||
|
||||
/**
|
||||
* Extension methods for the NSObject class
|
||||
/**
|
||||
* GNUstep specific (non-standard) additions to the NSString class.
|
||||
*/
|
||||
@implementation NSString (GSCategories)
|
||||
|
||||
|
@ -606,8 +631,139 @@ static void MD5Transform (unsigned long buf[4], unsigned long const in[16])
|
|||
return [self substringToIndex: ([self length] - [suffix length])];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string formed by removing leading white space from the
|
||||
* receiver.
|
||||
*/
|
||||
- (NSString*) stringByTrimmingLeadSpaces
|
||||
{
|
||||
unsigned length = [self length];
|
||||
|
||||
if (length > 0)
|
||||
{
|
||||
unsigned start = 0;
|
||||
unichar (*caiImp)(NSString*, SEL, unsigned int);
|
||||
SEL caiSel = @selector(characterAtIndex:);
|
||||
|
||||
caiImp = (unichar (*)())[self methodForSelector: caiSel];
|
||||
while (start < length && isspace((*caiImp)(self, caiSel, start)))
|
||||
{
|
||||
start++;
|
||||
}
|
||||
if (start > 0)
|
||||
{
|
||||
return [self substringFromIndex: start];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string formed by removing trailing white space from the
|
||||
* receiver.
|
||||
*/
|
||||
- (NSString*) stringByTrimmingTailSpaces
|
||||
{
|
||||
unsigned length = [self length];
|
||||
|
||||
if (length > 0)
|
||||
{
|
||||
unsigned end = length;
|
||||
unichar (*caiImp)(NSString*, SEL, unsigned int);
|
||||
SEL caiSel = @selector(characterAtIndex:);
|
||||
|
||||
caiImp = (unichar (*)())[self methodForSelector: caiSel];
|
||||
while (end > 0)
|
||||
{
|
||||
if (!isspace((*caiImp)(self, caiSel, end - 1)))
|
||||
{
|
||||
break;
|
||||
}
|
||||
end--;
|
||||
}
|
||||
if (end < length)
|
||||
{
|
||||
return [self substringToIndex: end];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string formed by removing both leading and trailing
|
||||
* white space from the receiver.
|
||||
*/
|
||||
- (NSString*) stringByTrimmingSpaces
|
||||
{
|
||||
unsigned length = [self length];
|
||||
|
||||
if (length > 0)
|
||||
{
|
||||
unsigned start = 0;
|
||||
unsigned end = length;
|
||||
unichar (*caiImp)(NSString*, SEL, unsigned int);
|
||||
SEL caiSel = @selector(characterAtIndex:);
|
||||
|
||||
caiImp = (unichar (*)())[self methodForSelector: caiSel];
|
||||
while (start < length && isspace((*caiImp)(self, caiSel, start)))
|
||||
{
|
||||
start++;
|
||||
}
|
||||
while (end > start)
|
||||
{
|
||||
if (!isspace((*caiImp)(self, caiSel, end - 1)))
|
||||
{
|
||||
break;
|
||||
}
|
||||
end--;
|
||||
}
|
||||
if (start > 0 || end < length)
|
||||
{
|
||||
if (start < end)
|
||||
{
|
||||
return [self substringFromRange:
|
||||
NSMakeRange(start, end - start)];
|
||||
}
|
||||
else
|
||||
{
|
||||
return [NSString string];
|
||||
}
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string in which any (and all) occurrances of
|
||||
* replace in the receiver have been replaced with by.
|
||||
* Returns the receiver if replace
|
||||
* does not occur within the receiver. NB. an empty string is
|
||||
* not considered to exist within the receiver.
|
||||
*/
|
||||
- (NSString*) stringByReplacingString: (NSString*)replace
|
||||
withString: (NSString*)by
|
||||
{
|
||||
NSRange range = [self rangeOfString: replace];
|
||||
|
||||
if (range.length > 0)
|
||||
{
|
||||
NSMutableString *tmp = [self mutableCopy];
|
||||
NSString *str;
|
||||
|
||||
[tmp replaceString: replace withString: by];
|
||||
str = AUTORELEASE([tmp copy]);
|
||||
RELEASE(tmp);
|
||||
return str;
|
||||
}
|
||||
else
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
* GNUstep specific (non-standard) additions to the NSMutableString class.
|
||||
*/
|
||||
@implementation NSMutableString (GSCategories)
|
||||
|
||||
/**
|
||||
|
@ -633,4 +789,81 @@ static void MD5Transform (unsigned long buf[4], unsigned long const in[16])
|
|||
[self deleteCharactersInRange: NSMakeRange(0, [prefix length])];
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces all occurrances of the string replace with the string by
|
||||
* in the receiver.<br />
|
||||
* Has no effect if replace does not occur within the
|
||||
* receiver. NB. an empty string is not considered to exist within
|
||||
* the receiver.<br />
|
||||
* Calls - replaceOccurrencesOfString:withString:options:range: passing
|
||||
* zero for the options and a range from 0 with the length of the receiver.
|
||||
*/
|
||||
- (void) replaceString: (NSString*)replace
|
||||
withString: (NSString*)by
|
||||
{
|
||||
[self replaceOccurrencesOfString: replace
|
||||
withString: by
|
||||
options: 0
|
||||
range: NSMakeRange(0, [self length])];
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all leading white space from the receiver.
|
||||
*/
|
||||
- (void) trimLeadSpaces
|
||||
{
|
||||
unsigned length = [self length];
|
||||
|
||||
if (length > 0)
|
||||
{
|
||||
unsigned start = 0;
|
||||
unichar (*caiImp)(NSString*, SEL, unsigned int);
|
||||
SEL caiSel = @selector(characterAtIndex:);
|
||||
|
||||
caiImp = (unichar (*)())[self methodForSelector: caiSel];
|
||||
while (start < length && isspace((*caiImp)(self, caiSel, start)))
|
||||
{
|
||||
start++;
|
||||
}
|
||||
if (start > 0)
|
||||
{
|
||||
[self deleteCharactersInRange: NSMakeRange(0, start)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all trailing white space from the receiver.
|
||||
*/
|
||||
- (void) trimTailSpaces
|
||||
{
|
||||
unsigned length = [self length];
|
||||
|
||||
if (length > 0)
|
||||
{
|
||||
unsigned end = length;
|
||||
unichar (*caiImp)(NSString*, SEL, unsigned int);
|
||||
SEL caiSel = @selector(characterAtIndex:);
|
||||
|
||||
caiImp = (unichar (*)())[self methodForSelector: caiSel];
|
||||
while (end > 0 && isspace((*caiImp)(self, caiSel, end - 1)))
|
||||
{
|
||||
end--;
|
||||
}
|
||||
if (end < length)
|
||||
{
|
||||
[self deleteCharactersInRange: NSMakeRange(end, length - end)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all leading or trailing white space from the receiver.
|
||||
*/
|
||||
- (void) trimSpaces
|
||||
{
|
||||
[self trimTailSpaces];
|
||||
[self trimLeadSpaces];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -35,6 +35,10 @@
|
|||
|
||||
@class NSMutableSet;
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* Macros
|
||||
*/
|
||||
|
||||
// Following are also defined in gnustep-base/Headers/gnustep/base/NSObject.h
|
||||
#define IF_NO_GC(x) \
|
||||
x
|
||||
|
@ -110,8 +114,6 @@
|
|||
format: @"in %s, range { %u, %u } extends beyond size (%u)", \
|
||||
sel_get_name(_cmd), RANGE.location, RANGE.length, SIZE]
|
||||
|
||||
GS_EXPORT NSRecursiveLock *gnustep_global_lock;
|
||||
|
||||
/* Taken from gnustep-base/Headers/gnustep/base/NSString.h */
|
||||
typedef enum _NSGNUstepStringEncoding
|
||||
{
|
||||
|
@ -143,20 +145,41 @@ typedef enum _NSGNUstepStringEncoding
|
|||
NSBIG5StringEncoding // Traditional chinese
|
||||
} NSGNUstepStringEncoding;
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* Variables
|
||||
*/
|
||||
GS_EXPORT NSRecursiveLock *gnustep_global_lock;
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* Class/Method Extensions
|
||||
*/
|
||||
|
||||
@interface NSObject(GSCompatibility)
|
||||
+ (id) notImplemented:(SEL)selector;
|
||||
- (BOOL) isInstance;
|
||||
@end
|
||||
|
||||
@interface NSArray (GSCompatibility)
|
||||
- (id) initWithArray: (NSArray*)array copyItems: (BOOL)shouldCopy;
|
||||
@end
|
||||
|
||||
@interface NSDistantObject (GSCompatibility)
|
||||
+ (void) setDebug: (int)val;
|
||||
@end
|
||||
|
||||
@interface NSFileHandle(GSCompatibility)
|
||||
+ (id) fileHandleAsServerAtAddress: (NSString*)address
|
||||
service: (NSString*)service
|
||||
protocol: (NSString*)protocol;
|
||||
- (NSString*) socketAddress;
|
||||
@end
|
||||
|
||||
// Used only in EOFault.m, -[EOFault forward::], for Object compatibility
|
||||
@interface NSInvocation(GSCompatibility)
|
||||
- (retval_t) returnFrame:(arglist_t)args;
|
||||
- (id) initWithArgframe:(arglist_t)args selector:(SEL)selector;
|
||||
@end
|
||||
|
||||
GS_EXPORT NSArray *NSStandardLibraryPaths();
|
||||
GS_EXPORT NSString *GetEncodingName(NSStringEncoding availableEncodingValue);
|
||||
|
||||
@interface NSString(GSCompatibility)
|
||||
- (BOOL) boolValue;
|
||||
@end
|
||||
|
@ -166,14 +189,18 @@ GS_EXPORT BOOL GSDebugSet(NSString *level);
|
|||
- (NSMutableSet *) debugSet;
|
||||
@end
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
* Functions
|
||||
*/
|
||||
|
||||
GS_EXPORT NSArray *NSStandardLibraryPaths();
|
||||
GS_EXPORT NSString *GetEncodingName(NSStringEncoding availableEncodingValue);
|
||||
|
||||
GS_EXPORT NSMutableDictionary *GSCurrentThreadDictionary();
|
||||
|
||||
GS_EXPORT NSString *GSDebugMethodMsg(id obj, SEL sel, const char *file, int line, NSString *fmt);
|
||||
GS_EXPORT NSString *GSDebugFunctionMsg(const char *func, const char *file, int line, NSString *fmt);
|
||||
|
||||
@interface NSArray (GSCompatibility)
|
||||
- (id) initWithArray: (NSArray*)array copyItems: (BOOL)shouldCopy;
|
||||
@end
|
||||
|
||||
|
||||
#endif /* NexT_FOUNDATION_LIB */
|
||||
|
||||
#endif
|
||||
|
|
|
@ -35,6 +35,11 @@ NSString *GetEncodingName(NSStringEncoding availableEncodingValue)
|
|||
return (NSString *)CFStringGetNameOfEncoding(CFStringConvertNSStringEncodingToEncoding(availableEncodingValue));
|
||||
}
|
||||
|
||||
NSMutableDictionary *GSCurrentThreadDictionary()
|
||||
{
|
||||
return [[NSThread currentThread] threadDictionary];
|
||||
}
|
||||
|
||||
NSArray *NSStandardLibraryPaths()
|
||||
{
|
||||
return NSSearchPathForDirectoriesInDomains(NSAllLibrariesDirectory, NSAllDomainsMask, YES);
|
||||
|
@ -108,6 +113,206 @@ GSDebugFunctionMsg(const char *func, const char *file, int line, NSString *fmt)
|
|||
|
||||
@end
|
||||
|
||||
@interface NSDistantObject (GSCategoriesRevealed)
|
||||
// This method is implemented in MacOS X 10.2.4, but is not public
|
||||
+ (void) _enableLogging:(BOOL)flag;
|
||||
@end
|
||||
|
||||
@implementation NSDistantObject (GSCompatibility)
|
||||
|
||||
+ (void) setDebug: (int)val
|
||||
{
|
||||
if([self respondsToSelector:@selector(_enableLogging:)])
|
||||
[self _enableLogging:!!val];
|
||||
}
|
||||
@end
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@implementation NSFileHandle(GSCompatibility)
|
||||
// From GSFileHandle.m
|
||||
|
||||
static BOOL
|
||||
getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
||||
{
|
||||
const char *proto = "tcp";
|
||||
struct servent *sp;
|
||||
|
||||
if (pcl)
|
||||
{
|
||||
proto = [pcl lossyCString];
|
||||
}
|
||||
memset(sin, '\0', sizeof(*sin));
|
||||
sin->sin_family = AF_INET;
|
||||
|
||||
/*
|
||||
* If we were given a hostname, we use any address for that host.
|
||||
* Otherwise we expect the given name to be an address unless it is
|
||||
* a null (any address).
|
||||
*/
|
||||
if (name)
|
||||
{
|
||||
NSHost* host = [NSHost hostWithName: name];
|
||||
|
||||
if (host != nil)
|
||||
{
|
||||
name = [host address];
|
||||
}
|
||||
#ifndef HAVE_INET_ATON
|
||||
sin->sin_addr.s_addr = inet_addr([name lossyCString]);
|
||||
if (sin->sin_addr.s_addr == INADDR_NONE)
|
||||
#else
|
||||
if (inet_aton([name lossyCString], &sin->sin_addr) == 0)
|
||||
#endif
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sin->sin_addr.s_addr = NSSwapHostIntToBig(INADDR_ANY);
|
||||
}
|
||||
if (svc == nil)
|
||||
{
|
||||
sin->sin_port = 0;
|
||||
return YES;
|
||||
}
|
||||
else if ((sp = getservbyname([svc lossyCString], proto)) == 0)
|
||||
{
|
||||
const char* ptr = [svc lossyCString];
|
||||
int val = atoi(ptr);
|
||||
|
||||
while (isdigit(*ptr))
|
||||
{
|
||||
ptr++;
|
||||
}
|
||||
if (*ptr == '\0' && val <= 0xffff)
|
||||
{
|
||||
unsigned short v = val;
|
||||
|
||||
sin->sin_port = NSSwapHostShortToBig(v);
|
||||
return YES;
|
||||
}
|
||||
else if (strcmp(ptr, "gdomap") == 0)
|
||||
{
|
||||
unsigned short v;
|
||||
#ifdef GDOMAP_PORT_OVERRIDE
|
||||
v = GDOMAP_PORT_OVERRIDE;
|
||||
#else
|
||||
v = 538; // IANA allocated port
|
||||
#endif
|
||||
sin->sin_port = NSSwapHostShortToBig(v);
|
||||
return YES;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sin->sin_port = sp->s_port;
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
|
||||
- (id) initAsServerAtAddress: (NSString*)a
|
||||
service: (NSString*)s
|
||||
protocol: (NSString*)p
|
||||
{
|
||||
#ifndef BROKEN_SO_REUSEADDR
|
||||
int status = 1;
|
||||
#endif
|
||||
int net;
|
||||
struct sockaddr_in sin;
|
||||
int size = sizeof(sin);
|
||||
|
||||
if (getAddr(a, s, p, &sin) == NO)
|
||||
{
|
||||
RELEASE(self);
|
||||
NSLog(@"bad address-service-protocol combination");
|
||||
return nil;
|
||||
}
|
||||
|
||||
if ((net = socket(AF_INET, SOCK_STREAM, PF_UNSPEC)) < 0)
|
||||
{
|
||||
NSLog(@"unable to create socket - %s", GSLastErrorStr(errno));
|
||||
RELEASE(self);
|
||||
return nil;
|
||||
}
|
||||
|
||||
#ifndef BROKEN_SO_REUSEADDR
|
||||
/*
|
||||
* Under decent systems, SO_REUSEADDR means that the port can be reused
|
||||
* immediately that this process exits. Under some it means
|
||||
* that multiple processes can serve the same port simultaneously.
|
||||
* We don't want that broken behavior!
|
||||
*/
|
||||
setsockopt(net, SOL_SOCKET, SO_REUSEADDR, (char *)&status, sizeof(status));
|
||||
#endif
|
||||
|
||||
if (bind(net, (struct sockaddr *)&sin, sizeof(sin)) < 0)
|
||||
{
|
||||
NSLog(@"unable to bind to port %s:%d - %s", inet_ntoa(sin.sin_addr),
|
||||
NSSwapBigShortToHost(sin.sin_port), GSLastErrorStr(errno));
|
||||
(void) close(net);
|
||||
RELEASE(self);
|
||||
return nil;
|
||||
}
|
||||
|
||||
if (listen(net, 5) < 0)
|
||||
{
|
||||
NSLog(@"unable to listen on port - %s", GSLastErrorStr(errno));
|
||||
(void) close(net);
|
||||
RELEASE(self);
|
||||
return nil;
|
||||
}
|
||||
|
||||
if (getsockname(net, (struct sockaddr*)&sin, &size) < 0)
|
||||
{
|
||||
NSLog(@"unable to get socket name - %s", GSLastErrorStr(errno));
|
||||
(void) close(net);
|
||||
RELEASE(self);
|
||||
return nil;
|
||||
}
|
||||
|
||||
self = [self initWithFileDescriptor: net closeOnDealloc: YES];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (id) fileHandleAsServerAtAddress: (NSString*)address
|
||||
service: (NSString*)service
|
||||
protocol: (NSString*)protocol
|
||||
{
|
||||
id o = [self allocWithZone: NSDefaultMallocZone()];
|
||||
|
||||
return AUTORELEASE([o initAsServerAtAddress: address
|
||||
service: service
|
||||
protocol: protocol]);
|
||||
}
|
||||
|
||||
- (NSString*) socketAddress
|
||||
{
|
||||
struct sockaddr_in sin;
|
||||
int size = sizeof(sin);
|
||||
|
||||
if (getsockname([self fileDescriptor], (struct sockaddr*)&sin, &size) < 0)
|
||||
{
|
||||
NSLog(@"unable to get socket name - %s", GSLastErrorStr(errno));
|
||||
return nil;
|
||||
}
|
||||
|
||||
return [[[NSString alloc] initWithCString: (char*)inet_ntoa(sin.sin_addr)]
|
||||
autorelease];
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSProcessInfo(GSCompatibility)
|
||||
|
||||
static NSMutableSet *_debug_set = nil;
|
||||
|
|
|
@ -468,22 +468,6 @@ static Class doubleNumberClass;
|
|||
return AUTORELEASE(theObj);
|
||||
}
|
||||
|
||||
+ (NSValue*) 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];
|
||||
}
|
||||
|
||||
/*
|
||||
* A moderately sane default init method - a zero value integer.
|
||||
*/
|
||||
|
|
|
@ -83,6 +83,7 @@
|
|||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <Foundation/NSHost.h>
|
||||
#include <Foundation/NSLock.h>
|
||||
#include "gnustep/base/GSCategories.h"
|
||||
|
||||
#include "GSPrivate.h"
|
||||
|
||||
|
|
|
@ -4318,139 +4318,6 @@ handle_printf_atsign (FILE *stream,
|
|||
@end
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* GNUstep specific (non-standard) additions to the NSString class.
|
||||
* The methods in this category are not available in MacOS-X
|
||||
*/
|
||||
@implementation NSString (GNUstep)
|
||||
/**
|
||||
* Returns a string formed by removing leading white space from the
|
||||
* receiver.
|
||||
*/
|
||||
- (NSString*) stringByTrimmingLeadSpaces
|
||||
{
|
||||
unsigned length = [self length];
|
||||
|
||||
if (length > 0)
|
||||
{
|
||||
unsigned start = 0;
|
||||
unichar (*caiImp)(NSString*, SEL, unsigned int);
|
||||
|
||||
caiImp = (unichar (*)())[self methodForSelector: caiSel];
|
||||
while (start < length && isspace((*caiImp)(self, caiSel, start)))
|
||||
{
|
||||
start++;
|
||||
}
|
||||
if (start > 0)
|
||||
{
|
||||
return [self substringFromIndex: start];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string formed by removing trailing white space from the
|
||||
* receiver.
|
||||
*/
|
||||
- (NSString*) stringByTrimmingTailSpaces
|
||||
{
|
||||
unsigned length = [self length];
|
||||
|
||||
if (length > 0)
|
||||
{
|
||||
unsigned end = length;
|
||||
unichar (*caiImp)(NSString*, SEL, unsigned int);
|
||||
|
||||
caiImp = (unichar (*)())[self methodForSelector: caiSel];
|
||||
while (end > 0)
|
||||
{
|
||||
if (!isspace((*caiImp)(self, caiSel, end - 1)))
|
||||
{
|
||||
break;
|
||||
}
|
||||
end--;
|
||||
}
|
||||
if (end < length)
|
||||
{
|
||||
return [self substringToIndex: end];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string formed by removing both leading and trailing
|
||||
* white space from the receiver.
|
||||
*/
|
||||
- (NSString*) stringByTrimmingSpaces
|
||||
{
|
||||
unsigned length = [self length];
|
||||
|
||||
if (length > 0)
|
||||
{
|
||||
unsigned start = 0;
|
||||
unsigned end = length;
|
||||
unichar (*caiImp)(NSString*, SEL, unsigned int);
|
||||
|
||||
caiImp = (unichar (*)())[self methodForSelector: caiSel];
|
||||
while (start < length && isspace((*caiImp)(self, caiSel, start)))
|
||||
{
|
||||
start++;
|
||||
}
|
||||
while (end > start)
|
||||
{
|
||||
if (!isspace((*caiImp)(self, caiSel, end - 1)))
|
||||
{
|
||||
break;
|
||||
}
|
||||
end--;
|
||||
}
|
||||
if (start > 0 || end < length)
|
||||
{
|
||||
if (start < end)
|
||||
{
|
||||
return [self substringFromRange:
|
||||
NSMakeRange(start, end - start)];
|
||||
}
|
||||
else
|
||||
{
|
||||
return [NSStringClass string];
|
||||
}
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string in which any (and all) occurrances of
|
||||
* replace in the receiver have been replaced with by.
|
||||
* Returns the receiver if replace
|
||||
* does not occur within the receiver. NB. an empty string is
|
||||
* not considered to exist within the receiver.
|
||||
*/
|
||||
- (NSString*) stringByReplacingString: (NSString*)replace
|
||||
withString: (NSString*)by
|
||||
{
|
||||
NSRange range = [self rangeOfString: replace];
|
||||
|
||||
if (range.length > 0)
|
||||
{
|
||||
NSMutableString *tmp = [self mutableCopy];
|
||||
NSString *str;
|
||||
|
||||
[tmp replaceString: replace withString: by];
|
||||
str = AUTORELEASE([tmp copy]);
|
||||
RELEASE(tmp);
|
||||
return str;
|
||||
}
|
||||
else
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
* GNUstep specific (non-standard) additions to the NSMutableString class.
|
||||
* The methods in this category are not available in MacOS-X
|
||||
|
@ -4478,81 +4345,6 @@ handle_printf_atsign (FILE *stream,
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces all occurrances of the string replace with the string by
|
||||
* in the receiver.<br />
|
||||
* Has no effect if replace does not occur within the
|
||||
* receiver. NB. an empty string is not considered to exist within
|
||||
* the receiver.<br />
|
||||
* Calls - replaceOccurrencesOfString:withString:options:range: passing
|
||||
* zero for the options and a range from 0 with the length of the receiver.
|
||||
*/
|
||||
- (void) replaceString: (NSString*)replace
|
||||
withString: (NSString*)by
|
||||
{
|
||||
[self replaceOccurrencesOfString: replace
|
||||
withString: by
|
||||
options: 0
|
||||
range: NSMakeRange(0, [self length])];
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all leading white space from the receiver.
|
||||
*/
|
||||
- (void) trimLeadSpaces
|
||||
{
|
||||
unsigned length = [self length];
|
||||
|
||||
if (length > 0)
|
||||
{
|
||||
unsigned start = 0;
|
||||
unichar (*caiImp)(NSString*, SEL, unsigned int);
|
||||
|
||||
caiImp = (unichar (*)())[self methodForSelector: caiSel];
|
||||
while (start < length && isspace((*caiImp)(self, caiSel, start)))
|
||||
{
|
||||
start++;
|
||||
}
|
||||
if (start > 0)
|
||||
{
|
||||
[self deleteCharactersInRange: NSMakeRange(0, start)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all trailing white space from the receiver.
|
||||
*/
|
||||
- (void) trimTailSpaces
|
||||
{
|
||||
unsigned length = [self length];
|
||||
|
||||
if (length > 0)
|
||||
{
|
||||
unsigned end = length;
|
||||
unichar (*caiImp)(NSString*, SEL, unsigned int);
|
||||
|
||||
caiImp = (unichar (*)())[self methodForSelector: caiSel];
|
||||
while (end > 0 && isspace((*caiImp)(self, caiSel, end - 1)))
|
||||
{
|
||||
end--;
|
||||
}
|
||||
if (end < length)
|
||||
{
|
||||
[self deleteCharactersInRange: NSMakeRange(end, length - end)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all leading or trailing white space from the receiver.
|
||||
*/
|
||||
- (void) trimSpaces
|
||||
{
|
||||
[self trimTailSpaces];
|
||||
[self trimLeadSpaces];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
|
|
@ -75,8 +75,10 @@
|
|||
#include <Foundation/NSTimeZone.h>
|
||||
#include <Foundation/NSByteOrder.h>
|
||||
#include <Foundation/NSDebug.h>
|
||||
#include "gnustep/base/GSCategories.h"
|
||||
#include <GSConfig.h>
|
||||
|
||||
|
||||
#define NOID
|
||||
#include "tzfile.h"
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include <Foundation/NSValue.h>
|
||||
#include <Foundation/NSLock.h>
|
||||
#include <Foundation/NSUserDefaults.h>
|
||||
#include "gnustep/base/GSCategories.h"
|
||||
|
||||
#include "GSPrivate.h"
|
||||
|
||||
|
|
|
@ -23,10 +23,8 @@
|
|||
#include <Foundation/Foundation.h>
|
||||
#include "AGSHtml.h"
|
||||
#include "gnustep/base/GNUstep.h"
|
||||
#ifdef NeXT_Foundation_LIBRARY
|
||||
#include "gnustep/base/GSCategories.h"
|
||||
#include "gnustep/base/GSCompatibility.h"
|
||||
#endif
|
||||
|
||||
static int XML_ELEMENT_NODE;
|
||||
static int XML_ENTITY_REF_NODE;
|
||||
|
|
|
@ -23,10 +23,8 @@
|
|||
#include <Foundation/Foundation.h>
|
||||
#include "AGSIndex.h"
|
||||
#include "gnustep/base/GNUstep.h"
|
||||
#ifdef NeXT_Foundation_LIBRARY
|
||||
#include "gnustep/base/GSCategories.h"
|
||||
#include "gnustep/base/GSCompatibility.h"
|
||||
#endif
|
||||
|
||||
static int XML_ELEMENT_NODE;
|
||||
static int XML_TEXT_NODE;
|
||||
|
|
|
@ -22,9 +22,7 @@
|
|||
|
||||
#include "AGSOutput.h"
|
||||
#include "gnustep/base/GNUstep.h"
|
||||
#ifdef NeXT_Foundation_LIBRARY
|
||||
#include "gnustep/base/GSCategories.h"
|
||||
#endif
|
||||
|
||||
@interface AGSOutput (Private)
|
||||
- (NSString*) mergeMarkup: (NSString*)markup
|
||||
|
|
|
@ -22,9 +22,7 @@
|
|||
|
||||
#include "AGSParser.h"
|
||||
#include "gnustep/base/GNUstep.h"
|
||||
#ifdef NeXT_Foundation_LIBRARY
|
||||
#include "gnustep/base/GSCategories.h"
|
||||
#endif
|
||||
|
||||
@implementation AGSParser
|
||||
|
||||
|
|
Loading…
Reference in a new issue