mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 09:04:13 +00:00
Added code from baseline.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/branches/NibCompatibility@22951 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
8fe86ac8e1
commit
057b19f761
17 changed files with 663 additions and 996 deletions
54
ChangeLog
54
ChangeLog
|
@ -1,3 +1,57 @@
|
|||
2006-05-20 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
Revert last changes ... passed regression tests but broke some
|
||||
software :-(
|
||||
|
||||
2006-05-20 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/GSString.m:
|
||||
* Source/NSSerializer.m:
|
||||
Commit more string tidyups and simplifications made while I was
|
||||
travelling. Changed private internal string subclasses so that
|
||||
they can't be re-initialised ... all instances are initialised
|
||||
'manually' rather than through a method that could be called by
|
||||
other code outside this file ... thus all initialisation by external
|
||||
code goes through ([-initWithBytesNoCopy:length:encoding:shouldFree])
|
||||
method of the placeholder string.
|
||||
|
||||
2006-05-15 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/GSHTTPURLHandle.m: Fix error when parsing response with no
|
||||
content.
|
||||
* Source/NSPredicate.m: Revert to previous version as last change
|
||||
contained broken code and wouldn't compile.
|
||||
* Source/NSKeyValueCoding.m:
|
||||
* Source/GSArray.m:
|
||||
* Source/GSFFCallInvocation.m:
|
||||
* Source/NSInvocation.m:
|
||||
* Source/NSCoder.m:
|
||||
* Source/NSObject.m:
|
||||
* Source/Additions/GSCategories.m:
|
||||
* Headers/Foundation/NSLock.h:
|
||||
* Tools/AGSHtml.m:
|
||||
* Tools/autogsdoc.m:
|
||||
Use casts to avoid spurious warnings from gcc-4.1
|
||||
|
||||
2006-05-15 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Source/NSPredicate.m:
|
||||
Extracted all the parsing into a speparate class
|
||||
GSPredicateScanner. This change is based on code by Nikolaus
|
||||
Schaller <hns@computer.org>, but extends this.
|
||||
|
||||
2006-05-14 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSString.m:
|
||||
* Source/GSString.m:
|
||||
Change to use ([initWithBytesNoCopy:length:encoding:freeWhenDone:])
|
||||
as the primary/designated initialiser for strings and update code
|
||||
to fix character encoding errors when copying mutable strings in
|
||||
a UTF8 locale (ie where the internal encoding for 8bit strings is
|
||||
not the same as the external encoding).
|
||||
WARNING ... this is a restructuring of functionality which is core
|
||||
to the library. Please use with care and report any bugs found.
|
||||
|
||||
2006-05-12 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/GSString.m: validate UTF-16 data when producing a Cstring
|
||||
|
|
|
@ -222,7 +222,7 @@
|
|||
* </example>
|
||||
*/
|
||||
#define GS_INITIALIZED_LOCK(IDENT,CLASSNAME) \
|
||||
(IDENT != nil ? IDENT : [CLASSNAME newLockAt: &IDENT])
|
||||
(IDENT != nil ? (id)IDENT : (id)[CLASSNAME newLockAt: &IDENT])
|
||||
|
||||
/**
|
||||
* Defines the <code>newLockAt:</code> method.
|
||||
|
|
|
@ -193,7 +193,7 @@ enum {
|
|||
- (id) initWithBytes: (const void*)bytes
|
||||
length: (unsigned int)length
|
||||
encoding: (NSStringEncoding)encoding;
|
||||
- (id) initWithBytesNoCopy: (const void*)bytes
|
||||
- (id) initWithBytesNoCopy: (void*)bytes
|
||||
length: (unsigned int)length
|
||||
encoding: (NSStringEncoding)encoding
|
||||
freeWhenDone: (BOOL)flag;
|
||||
|
|
|
@ -992,7 +992,7 @@ static void MD5Transform (uint32_t buf[4], uint32_t const in[16])
|
|||
* Ordering objects by their address is pretty useless,
|
||||
* so subclasses should override this is some useful way.
|
||||
*/
|
||||
if (self > anObject)
|
||||
if ((id)self > anObject)
|
||||
{
|
||||
return NSOrderedDescending;
|
||||
}
|
||||
|
|
|
@ -329,7 +329,7 @@ static void GSSetupEncodingTable(void)
|
|||
}
|
||||
}
|
||||
|
||||
static BOOL GSEncodingSupported(NSStringEncoding enc)
|
||||
BOOL GSEncodingSupported(NSStringEncoding enc)
|
||||
{
|
||||
GSSetupEncodingTable();
|
||||
|
||||
|
|
|
@ -19,7 +19,8 @@
|
|||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
|
||||
$Date$ $Revision$
|
||||
*/
|
||||
|
@ -121,9 +122,9 @@ static Class GSInlineArrayClass;
|
|||
|
||||
+ (id) allocWithZone: (NSZone*)zone
|
||||
{
|
||||
GSArray *array = NSAllocateObject(self, 0, zone);
|
||||
GSArray *array = (GSArray*)NSAllocateObject(self, 0, zone);
|
||||
|
||||
return array;
|
||||
return (id)array;
|
||||
}
|
||||
|
||||
- (id) copyWithZone: (NSZone*)zone
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
#include "Foundation/NSException.h"
|
||||
#include "Foundation/NSCoder.h"
|
||||
|
@ -684,8 +685,8 @@ GSFFCallInvokeWithTargetAndImp(NSInvocation *_inv, id anObject, IMP imp)
|
|||
{
|
||||
GSMethod method;
|
||||
method = GSGetMethod((GSObjCIsInstance(_target)
|
||||
? GSObjCClass(_target)
|
||||
: _target),
|
||||
? (id)GSObjCClass(_target)
|
||||
: (id)_target),
|
||||
_selector,
|
||||
GSObjCIsInstance(_target),
|
||||
YES);
|
||||
|
|
|
@ -477,6 +477,7 @@ static void debugWrite(GSHTTPURLHandle *handle, NSData *data)
|
|||
NSDictionary *dict = [not userInfo];
|
||||
NSData *d;
|
||||
NSRange r;
|
||||
BOOL complete;
|
||||
|
||||
RETAIN(self);
|
||||
|
||||
|
@ -502,7 +503,7 @@ static void debugWrite(GSHTTPURLHandle *handle, NSData *data)
|
|||
[sock closeFile];
|
||||
DESTROY(sock);
|
||||
}
|
||||
else if ([parser parse: d] == NO)
|
||||
else if ([parser parse: d] == NO && (complete = [parser isComplete]) == NO)
|
||||
{
|
||||
if (debug == YES)
|
||||
{
|
||||
|
@ -513,8 +514,6 @@ static void debugWrite(GSHTTPURLHandle *handle, NSData *data)
|
|||
}
|
||||
else
|
||||
{
|
||||
BOOL complete = [parser isComplete];
|
||||
|
||||
if (complete == NO && [parser isInHeaders] == NO)
|
||||
{
|
||||
GSMimeHeader *info;
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -261,14 +261,19 @@ static NSString *ExecutablePath()
|
|||
really needs it (So far only needed if using GNU dld library) */
|
||||
#ifdef __MINGW32__
|
||||
const unichar *
|
||||
#else
|
||||
const char *
|
||||
#endif
|
||||
objc_executable_location (void)
|
||||
{
|
||||
return [[ExecutablePath() stringByDeletingLastPathComponent]
|
||||
fileSystemRepresentation];
|
||||
}
|
||||
#else
|
||||
const char *
|
||||
objc_executable_location (void)
|
||||
{
|
||||
return [[ExecutablePath() stringByDeletingLastPathComponent]
|
||||
fileSystemRepresentation];
|
||||
}
|
||||
#endif
|
||||
|
||||
static BOOL
|
||||
bundle_directory_readable(NSString *path)
|
||||
|
|
|
@ -123,8 +123,9 @@
|
|||
|
||||
- (void) encodePropertyList: (id)plist
|
||||
{
|
||||
id anObject = plist ? [NSSerializer serializePropertyList: plist] : nil;
|
||||
id anObject;
|
||||
|
||||
anObject = plist ? (id)[NSSerializer serializePropertyList: plist] : nil;
|
||||
[self encodeValueOfObjCType: @encode(id) at: &anObject];
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,8 @@
|
|||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
|
||||
<title>NSInvocation class reference</title>
|
||||
$Date$ $Revision$
|
||||
|
@ -602,8 +603,8 @@ _arg_addr(NSInvocation *inv, int index)
|
|||
{
|
||||
GSMethod method;
|
||||
method = GSGetMethod((GSObjCIsInstance(_target)
|
||||
? GSObjCClass(_target)
|
||||
: _target),
|
||||
? (id)GSObjCClass(_target)
|
||||
: (id)_target),
|
||||
_selector,
|
||||
GSObjCIsInstance(_target),
|
||||
YES);
|
||||
|
|
|
@ -217,11 +217,9 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
|
|||
- (id) handleQueryWithUnboundKey: (NSString*)aKey
|
||||
{
|
||||
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
self,
|
||||
@"NSTargetObjectUserInfoKey",
|
||||
(aKey ? aKey : @"(nil)"),
|
||||
@"NSUnknownUserInfoKey",
|
||||
nil];
|
||||
self, @"NSTargetObjectUserInfoKey",
|
||||
(aKey ? (id)aKey : (id)@"(nil)"), @"NSUnknownUserInfoKey",
|
||||
nil];
|
||||
NSException *exp = [NSException exceptionWithName: NSUndefinedKeyException
|
||||
reason: @"Unable to find value for key"
|
||||
userInfo: dict];
|
||||
|
@ -235,11 +233,9 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
|
|||
- (void) handleTakeValue: (id)anObject forUnboundKey: (NSString*)aKey
|
||||
{
|
||||
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
(anObject ? anObject : @"(nil)"),
|
||||
@"NSTargetObjectUserInfoKey",
|
||||
(aKey ? aKey : @"(nil)"),
|
||||
@"NSUnknownUserInfoKey",
|
||||
nil];
|
||||
(anObject ? (id)anObject : (id)@"(nil)"), @"NSTargetObjectUserInfoKey",
|
||||
(aKey ? (id)aKey : (id)@"(nil)"), @"NSUnknownUserInfoKey",
|
||||
nil];
|
||||
NSException *exp = [NSException exceptionWithName: NSUndefinedKeyException
|
||||
reason: @"Unable to set value for key"
|
||||
userInfo: dict];
|
||||
|
@ -345,11 +341,9 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
|
|||
}
|
||||
|
||||
dict = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
(anObject ? anObject : @"(nil)"),
|
||||
@"NSTargetObjectUserInfoKey",
|
||||
(aKey ? aKey : @"(nil)"),
|
||||
@"NSUnknownUserInfoKey",
|
||||
nil];
|
||||
(anObject ? (id)anObject : (id)@"(nil)"), @"NSTargetObjectUserInfoKey",
|
||||
(aKey ? (id)aKey : (id)@"(nil)"), @"NSUnknownUserInfoKey",
|
||||
nil];
|
||||
exp = [NSException exceptionWithName: NSInvalidArgumentException
|
||||
reason: @"Unable to set nil value for key"
|
||||
userInfo: dict];
|
||||
|
@ -801,11 +795,9 @@ static id ValueForKey(NSObject *self, const char *key, unsigned size)
|
|||
return [self handleQueryWithUnboundKey: aKey];
|
||||
}
|
||||
dict = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
self,
|
||||
@"NSTargetObjectUserInfoKey",
|
||||
(aKey ? aKey : @"(nil)"),
|
||||
@"NSUnknownUserInfoKey",
|
||||
nil];
|
||||
self, @"NSTargetObjectUserInfoKey",
|
||||
(aKey ? (id)aKey : (id)@"(nil)"), @"NSUnknownUserInfoKey",
|
||||
nil];
|
||||
exp = [NSException exceptionWithName: NSUndefinedKeyException
|
||||
reason: @"Unable to find value for key"
|
||||
userInfo: dict];
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
|
||||
<title>NSObject class reference</title>
|
||||
$Date$ $Revision$
|
||||
|
@ -1388,8 +1389,9 @@ GSDescriptionForClassMethod(pcl self, SEL aSel)
|
|||
format: @"%@ null selector given", NSStringFromSelector(_cmd)];
|
||||
|
||||
mth = GSGetMethod(self, aSelector, YES, YES);
|
||||
return mth ? [NSMethodSignature signatureWithObjCTypes:mth->method_types]
|
||||
: nil;
|
||||
if (mth == 0)
|
||||
return nil;
|
||||
return [NSMethodSignature signatureWithObjCTypes:mth->method_types];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2075,8 +2077,9 @@ GSDescriptionForClassMethod(pcl self, SEL aSel)
|
|||
format: @"%@ null selector given", NSStringFromSelector(_cmd)];
|
||||
|
||||
mth = GSGetMethod(self, aSelector, YES, YES);
|
||||
return mth ? [NSMethodSignature signatureWithObjCTypes:mth->method_types]
|
||||
: nil;
|
||||
if (mth == 0)
|
||||
return nil;
|
||||
return [NSMethodSignature signatureWithObjCTypes:mth->method_types];
|
||||
}
|
||||
|
||||
- (IMP) methodFor: (SEL)aSel
|
||||
|
|
|
@ -819,7 +819,7 @@ handle_printf_atsign (FILE *stream,
|
|||
* <p>In MacOS-X class clusters do not have designated initialisers,
|
||||
* and there is a general rule that -init is treated as the designated
|
||||
* initialiser of the class cluster, but that other intitialisers
|
||||
* may not work s expected an would need to be individually overridden
|
||||
* may not work as expected and would need to be individually overridden
|
||||
* in any subclass.
|
||||
* </p>
|
||||
* <p>GNUstep tries to make it easier to subclass a class cluster,
|
||||
|
@ -838,6 +838,11 @@ handle_printf_atsign (FILE *stream,
|
|||
* <em>all</em> the class cluster initialisers you might use in conjunction
|
||||
* with your subclass.
|
||||
* </p>
|
||||
* <p>NB. The GNUstep designated initialiser for the NSString class cluster
|
||||
* has changed to -initWithBytesNoCopy:length:encoding:freeWhenDone:
|
||||
* from -initWithCharactersNoCopy:length:freeWhenDone: and older code
|
||||
* subclassing NSString will need to be updated.
|
||||
* </p>
|
||||
*/
|
||||
- (id) init
|
||||
{
|
||||
|
@ -859,147 +864,24 @@ handle_printf_atsign (FILE *stream,
|
|||
{
|
||||
if (length == 0)
|
||||
{
|
||||
self = [self initWithCharactersNoCopy: (unichar*)0
|
||||
length: 0
|
||||
freeWhenDone: NO];
|
||||
}
|
||||
else if (_ByteEncodingOk == YES
|
||||
&& (encoding==_DefaultStringEncoding || encoding==NSASCIIStringEncoding))
|
||||
{
|
||||
self = [self initWithCString: bytes
|
||||
length: length];
|
||||
}
|
||||
else if (encoding == NSUTF8StringEncoding)
|
||||
{
|
||||
unsigned char *b = (unsigned char*)bytes;
|
||||
unsigned i = 0;
|
||||
|
||||
/*
|
||||
* If the data begins with the UTF8 Byte Order Marker (as a
|
||||
* signature for UTF8 data) we must remove it.
|
||||
*/
|
||||
if (length > 2 && b[0] == 0xEF && b[1] == 0xBB && b[2] == 0xBF)
|
||||
{
|
||||
length -= 3;
|
||||
bytes += 3;
|
||||
}
|
||||
|
||||
if (_ByteEncodingOk)
|
||||
{
|
||||
/*
|
||||
* If it's ok to store ascii strings as internal C strings,
|
||||
* check to see if we have in fact got an ascii string.
|
||||
*/
|
||||
while (i < length)
|
||||
{
|
||||
if (b[i] > 127)
|
||||
{
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == length)
|
||||
{
|
||||
self = [self initWithCString: bytes length: length];
|
||||
}
|
||||
else
|
||||
{
|
||||
unichar *u = 0;
|
||||
unsigned int l = 0;
|
||||
|
||||
if (GSToUnicode(&u, &l, bytes, length, NSUTF8StringEncoding,
|
||||
GSObjCZone(self), 0) == NO)
|
||||
{
|
||||
DESTROY(self);
|
||||
}
|
||||
else
|
||||
{
|
||||
self = [self initWithCharactersNoCopy: u
|
||||
length: l
|
||||
freeWhenDone: YES];
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (encoding == NSUnicodeStringEncoding)
|
||||
{
|
||||
if (length%2 != 0)
|
||||
{
|
||||
DESTROY(self); // Not valid unicode data.
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOL swapped = NO;
|
||||
unsigned char *b;
|
||||
unichar *uptr;
|
||||
|
||||
b = (unsigned char*)bytes;
|
||||
uptr = (unichar*)b;
|
||||
if (*uptr == byteOrderMark)
|
||||
{
|
||||
b = (unsigned char*)++uptr;
|
||||
length -= sizeof(unichar);
|
||||
}
|
||||
else if (*uptr == byteOrderMarkSwapped)
|
||||
{
|
||||
b = (unsigned char*)++uptr;
|
||||
length -= sizeof(unichar);
|
||||
swapped = YES;
|
||||
}
|
||||
if (length == 0)
|
||||
{
|
||||
self = [self initWithCharactersNoCopy: (unichar*)0
|
||||
length: 0
|
||||
freeWhenDone: NO];
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned char *u;
|
||||
|
||||
u = (unsigned char*)NSZoneMalloc(GSObjCZone(self), length);
|
||||
if (swapped == YES)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < length; i += 2)
|
||||
{
|
||||
u[i] = b[i + 1];
|
||||
u[i + 1] = b[i];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(u, b, length);
|
||||
}
|
||||
self = [self initWithCharactersNoCopy: (unichar*)u
|
||||
length: length/2
|
||||
freeWhenDone: YES];
|
||||
}
|
||||
}
|
||||
return [self initWithBytesNoCopy: (void *)0
|
||||
length: 0
|
||||
encoding: encoding
|
||||
freeWhenDone: NO];
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned char *b;
|
||||
unichar *u = 0;
|
||||
unsigned l = 0;
|
||||
void *buf = NSZoneMalloc(GSObjCZone(self), length);
|
||||
|
||||
b = (unsigned char*)bytes;
|
||||
if (GSToUnicode(&u, &l, b, length, encoding, GSObjCZone(self), 0) == NO)
|
||||
{
|
||||
DESTROY(self);
|
||||
}
|
||||
else
|
||||
{
|
||||
self = [self initWithCharactersNoCopy: u
|
||||
length: l
|
||||
freeWhenDone: YES];
|
||||
}
|
||||
memcpy(buf, bytes, length);
|
||||
return [self initWithBytesNoCopy: buf
|
||||
length: length
|
||||
encoding: encoding
|
||||
freeWhenDone: YES];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
/** <init /> <override-subclass />
|
||||
* Initialises the receiver with the supplied length of bytes, using the
|
||||
* specified encoding.<br />
|
||||
* For NSUnicodeStringEncoding and NSUTF8String encoding, a Byte Order
|
||||
|
@ -1010,194 +892,32 @@ handle_printf_atsign (FILE *stream,
|
|||
* needed.<br />
|
||||
* If the data can not be interpreted using the encoding, the receiver
|
||||
* is released and nil is returned.
|
||||
* <p>Note, this is the most basic initialiser for strings.
|
||||
* In the GNUstep implementation, your subclasses may override
|
||||
* this initialiser in order to have all others function.</p>
|
||||
*/
|
||||
- (id) initWithBytesNoCopy: (const void*)bytes
|
||||
- (id) initWithBytesNoCopy: (void*)bytes
|
||||
length: (unsigned int)length
|
||||
encoding: (NSStringEncoding)encoding
|
||||
freeWhenDone: (BOOL)flag
|
||||
{
|
||||
BOOL bytesNeeded = NO;
|
||||
|
||||
if (flag == NO)
|
||||
{
|
||||
bytesNeeded = YES;
|
||||
}
|
||||
|
||||
if (length == 0)
|
||||
{
|
||||
self = [self initWithCharactersNoCopy: (unichar*)0
|
||||
length: 0
|
||||
freeWhenDone: NO];
|
||||
}
|
||||
else if (_ByteEncodingOk == YES
|
||||
&& (encoding==_DefaultStringEncoding || encoding==NSASCIIStringEncoding))
|
||||
{
|
||||
self = [self initWithCStringNoCopy: (void*)bytes
|
||||
length: length
|
||||
freeWhenDone: YES];
|
||||
bytesNeeded = YES;
|
||||
}
|
||||
else if (encoding == NSUTF8StringEncoding)
|
||||
{
|
||||
unsigned char *b =(unsigned char*)bytes;
|
||||
unsigned i = 0;
|
||||
|
||||
/*
|
||||
* If the data begins with the UTF8 Byte Order Marker (as a
|
||||
* signature for UTF8 data) we must remove it.
|
||||
*/
|
||||
if (length > 2 && b[0] == 0xEF && b[1] == 0xBB && b[2] == 0xBF)
|
||||
{
|
||||
length -= 3;
|
||||
bytes += 3;
|
||||
}
|
||||
|
||||
if (_ByteEncodingOk)
|
||||
{
|
||||
/*
|
||||
* If it's ok to store ascii strings as internal C strings,
|
||||
* check to see if we have in fact got an ascii string.
|
||||
*/
|
||||
while (i < length)
|
||||
{
|
||||
if (b[i] > 127)
|
||||
{
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == length)
|
||||
{
|
||||
self = [self initWithCString: bytes length: length];
|
||||
}
|
||||
else
|
||||
{
|
||||
unichar *u = 0;
|
||||
unsigned int l = 0;
|
||||
|
||||
if (GSToUnicode(&u, &l, bytes, length, NSUTF8StringEncoding,
|
||||
GSObjCZone(self), 0) == NO)
|
||||
{
|
||||
DESTROY(self);
|
||||
}
|
||||
else
|
||||
{
|
||||
self = [self initWithCharactersNoCopy: u
|
||||
length: l
|
||||
freeWhenDone: YES];
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (encoding == NSUnicodeStringEncoding)
|
||||
{
|
||||
if (length%2 != 0)
|
||||
{
|
||||
DESTROY(self); // Not valid unicode data.
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOL swapped = NO;
|
||||
BOOL copy = NO;
|
||||
unsigned char *b;
|
||||
unichar *uptr;
|
||||
|
||||
b = (unsigned char*)bytes;
|
||||
uptr = (unichar*)b;
|
||||
if (*uptr == byteOrderMark)
|
||||
{
|
||||
b = (unsigned char*)++uptr;
|
||||
length -= sizeof(unichar);
|
||||
copy = YES;
|
||||
flag = YES;
|
||||
}
|
||||
else if (*uptr == byteOrderMarkSwapped)
|
||||
{
|
||||
b = (unsigned char*)++uptr;
|
||||
length -= sizeof(unichar);
|
||||
swapped = YES;
|
||||
copy = YES;
|
||||
flag = YES;
|
||||
}
|
||||
if (length == 0)
|
||||
{
|
||||
self = [self initWithCharactersNoCopy: (unichar*)0
|
||||
length: 0
|
||||
freeWhenDone: NO];
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned char *u;
|
||||
|
||||
if (copy == YES)
|
||||
{
|
||||
u = (unsigned char*)NSZoneMalloc(GSObjCZone(self), length);
|
||||
if (swapped == YES)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < length; i += 2)
|
||||
{
|
||||
u[i] = b[i + 1];
|
||||
u[i + 1] = b[i];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(u, b, length);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
u = (unsigned char *)bytes;
|
||||
bytesNeeded = YES;
|
||||
}
|
||||
self = [self initWithCharactersNoCopy: (unichar*)u
|
||||
length: length/2
|
||||
freeWhenDone: flag];
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned char *b;
|
||||
unichar *u = 0;
|
||||
unsigned l = 0;
|
||||
|
||||
b = (unsigned char*)bytes;
|
||||
if (GSToUnicode(&u, &l, b, length, encoding, GSObjCZone(self), 0) == NO)
|
||||
{
|
||||
DESTROY(self);
|
||||
}
|
||||
else
|
||||
{
|
||||
self = [self initWithCharactersNoCopy: u
|
||||
length: l
|
||||
freeWhenDone: YES];
|
||||
}
|
||||
}
|
||||
if (bytesNeeded == NO && bytes != 0)
|
||||
{
|
||||
NSZoneFree(NSZoneFromPointer((void*)bytes), (void*)bytes);
|
||||
}
|
||||
self = [self init];
|
||||
return self;
|
||||
}
|
||||
|
||||
/** <init /> <override-subclass />
|
||||
/**
|
||||
* <p>Initialize with given unicode chars up to length, regardless of presence
|
||||
* of null bytes. Does not copy the string. If flag, frees its storage when
|
||||
* this instance is deallocated.</p>
|
||||
* <p>Note, this is the most basic initialiser for unicode strings.
|
||||
* In the GNUstep implementation, your subclasses may override
|
||||
* this initialiser in order to have all others function.</p>
|
||||
*/
|
||||
- (id) initWithCharactersNoCopy: (unichar*)chars
|
||||
length: (unsigned int)length
|
||||
freeWhenDone: (BOOL)flag
|
||||
{
|
||||
self = [self init];
|
||||
return self;
|
||||
return [self initWithBytesNoCopy: chars
|
||||
length: length * sizeof(unichar)
|
||||
encoding: NSUnicodeStringEncoding
|
||||
freeWhenDone: flag];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1207,58 +927,9 @@ handle_printf_atsign (FILE *stream,
|
|||
- (id) initWithCharacters: (const unichar*)chars
|
||||
length: (unsigned int)length
|
||||
{
|
||||
if (length > 0)
|
||||
{
|
||||
unsigned int i;
|
||||
BOOL isAscii = YES;
|
||||
|
||||
if (chars == 0)
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"null pointer but non-zero length"];
|
||||
}
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
if (chars[i] >= 128)
|
||||
{
|
||||
isAscii = NO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isAscii == YES)
|
||||
{
|
||||
char *s;
|
||||
|
||||
s = NSZoneMalloc(GSObjCZone(self), length);
|
||||
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
s[i] = (unsigned char)chars[i];
|
||||
}
|
||||
self = [self initWithCStringNoCopy: s
|
||||
length: length
|
||||
freeWhenDone: YES];
|
||||
}
|
||||
else
|
||||
{
|
||||
unichar *s;
|
||||
|
||||
s = NSZoneMalloc(GSObjCZone(self), sizeof(unichar)*length);
|
||||
|
||||
memcpy(s, chars, sizeof(unichar)*length);
|
||||
self = [self initWithCharactersNoCopy: s
|
||||
length: length
|
||||
freeWhenDone: YES];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
self = [self initWithCharactersNoCopy: (unichar*)0
|
||||
length: 0
|
||||
freeWhenDone: NO];
|
||||
}
|
||||
|
||||
return self;
|
||||
return [self initWithBytes: chars
|
||||
length: length * sizeof(unichar)
|
||||
encoding: NSUnicodeStringEncoding];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1271,23 +942,10 @@ handle_printf_atsign (FILE *stream,
|
|||
length: (unsigned int)length
|
||||
freeWhenDone: (BOOL)flag
|
||||
{
|
||||
unichar *buf = 0;
|
||||
unsigned int l = 0;
|
||||
|
||||
if (GSToUnicode(&buf, &l, (unsigned char*)byteString, length,
|
||||
_DefaultStringEncoding, [self zone], 0) == NO)
|
||||
{
|
||||
DESTROY(self);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (flag == YES && byteString != 0)
|
||||
{
|
||||
NSZoneFree(NSZoneFromPointer(byteString), byteString);
|
||||
}
|
||||
self = [self initWithCharactersNoCopy: buf length: l freeWhenDone: YES];
|
||||
}
|
||||
return self;
|
||||
return [self initWithBytesNoCopy: byteString
|
||||
length: length
|
||||
encoding: _DefaultStringEncoding
|
||||
freeWhenDone: flag];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1310,22 +968,9 @@ handle_printf_atsign (FILE *stream,
|
|||
*/
|
||||
- (id) initWithCString: (const char*)byteString length: (unsigned int)length
|
||||
{
|
||||
if (length > 0)
|
||||
{
|
||||
char *s = NSZoneMalloc(GSObjCZone(self), length);
|
||||
|
||||
if (byteString != 0)
|
||||
{
|
||||
memcpy(s, byteString, length);
|
||||
}
|
||||
self = [self initWithCStringNoCopy: s length: length freeWhenDone: YES];
|
||||
}
|
||||
else
|
||||
{
|
||||
self = [self initWithCStringNoCopy: 0 length: 0 freeWhenDone: NO];
|
||||
}
|
||||
|
||||
return self;
|
||||
return [self initWithBytes: byteString
|
||||
length: length
|
||||
encoding: _DefaultStringEncoding];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1335,8 +980,9 @@ handle_printf_atsign (FILE *stream,
|
|||
*/
|
||||
- (id) initWithCString: (const char*)byteString
|
||||
{
|
||||
return [self initWithCString: byteString
|
||||
length: (byteString ? strlen(byteString) : 0)];
|
||||
return [self initWithBytes: byteString
|
||||
length: (byteString ? strlen(byteString) : 0)
|
||||
encoding: _DefaultStringEncoding];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1369,66 +1015,9 @@ handle_printf_atsign (FILE *stream,
|
|||
*/
|
||||
- (id) initWithUTF8String: (const char *)bytes
|
||||
{
|
||||
unsigned length = 0;
|
||||
|
||||
if (bytes == NULL)
|
||||
{
|
||||
NSDebugMLog(@"bytes is NULL");
|
||||
}
|
||||
else
|
||||
{
|
||||
length = strlen(bytes);
|
||||
}
|
||||
|
||||
if (length > 0)
|
||||
{
|
||||
unsigned i = 0;
|
||||
|
||||
if (_ByteEncodingOk)
|
||||
{
|
||||
/*
|
||||
* If it's ok to store ascii strings as internal C strings,
|
||||
* check to see if we have in fact got an ascii string.
|
||||
*/
|
||||
while (i < length)
|
||||
{
|
||||
if (((unsigned char*)bytes)[i] > 127)
|
||||
{
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == length)
|
||||
{
|
||||
self = [self initWithCString: bytes length: length];
|
||||
}
|
||||
else
|
||||
{
|
||||
unichar *u = 0;
|
||||
unsigned int l = 0;
|
||||
|
||||
if (GSToUnicode(&u, &l, (unsigned char*)bytes, length,
|
||||
NSUTF8StringEncoding, GSObjCZone(self), 0) == NO)
|
||||
{
|
||||
DESTROY(self);
|
||||
}
|
||||
else
|
||||
{
|
||||
self = [self initWithCharactersNoCopy: u
|
||||
length: l
|
||||
freeWhenDone: YES];
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
self = [self initWithCharactersNoCopy: (unichar*)0
|
||||
length: 0
|
||||
freeWhenDone: NO];
|
||||
}
|
||||
return self;
|
||||
return [self initWithBytes: bytes
|
||||
length: (bytes ? strlen(bytes) : 0)
|
||||
encoding: NSUTF8StringEncoding];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1551,155 +1140,9 @@ handle_printf_atsign (FILE *stream,
|
|||
- (id) initWithData: (NSData*)data
|
||||
encoding: (NSStringEncoding)encoding
|
||||
{
|
||||
unsigned len = [data length];
|
||||
|
||||
if (len == 0)
|
||||
{
|
||||
self = [self initWithCharactersNoCopy: (unichar*)0
|
||||
length: 0
|
||||
freeWhenDone: NO];
|
||||
}
|
||||
else if (_ByteEncodingOk == YES
|
||||
&& (encoding==_DefaultStringEncoding || encoding==NSASCIIStringEncoding))
|
||||
{
|
||||
char *s;
|
||||
|
||||
/*
|
||||
* We can only create an internal C string if the default C string
|
||||
* encoding is Ok, and the specified encoding matches it.
|
||||
*/
|
||||
s = NSZoneMalloc(GSObjCZone(self), len);
|
||||
[data getBytes: s];
|
||||
self = [self initWithCStringNoCopy: s length: len freeWhenDone: YES];
|
||||
}
|
||||
else if (encoding == NSUTF8StringEncoding)
|
||||
{
|
||||
const unsigned char *bytes = [data bytes];
|
||||
unsigned i = 0;
|
||||
|
||||
/*
|
||||
* If the data begins with the UTF8 Byte Order Marker (as a
|
||||
* signature for UTF8 data) we must remove it.
|
||||
*/
|
||||
if (len > 2 && bytes[0] == 0xEF && bytes[1] == 0xBB && bytes[2] == 0xBF)
|
||||
{
|
||||
len -= 3;
|
||||
bytes += 3;
|
||||
}
|
||||
|
||||
if (_ByteEncodingOk)
|
||||
{
|
||||
/*
|
||||
* If it's ok to store ascii strings as internal C strings,
|
||||
* check to see if we have in fact got an ascii string.
|
||||
*/
|
||||
while (i < len)
|
||||
{
|
||||
if ((bytes)[i] > 127)
|
||||
{
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == len)
|
||||
{
|
||||
self = [self initWithCString: (char*)bytes length: len];
|
||||
}
|
||||
else
|
||||
{
|
||||
unichar *u = 0;
|
||||
unsigned int l = 0;
|
||||
|
||||
if (GSToUnicode(&u, &l, bytes, len, NSUTF8StringEncoding,
|
||||
GSObjCZone(self), 0) == NO)
|
||||
{
|
||||
DESTROY(self);
|
||||
}
|
||||
else
|
||||
{
|
||||
self = [self initWithCharactersNoCopy: u
|
||||
length: l
|
||||
freeWhenDone: YES];
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (encoding == NSUnicodeStringEncoding)
|
||||
{
|
||||
if (len%2 != 0)
|
||||
{
|
||||
DESTROY(self); // Not valid unicode data.
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOL swapped = NO;
|
||||
unsigned char *b;
|
||||
unichar *uptr;
|
||||
|
||||
b = (unsigned char*)[data bytes];
|
||||
uptr = (unichar*)b;
|
||||
if (*uptr == byteOrderMark)
|
||||
{
|
||||
b = (unsigned char*)++uptr;
|
||||
len -= sizeof(unichar);
|
||||
}
|
||||
else if (*uptr == byteOrderMarkSwapped)
|
||||
{
|
||||
b = (unsigned char*)++uptr;
|
||||
len -= sizeof(unichar);
|
||||
swapped = YES;
|
||||
}
|
||||
if (len == 0)
|
||||
{
|
||||
self = [self initWithCharactersNoCopy: (unichar*)0
|
||||
length: 0
|
||||
freeWhenDone: NO];
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned char *u;
|
||||
|
||||
u = (unsigned char*)NSZoneMalloc(GSObjCZone(self), len);
|
||||
if (swapped == YES)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < len; i += 2)
|
||||
{
|
||||
u[i] = b[i + 1];
|
||||
u[i + 1] = b[i];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(u, b, len);
|
||||
}
|
||||
self = [self initWithCharactersNoCopy: (unichar*)u
|
||||
length: len/2
|
||||
freeWhenDone: YES];
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned char *b;
|
||||
unichar *u = 0;
|
||||
unsigned l = 0;
|
||||
|
||||
b = (unsigned char*)[data bytes];
|
||||
if (GSToUnicode(&u, &l, b, len, encoding, GSObjCZone(self), 0) == NO)
|
||||
{
|
||||
DESTROY(self);
|
||||
}
|
||||
else
|
||||
{
|
||||
self = [self initWithCharactersNoCopy: u
|
||||
length: l
|
||||
freeWhenDone: YES];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
return [self initWithBytes: [data bytes]
|
||||
length: [data length]
|
||||
encoding: encoding];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5053,49 +4496,26 @@ static NSFileManager *fm = nil;
|
|||
length: count
|
||||
freeWhenDone: YES];
|
||||
}
|
||||
else if (enc == NSASCIIStringEncoding
|
||||
|| enc == _DefaultStringEncoding)
|
||||
{
|
||||
char *chars;
|
||||
|
||||
chars = NSZoneMalloc(zone, count+1);
|
||||
[aCoder decodeArrayOfObjCType: @encode(unsigned char)
|
||||
count: count
|
||||
at: chars];
|
||||
self = [self initWithCStringNoCopy: chars
|
||||
length: count
|
||||
freeWhenDone: YES];
|
||||
}
|
||||
else if (enc == NSUTF8StringEncoding)
|
||||
{
|
||||
unsigned char *chars;
|
||||
|
||||
chars = NSZoneMalloc(zone, count+1);
|
||||
[aCoder decodeArrayOfObjCType: @encode(unsigned char)
|
||||
count: count
|
||||
at: chars];
|
||||
chars[count] = '\0';
|
||||
self = [self initWithUTF8String: (char*)chars];
|
||||
NSZoneFree(zone, chars);
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned char *chars;
|
||||
NSData *data;
|
||||
|
||||
chars = NSZoneMalloc(zone, count);
|
||||
chars = NSZoneMalloc(zone, count+1);
|
||||
[aCoder decodeArrayOfObjCType: @encode(unsigned char)
|
||||
count: count
|
||||
count: count
|
||||
at: chars];
|
||||
data = [NSDataClass allocWithZone: zone];
|
||||
data = [data initWithBytesNoCopy: chars length: count];
|
||||
self = [self initWithData: data encoding: enc];
|
||||
RELEASE(data);
|
||||
self = [self initWithBytesNoCopy: chars
|
||||
length: count
|
||||
encoding: enc
|
||||
freeWhenDone: YES];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
self = [self initWithCStringNoCopy: "" length: 0 freeWhenDone: NO];
|
||||
self = [self initWithBytesNoCopy: ""
|
||||
length: 0
|
||||
encoding: NSASCIIStringEncoding
|
||||
freeWhenDone: NO];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
|
|
|
@ -2290,7 +2290,7 @@ static NSString *mainFont = nil;
|
|||
{
|
||||
NSArray *a;
|
||||
NSMutableString *ivarBuf = ivarsAtEnd ?
|
||||
[NSMutableString stringWithCapacity: 1024] : nil;
|
||||
(id)[NSMutableString stringWithCapacity: 1024] : nil;
|
||||
NSDictionary *prop = [node attributes];
|
||||
|
||||
node = [node firstChildElement];
|
||||
|
|
|
@ -2203,7 +2203,7 @@ main(int argc, char **argv, char **env)
|
|||
{
|
||||
NSLog(@"Replace %@ with %@",
|
||||
[s substringWithRange: replace],
|
||||
repstr ? repstr : @"self");
|
||||
repstr ? (id)repstr : (id)@"self");
|
||||
}
|
||||
if (repstr != nil)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue