mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Merge branch 'master' into file_creation_date
This commit is contained in:
commit
57e4eba479
22 changed files with 2246 additions and 1883 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -26,6 +26,9 @@ Tests/base/coding/ulong-8.type
|
|||
*.orig
|
||||
*.swp
|
||||
|
||||
# MacOS Desktop Services Store
|
||||
.DS_Store
|
||||
|
||||
# Created by https://www.gitignore.io/api/xcode
|
||||
# Edit at https://www.gitignore.io/?templates=xcode
|
||||
|
||||
|
|
45
ChangeLog
45
ChangeLog
|
@ -1,4 +1,4 @@
|
|||
2010-05-04 Riccardo Mottola <rm@gnu.org>
|
||||
2010-05-12 Riccardo Mottola <rm@gnu.org>
|
||||
|
||||
* Source/NSFileManager.m:
|
||||
In changeFileAttributes implement setting of creation date also for
|
||||
|
@ -6,7 +6,7 @@
|
|||
Also, implement reading the creation (birth time) date if a supported
|
||||
method was detected.
|
||||
|
||||
2010-05-01 Riccardo Mottola <rm@gnu.org>
|
||||
2010-05-12 Riccardo Mottola <rm@gnu.org>
|
||||
|
||||
* configure
|
||||
* configure.ac
|
||||
|
@ -16,6 +16,47 @@
|
|||
* Source/NSFileManager.m: (changeFileAttributes:)
|
||||
Use utimensat() to set file modification date, if available.
|
||||
|
||||
2020-05-05 Frederik Seiffert <frederik@algoriddim.com>
|
||||
|
||||
* Source/unix/NSStream.m: Add NSInputStream support for reading
|
||||
Android assets from main bundle.
|
||||
|
||||
2020-05-10 Fred Kiefer <fredkiefer@gmx.de>
|
||||
|
||||
* Source/NSISO8601DateFormatter.m,
|
||||
* Source/NSOrthography.m: Clean up some compiler warnings.
|
||||
|
||||
2020-05-09 Fred Kiefer <fredkiefer@gmx.de>
|
||||
|
||||
* Tests/base/NSLocale/general.m: Mark more tests that depend on
|
||||
locale setting as hopes.
|
||||
* Tests/base/NSXMLParser/parse.m: Mark stream test as hopeful as
|
||||
this isn't implemented at the moment.
|
||||
* Tests/base/NSURL/basic.m: Use PASS_EQUAL in the downlaod test
|
||||
to get the actual http status reported.
|
||||
|
||||
2020-05-08 Fred Kiefer <fredkiefer@gmx.de>
|
||||
|
||||
* Source/NSXMLParser.m: Fix small bug in last commit that broke
|
||||
all gui applications when there was a commented out section in the
|
||||
user default XML file.
|
||||
|
||||
2020-05-07 Frederik Seiffert <frederik@algoriddim.com>
|
||||
|
||||
* Headers/Foundation/NSLocale.h:
|
||||
* Source/NSLocale.m:
|
||||
Use "instancetype" for instance-returning methods. Fix method
|
||||
signature of -displayNameForKey:value:.
|
||||
|
||||
2020-05-05 Frederik Seiffert <frederik@algoriddim.com>
|
||||
|
||||
* Headers/Foundation/NSXMLParser.h:
|
||||
* Headers/GNUstepBase/GSXML.h:
|
||||
* Source/Additions/GSXML.m:
|
||||
* Source/NSXMLParser.m:
|
||||
* Tests/base/NSXMLParser/parse.m:
|
||||
Implement -[NSXMLParser initWithStream:].
|
||||
|
||||
2020-04-26 Fred Kiefer <fredkiefer@gmx.de>
|
||||
|
||||
* Source/NSLocale.m: Respect NSLocaleCalendarIdentifier if
|
||||
|
|
|
@ -156,7 +156,7 @@ GS_EXPORT NSString * const NSISO8601Calendar;
|
|||
|
||||
/** Returns the current locale information.
|
||||
*/
|
||||
+ (id) currentLocale;
|
||||
+ (instancetype) currentLocale;
|
||||
|
||||
/** Returns an array of NSString representing all known country codes.
|
||||
*/
|
||||
|
@ -190,7 +190,7 @@ GS_EXPORT NSString * const NSISO8601Calendar;
|
|||
#if OS_API_VERSION(MAC_OS_X_VERSION_10_6, GS_API_LATEST)
|
||||
/** Returns a locale initialised with the given locale identifier.
|
||||
*/
|
||||
+ (id) localeWithLocaleIdentifier:(NSString *)string;
|
||||
+ (instancetype) localeWithLocaleIdentifier:(NSString *)string;
|
||||
#endif
|
||||
|
||||
#if OS_API_VERSION(MAC_OS_X_VERSION_10_5, GS_API_LATEST)
|
||||
|
@ -202,7 +202,7 @@ GS_EXPORT NSString * const NSISO8601Calendar;
|
|||
|
||||
/** Returns the the system locale.
|
||||
*/
|
||||
+ (id) systemLocale;
|
||||
+ (instancetype) systemLocale;
|
||||
|
||||
#if OS_API_VERSION(MAC_OS_X_VERSION_10_6, GS_API_LATEST)
|
||||
/** Returns the windows locale code corresponding to the staqndard locale
|
||||
|
@ -216,12 +216,12 @@ GS_EXPORT NSString * const NSISO8601Calendar;
|
|||
* on the basis that it represents information whose type is specified by
|
||||
* the key.
|
||||
*/
|
||||
- (NSString *) displayNameForKey: (id)key value: (id)value;
|
||||
- (NSString *) displayNameForKey: (NSString *)key value: (id)value;
|
||||
|
||||
/** Initialises the receiver to be the locale specified by the identifier.
|
||||
* This may result in replacement of the receiver by an existing locale.
|
||||
*/
|
||||
- (id) initWithLocaleIdentifier: (NSString *)string;
|
||||
- (instancetype) initWithLocaleIdentifier: (NSString *)string;
|
||||
|
||||
/** Returns the canonical identifier for the receiver (which
|
||||
* may differ from the identifgier used to create the receiver
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
@class NSData, NSDictionary, NSError, NSString, NSURL;
|
||||
@class NSData, NSDictionary, NSError, NSInputStream, NSString, NSURL;
|
||||
|
||||
/**
|
||||
* Domain for errors
|
||||
|
@ -100,12 +100,17 @@ GS_EXPORT NSString* const NSXMLParserErrorDomain;
|
|||
/**
|
||||
* Convenience method fetching data from anURL.<br />
|
||||
*/
|
||||
- (id) initWithContentsOfURL: (NSURL*)anURL;
|
||||
- (instancetype) initWithContentsOfURL: (NSURL*)anURL;
|
||||
|
||||
/** <init />
|
||||
* Initialises the parser with the specified xml data.
|
||||
*/
|
||||
- (id) initWithData: (NSData*)data;
|
||||
- (instancetype) initWithData: (NSData*)data;
|
||||
|
||||
/**
|
||||
* Initialises the parser with the specified input stream.
|
||||
*/
|
||||
- (instancetype) initWithStream: (NSInputStream*)stream;
|
||||
|
||||
/**
|
||||
* Parses the supplied data and returns YES on success, NO otherwise.
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#import <Foundation/NSObject.h>
|
||||
#import <Foundation/NSString.h>
|
||||
#import <Foundation/NSDictionary.h>
|
||||
#import <Foundation/NSStream.h>
|
||||
#else
|
||||
#import <Foundation/Foundation.h>
|
||||
#endif
|
||||
|
@ -222,6 +223,8 @@ extern "C" {
|
|||
withContentsOfURL: (NSURL*)url;
|
||||
- (id) initWithSAXHandler: (GSSAXHandler*)handler
|
||||
withData: (NSData*)data;
|
||||
- (id) initWithSAXHandler: (GSSAXHandler*)handler
|
||||
withInputStream: (NSInputStream*)stream;
|
||||
|
||||
- (BOOL) keepBlanks: (BOOL)yesno;
|
||||
- (NSInteger) lineNumber;
|
||||
|
|
1
MISSING
1
MISSING
|
@ -910,7 +910,6 @@ NSXMLNodeOptions:
|
|||
NSXMLParser:
|
||||
@class NSInputStream
|
||||
|
||||
- initWithStream:
|
||||
- parseError
|
||||
-------------------------------------------------------------
|
||||
NSZone:
|
||||
|
|
|
@ -172,6 +172,19 @@ setupCache()
|
|||
}
|
||||
}
|
||||
|
||||
static int xmlNSInputStreamReadCallback(void *context, char *buffer, int len)
|
||||
{
|
||||
NSInputStream *stream = (NSInputStream *)context;
|
||||
return [stream read: (uint8_t *)buffer maxLength: len];
|
||||
}
|
||||
|
||||
static int xmlNSInputStreamCloseCallback (void *context)
|
||||
{
|
||||
NSInputStream *stream = (NSInputStream *)context;
|
||||
[stream close];
|
||||
return 0;
|
||||
}
|
||||
|
||||
static xmlParserInputPtr
|
||||
loadEntityFunction(const unsigned char *url, const unsigned char *eid,
|
||||
void *ctx);
|
||||
|
@ -2102,6 +2115,31 @@ static NSString *endMarker = @"At end of incremental parse";
|
|||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Initialisation of a new Parser with SAX handler (if not nil)
|
||||
* by calling -initWithSAXHandler:
|
||||
* </p>
|
||||
* <p>
|
||||
* Sets the input source for the parser to be the specified input stream,
|
||||
* so parsing of the entire document will be performed rather than
|
||||
* incremental parsing.
|
||||
* </p>
|
||||
*/
|
||||
- (id) initWithSAXHandler: (GSSAXHandler*)handler
|
||||
withInputStream: (NSInputStream*)stream
|
||||
{
|
||||
if (stream == nil || [stream isKindOfClass: [NSInputStream class]] == NO)
|
||||
{
|
||||
NSLog(@"Bad NSInputStream passed to initialize GSXMLParser");
|
||||
DESTROY(self);
|
||||
return nil;
|
||||
}
|
||||
src = RETAIN(stream);
|
||||
self = [self initWithSAXHandler: handler];
|
||||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set and return the previous value for blank text nodes support.
|
||||
* ignorableWhitespace nodes are only generated when running
|
||||
|
@ -2167,7 +2205,8 @@ static NSString *endMarker = @"At end of incremental parse";
|
|||
return NO;
|
||||
}
|
||||
|
||||
if ([src isKindOfClass: [NSData class]])
|
||||
if ([src isKindOfClass: [NSData class]]
|
||||
|| [src isKindOfClass: [NSInputStream class]])
|
||||
{
|
||||
}
|
||||
else if ([src isKindOfClass: NSString_class])
|
||||
|
@ -2194,14 +2233,22 @@ static NSString *endMarker = @"At end of incremental parse";
|
|||
}
|
||||
else
|
||||
{
|
||||
NSLog(@"source for [-parse] must be NSString, NSData or NSURL type");
|
||||
NSLog(@"Source for [-parse] must be NSString, NSData, NSInputStream, or"
|
||||
@" NSURL type");
|
||||
return NO;
|
||||
}
|
||||
|
||||
tmp = RETAIN(src);
|
||||
ASSIGN(src, endMarker);
|
||||
[self _parseChunk: tmp];
|
||||
[self _parseChunk: nil];
|
||||
if ([tmp isKindOfClass: [NSInputStream class]])
|
||||
{
|
||||
xmlParseDocument(lib);
|
||||
}
|
||||
else
|
||||
{
|
||||
[self _parseChunk: tmp];
|
||||
[self _parseChunk: nil];
|
||||
}
|
||||
RELEASE(tmp);
|
||||
|
||||
if (((xmlParserCtxtPtr)lib)->wellFormed != 0
|
||||
|
@ -2382,7 +2429,19 @@ static NSString *endMarker = @"At end of incremental parse";
|
|||
{
|
||||
file = ".";
|
||||
}
|
||||
lib = (void*)xmlCreatePushParserCtxt([saxHandler lib], NULL, 0, 0, file);
|
||||
|
||||
if ([src isKindOfClass: [NSInputStream class]])
|
||||
{
|
||||
[(NSInputStream*)src open];
|
||||
lib = (void*)xmlCreateIOParserCtxt([saxHandler lib], NULL,
|
||||
xmlNSInputStreamReadCallback, xmlNSInputStreamCloseCallback,
|
||||
(void*)src, XML_CHAR_ENCODING_NONE);
|
||||
}
|
||||
else
|
||||
{
|
||||
lib = (void*)xmlCreatePushParserCtxt([saxHandler lib], NULL, 0, 0, file);
|
||||
}
|
||||
|
||||
if (lib == NULL)
|
||||
{
|
||||
NSLog(@"Failed to create libxml parser context");
|
||||
|
|
|
@ -1050,25 +1050,21 @@ static Class concreteMutableClass = nil;
|
|||
|
||||
- (NSCharacterSet*) invertedSet
|
||||
{
|
||||
unsigned i;
|
||||
unsigned length;
|
||||
unsigned char *bytes;
|
||||
NSMutableData *bitmap;
|
||||
NSMutableCharacterSet *m = [self mutableCopy];
|
||||
NSCharacterSet *c;
|
||||
|
||||
bitmap = AUTORELEASE([[self bitmapRepresentation] mutableCopy]);
|
||||
length = [bitmap length];
|
||||
bytes = [bitmap mutableBytes];
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
bytes[i] = ~bytes[i];
|
||||
}
|
||||
return [[self class] characterSetWithBitmapRepresentation: bitmap];
|
||||
[m invert];
|
||||
c = [m copy];
|
||||
RELEASE(m);
|
||||
return AUTORELEASE(c);
|
||||
}
|
||||
|
||||
- (BOOL) isEqual: (id)anObject
|
||||
{
|
||||
if (anObject == self)
|
||||
return YES;
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
if ([anObject isKindOfClass: abstractClass])
|
||||
{
|
||||
unsigned i;
|
||||
|
|
|
@ -22,17 +22,18 @@
|
|||
Boston, MA 02110 USA.
|
||||
*/
|
||||
|
||||
#include <Foundation/NSISO8601DateFormatter.h>
|
||||
#include <Foundation/NSDateFormatter.h>
|
||||
#include <Foundation/NSTimeZone.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#import "Foundation/NSCoder.h"
|
||||
#import "Foundation/NSDateFormatter.h"
|
||||
#import "Foundation/NSISO8601DateFormatter.h"
|
||||
#import "Foundation/NSString.h"
|
||||
#import "Foundation/NSTimeZone.h"
|
||||
|
||||
@implementation NSISO8601DateFormatter
|
||||
|
||||
- (instancetype) init
|
||||
{
|
||||
self = [super init];
|
||||
if(self != nil)
|
||||
if (self != nil)
|
||||
{
|
||||
_formatter = [[NSDateFormatter alloc] init];
|
||||
_timeZone = RETAIN([NSTimeZone localTimeZone]);
|
||||
|
@ -41,11 +42,11 @@
|
|||
return self;
|
||||
}
|
||||
|
||||
- (oneway void) release
|
||||
- (oneway void) dealloc
|
||||
{
|
||||
RELEASE(_formatter);
|
||||
RELEASE(_timeZone);
|
||||
[super release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSTimeZone *) timeZone
|
||||
|
@ -68,32 +69,32 @@
|
|||
NSString *result = @"";
|
||||
|
||||
// Build date...
|
||||
if(_formatOptions & NSISO8601DateFormatWithYear)
|
||||
if (_formatOptions & NSISO8601DateFormatWithYear)
|
||||
{
|
||||
result = [result stringByAppendingString: @"yyyy"];
|
||||
}
|
||||
if(_formatOptions & NSISO8601DateFormatWithDashSeparatorInDate &&
|
||||
_formatOptions & NSISO8601DateFormatWithMonth)
|
||||
if (_formatOptions & NSISO8601DateFormatWithDashSeparatorInDate &&
|
||||
_formatOptions & NSISO8601DateFormatWithMonth)
|
||||
{
|
||||
result = [result stringByAppendingString: @"-"];
|
||||
}
|
||||
if(_formatOptions & NSISO8601DateFormatWithMonth)
|
||||
if (_formatOptions & NSISO8601DateFormatWithMonth)
|
||||
{
|
||||
result = [result stringByAppendingString: @"MM"];
|
||||
}
|
||||
if(_formatOptions & NSISO8601DateFormatWithDashSeparatorInDate &&
|
||||
_formatOptions & NSISO8601DateFormatWithDay)
|
||||
if (_formatOptions & NSISO8601DateFormatWithDashSeparatorInDate &&
|
||||
_formatOptions & NSISO8601DateFormatWithDay)
|
||||
{
|
||||
result = [result stringByAppendingString: @"-"];
|
||||
}
|
||||
if(_formatOptions & NSISO8601DateFormatWithDay)
|
||||
if (_formatOptions & NSISO8601DateFormatWithDay)
|
||||
{
|
||||
result = [result stringByAppendingString: @"dd"];
|
||||
}
|
||||
|
||||
// Build time...
|
||||
if(_formatOptions & NSISO8601DateFormatWithSpaceBetweenDateAndTime &&
|
||||
_formatOptions & NSISO8601DateFormatWithTime)
|
||||
if (_formatOptions & NSISO8601DateFormatWithSpaceBetweenDateAndTime &&
|
||||
_formatOptions & NSISO8601DateFormatWithTime)
|
||||
{
|
||||
result = [result stringByAppendingString: @" "];
|
||||
}
|
||||
|
@ -102,9 +103,9 @@
|
|||
// Add T in format if we have a time component...
|
||||
result = [result stringByAppendingString: @"'T'"];
|
||||
}
|
||||
if(_formatOptions & NSISO8601DateFormatWithTime)
|
||||
if (_formatOptions & NSISO8601DateFormatWithTime)
|
||||
{
|
||||
if(_formatOptions & NSISO8601DateFormatWithColonSeparatorInTime)
|
||||
if (_formatOptions & NSISO8601DateFormatWithColonSeparatorInTime)
|
||||
{
|
||||
result = [result stringByAppendingString: @"HH:mm:ss"];
|
||||
}
|
||||
|
@ -113,13 +114,13 @@
|
|||
result = [result stringByAppendingString: @"HHmmss"];
|
||||
}
|
||||
}
|
||||
if(_formatOptions & NSISO8601DateFormatWithFractionalSeconds)
|
||||
if (_formatOptions & NSISO8601DateFormatWithFractionalSeconds)
|
||||
{
|
||||
result = [result stringByAppendingString: @".SSSSSS"];
|
||||
}
|
||||
if(_formatOptions & NSISO8601DateFormatWithTimeZone)
|
||||
if (_formatOptions & NSISO8601DateFormatWithTimeZone)
|
||||
{
|
||||
if(_formatOptions & NSISO8601DateFormatWithColonSeparatorInTimeZone)
|
||||
if (_formatOptions & NSISO8601DateFormatWithColonSeparatorInTimeZone)
|
||||
{
|
||||
result = [result stringByAppendingString: @"ZZ:ZZ"];
|
||||
}
|
||||
|
@ -164,5 +165,36 @@
|
|||
return [formatter stringFromDate: date];
|
||||
}
|
||||
|
||||
- (void) encodeWithCoder: (NSCoder *)coder
|
||||
{
|
||||
if ([coder allowsKeyedCoding])
|
||||
{
|
||||
[coder encodeObject: _timeZone forKey: @"NS.timeZone"];
|
||||
[coder encodeInteger: _formatOptions forKey: @"NS.formatOptions"];
|
||||
}
|
||||
else
|
||||
{
|
||||
[coder encodeObject: _timeZone];
|
||||
[coder encodeValueOfObjCType: @encode(NSUInteger) at: &_formatOptions];
|
||||
}
|
||||
}
|
||||
|
||||
- (id) initWithCoder: (NSCoder *)decoder
|
||||
{
|
||||
if ((self = [super init]) != nil)
|
||||
{
|
||||
if ([decoder allowsKeyedCoding])
|
||||
{
|
||||
ASSIGN(_timeZone, [decoder decodeObjectForKey: @"NS.timeZone"]);
|
||||
_formatOptions = [decoder decodeIntegerForKey: @"NS.formatOptions"];
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSIGN(_timeZone, [decoder decodeObject]);
|
||||
[decoder decodeValueOfObjCType: @encode(NSUInteger) at: &_formatOptions];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@end
|
||||
|
||||
|
|
|
@ -468,11 +468,16 @@ parseNumber(ParserState *state)
|
|||
{\
|
||||
bufferSize *= 2;\
|
||||
if (number == numberBuffer)\
|
||||
number = malloc(bufferSize);\
|
||||
{\
|
||||
number = malloc(bufferSize);\
|
||||
memcpy(number, numberBuffer, sizeof(numberBuffer));\
|
||||
}\
|
||||
else\
|
||||
number = realloc(number, bufferSize);\
|
||||
{\
|
||||
number = realloc(number, bufferSize);\
|
||||
}\
|
||||
}\
|
||||
number[parsedSize++] = (char)x; } while (0)
|
||||
number[parsedSize++] = (char)x; } while (0)
|
||||
// JSON numbers must start with a - or a digit
|
||||
if (!(c == '-' || isdigit(c)))
|
||||
{
|
||||
|
@ -508,6 +513,8 @@ parseNumber(ParserState *state)
|
|||
free(number);
|
||||
number = numberBuffer;
|
||||
}
|
||||
parseError(state);
|
||||
return nil;
|
||||
}
|
||||
BUFFER(c);
|
||||
while (isdigit(c = consumeChar(state)))
|
||||
|
|
|
@ -691,7 +691,7 @@ static NSRecursiveLock *classLock = nil;
|
|||
#endif
|
||||
}
|
||||
|
||||
- (NSString *) displayNameForKey: (id) key value: (id) value
|
||||
- (NSString *) displayNameForKey: (NSString *) key value: (id) value
|
||||
{
|
||||
#if GS_USE_ICU == 1
|
||||
int32_t length = 0;
|
||||
|
|
|
@ -22,7 +22,10 @@
|
|||
Boston, MA 02110 USA.
|
||||
*/
|
||||
|
||||
#include <Foundation/NSOrthography.h>
|
||||
#import "Foundation/NSArray.h"
|
||||
#import "Foundation/NSDictionary.h"
|
||||
#import "Foundation/NSOrthography.h"
|
||||
#import "Foundation/NSString.h"
|
||||
|
||||
@implementation NSOrthography
|
||||
|
||||
|
@ -30,7 +33,7 @@
|
|||
languageMap: (NSDictionary *)map
|
||||
{
|
||||
self = [super init];
|
||||
if(self != nil)
|
||||
if (self != nil)
|
||||
{
|
||||
ASSIGNCOPY(_dominantScript, script);
|
||||
ASSIGNCOPY(_languageMap, map);
|
||||
|
@ -38,11 +41,11 @@
|
|||
return self;
|
||||
}
|
||||
|
||||
- (oneway void) release
|
||||
- (oneway void) dealloc
|
||||
{
|
||||
RELEASE(_dominantScript);
|
||||
RELEASE(_languageMap);
|
||||
[super release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSString *) dominantScript
|
||||
|
|
|
@ -2116,17 +2116,33 @@ GS_PRIVATE_INTERNAL(NSURLQueryItem)
|
|||
return AUTORELEASE(newQueryItem);
|
||||
}
|
||||
|
||||
- (instancetype)initWithName:(NSString *)name
|
||||
- (instancetype) init
|
||||
{
|
||||
self = [self initWithName:nil value:nil];
|
||||
if(self != nil)
|
||||
{
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithName:(NSString *)name
|
||||
value:(NSString *)value
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil)
|
||||
{
|
||||
GS_CREATE_INTERNAL(NSURLQueryItem);
|
||||
|
||||
ASSIGNCOPY(internal->_name, name);
|
||||
ASSIGNCOPY(internal->_value, value);
|
||||
}
|
||||
if(self != nil)
|
||||
{
|
||||
GS_CREATE_INTERNAL(NSURLQueryItem);
|
||||
if(name)
|
||||
{
|
||||
ASSIGNCOPY(internal->_name, name);
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSIGN(internal->_name, @""); //OSX behaviour is to set an empty string for nil name property
|
||||
}
|
||||
ASSIGNCOPY(internal->_value, value);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -2225,14 +2241,14 @@ static NSCharacterSet *queryItemCharSet = nil;
|
|||
// Creating URL components...
|
||||
+ (instancetype) componentsWithString: (NSString *)urlString
|
||||
{
|
||||
return [[NSURLComponents alloc] initWithString: urlString];
|
||||
return AUTORELEASE([[NSURLComponents alloc] initWithString: urlString]);
|
||||
}
|
||||
|
||||
+ (instancetype) componentsWithURL: (NSURL *)url
|
||||
resolvingAgainstBaseURL: (BOOL)resolve
|
||||
{
|
||||
return [[NSURLComponents alloc] initWithURL: url
|
||||
resolvingAgainstBaseURL: resolve];
|
||||
return AUTORELEASE([[NSURLComponents alloc] initWithURL: url
|
||||
resolvingAgainstBaseURL: resolve]);
|
||||
}
|
||||
|
||||
- (instancetype) init
|
||||
|
@ -2256,12 +2272,16 @@ static NSCharacterSet *queryItemCharSet = nil;
|
|||
|
||||
- (instancetype) initWithString: (NSString *)URLString
|
||||
{
|
||||
self = [self init];
|
||||
if (self != nil)
|
||||
//OSX behavior is to return nil for a string which cannot be used to initialize valid NSURL object
|
||||
NSURL* url = [NSURL URLWithString:URLString];
|
||||
if(url)
|
||||
{
|
||||
[self setString: URLString];
|
||||
return [self initWithURL:url resolvingAgainstBaseURL:NO];
|
||||
}
|
||||
else
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype) initWithURL: (NSURL *)url
|
||||
|
@ -2454,7 +2474,7 @@ static NSCharacterSet *queryItemCharSet = nil;
|
|||
[self setUser: [url user]];
|
||||
[self setPassword: [url password]];
|
||||
[self setPath: [url path]];
|
||||
[self setQuery: [url query]];
|
||||
[self setPercentEncodedQuery:[url query]];
|
||||
[self setFragment: [url fragment]];
|
||||
}
|
||||
|
||||
|
|
3577
Source/NSXMLParser.m
3577
Source/NSXMLParser.m
File diff suppressed because it is too large
Load diff
|
@ -33,6 +33,10 @@
|
|||
# include <sys/fcntl.h>
|
||||
#endif
|
||||
|
||||
#ifdef __ANDROID__
|
||||
# include <android/asset_manager_jni.h>
|
||||
#endif
|
||||
|
||||
#import "Foundation/NSData.h"
|
||||
#import "Foundation/NSArray.h"
|
||||
#import "Foundation/NSDictionary.h"
|
||||
|
@ -57,6 +61,9 @@
|
|||
{
|
||||
@private
|
||||
NSString *_path;
|
||||
#ifdef __ANDROID__
|
||||
AAsset *_asset;
|
||||
#endif
|
||||
}
|
||||
@end
|
||||
|
||||
|
@ -133,7 +140,16 @@
|
|||
return 0;
|
||||
}
|
||||
|
||||
readLen = read((intptr_t)_loopID, buffer, len);
|
||||
#ifdef __ANDROID__
|
||||
if (_asset)
|
||||
{
|
||||
readLen = AAsset_read(_asset, buffer, len);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
readLen = read((intptr_t)_loopID, buffer, len);
|
||||
}
|
||||
if (readLen < 0 && errno != EAGAIN && errno != EINTR)
|
||||
{
|
||||
[self _recordError];
|
||||
|
@ -165,7 +181,18 @@
|
|||
off_t offset = 0;
|
||||
|
||||
if ([self _isOpened])
|
||||
offset = lseek((intptr_t)_loopID, 0, SEEK_CUR);
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
if (_asset)
|
||||
{
|
||||
offset = AAsset_seek(_asset, 0, SEEK_CUR);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
offset = lseek((intptr_t)_loopID, 0, SEEK_CUR);
|
||||
}
|
||||
}
|
||||
return [NSNumber numberWithLong: offset];
|
||||
}
|
||||
return [super propertyForKey: key];
|
||||
|
@ -177,9 +204,15 @@
|
|||
|
||||
fd = open([_path fileSystemRepresentation], O_RDONLY|O_NONBLOCK);
|
||||
if (fd < 0)
|
||||
{
|
||||
[self _recordError];
|
||||
return;
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
_asset = [NSBundle assetForPath:_path withMode:AASSET_MODE_STREAMING];
|
||||
if (!_asset)
|
||||
#endif
|
||||
{
|
||||
[self _recordError];
|
||||
return;
|
||||
}
|
||||
}
|
||||
_loopID = (void*)(intptr_t)fd;
|
||||
[super open];
|
||||
|
@ -187,10 +220,19 @@
|
|||
|
||||
- (void) close
|
||||
{
|
||||
int closeReturn = close((intptr_t)_loopID);
|
||||
#ifdef __ANDROID__
|
||||
if (_asset)
|
||||
{
|
||||
AAsset_close(_asset);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
int closeReturn = close((intptr_t)_loopID);
|
||||
|
||||
if (closeReturn < 0)
|
||||
[self _recordError];
|
||||
if (closeReturn < 0)
|
||||
[self _recordError];
|
||||
}
|
||||
[super close];
|
||||
}
|
||||
|
||||
|
|
|
@ -51,6 +51,9 @@ TOP_DIR := $(shell dirname $(CURDIR))
|
|||
all::
|
||||
@(echo If you want to run the gnustep-base testsuite, please type \'${MAKE} check\')
|
||||
|
||||
# To run tests for a separate group please, use 'make check testobj=NSString'
|
||||
# or 'make check testobj=NSDate/general.m' to run an individual test file
|
||||
#
|
||||
#
|
||||
# 'make check' runs the testsuite (Objective-C tests only)
|
||||
#
|
||||
|
@ -72,9 +75,9 @@ check::
|
|||
export LD_LIBRARY_PATH;\
|
||||
export PATH;\
|
||||
if [ "$(debug)" = "yes" ]; then \
|
||||
gnustep-tests --debug base;\
|
||||
gnustep-tests --debug 'base/$(testobj)';\
|
||||
else \
|
||||
gnustep-tests base;\
|
||||
gnustep-tests 'base/$(testobj)';\
|
||||
fi; \
|
||||
)
|
||||
|
||||
|
|
|
@ -33,6 +33,33 @@ int main()
|
|||
![theSet characterIsMember: '\n'],
|
||||
"Check some characters from lowercaseLetterCharacterSet");
|
||||
|
||||
theSet = [NSCharacterSet newlineCharacterSet];
|
||||
PASS(![theSet characterIsMember: 'A'] &&
|
||||
![theSet characterIsMember: 'Z'] &&
|
||||
![theSet characterIsMember: 'a'] &&
|
||||
![theSet characterIsMember: 'z'] &&
|
||||
![theSet characterIsMember: '9'] &&
|
||||
![theSet characterIsMember: '0'] &&
|
||||
![theSet characterIsMember: '#'] &&
|
||||
![theSet characterIsMember: ' '] &&
|
||||
[theSet characterIsMember: '\n'] &&
|
||||
![theSet characterIsMember: '\t'],
|
||||
"Check some characters from newlineCharacterSet");
|
||||
|
||||
theSet = [theSet invertedSet];
|
||||
PASS([theSet characterIsMember: 'A'] &&
|
||||
[theSet characterIsMember: 'Z'] &&
|
||||
[theSet characterIsMember: 'a'] &&
|
||||
[theSet characterIsMember: 'z'] &&
|
||||
[theSet characterIsMember: '9'] &&
|
||||
[theSet characterIsMember: '0'] &&
|
||||
[theSet characterIsMember: '#'] &&
|
||||
[theSet characterIsMember: ' '] &&
|
||||
![theSet characterIsMember: '\n'] &&
|
||||
[theSet characterIsMember: '\t'] &&
|
||||
[theSet characterIsMember: 0xf6],
|
||||
"Check some characters from inverted newlineCharacterSet");
|
||||
|
||||
theSet = [NSCharacterSet whitespaceAndNewlineCharacterSet];
|
||||
PASS(![theSet characterIsMember: 'A'] &&
|
||||
![theSet characterIsMember: 'Z'] &&
|
||||
|
|
|
@ -22,6 +22,7 @@ int main(void)
|
|||
|
||||
// These tests don't really work all that well. I need to come up with
|
||||
// something better. Most of the ones that fail are because nil is returned.
|
||||
testHopeful = YES;
|
||||
locale = [[NSLocale alloc] initWithLocaleIdentifier: @"es_ES_PREEURO"];
|
||||
PASS_EQUAL([locale objectForKey: NSLocaleIdentifier],
|
||||
@"es_ES@currency=ESP",
|
||||
|
@ -64,7 +65,6 @@ int main(void)
|
|||
"NSLocaleCurrencyCode key returns 'ESP'");
|
||||
PASS_EQUAL([locale objectForKey: NSLocaleCollatorIdentifier],
|
||||
@"es_ES@currency=ESP", "NSLocaleCollatorIdentifier for Spain");
|
||||
testHopeful = YES;
|
||||
PASS_EQUAL([locale objectForKey: NSLocaleGroupingSeparator],
|
||||
@".",
|
||||
"NSLocaleGroupingSeparator key returns '.'");
|
||||
|
|
|
@ -59,7 +59,7 @@ int main()
|
|||
url = [NSURL URLWithString: @"http://www.w3.org/silly-file-name"];
|
||||
data = [url resourceDataUsingCache: NO];
|
||||
num = [url propertyForKey: NSHTTPPropertyStatusCodeKey];
|
||||
PASS([num isKindOfClass: [NSNumber class]] && [num intValue] == 404,
|
||||
PASS_EQUAL(num, [NSNumber numberWithInt: 404],
|
||||
"Status of load is 404 for www.w3.org/silly-file-name");
|
||||
str = [url scheme];
|
||||
PASS([str isEqual: @"http"],
|
||||
|
@ -339,6 +339,23 @@ GSPathHandling("right");
|
|||
PASS_EQUAL([rel absoluteString], @"data:,$2A", "relative data URL works");
|
||||
PASS_EQUAL([rel baseURL], nil, "Base URL of relative data URL is nil");
|
||||
|
||||
///NSURLQueryItem
|
||||
|
||||
//OSX behavior is to return query item with an empty string name
|
||||
NSURLQueryItem* item = [[NSURLQueryItem alloc] init];
|
||||
PASS_EQUAL(item.name, @"", "NSURLQueryItem.name should not be nil");
|
||||
PASS_EQUAL(item.value, nil, "NSURLQueryItem.value should be nil");
|
||||
|
||||
//OSX behavior is to return query item with an empty string name
|
||||
item = [[NSURLQueryItem alloc] initWithName:nil value:nil];
|
||||
PASS_EQUAL(item.name, @"", "NSURLQueryItem.name should not be nil");
|
||||
PASS_EQUAL(item.value, nil, "NSURLQueryItem.value should be nil");
|
||||
|
||||
item = [[NSURLQueryItem alloc] initWithName:@"myName" value:@"myValue"];
|
||||
PASS_EQUAL(item.name, @"myName", "NSURLQueryItem.name should not be nil");
|
||||
PASS_EQUAL(item.value, @"myValue", "NSURLQueryItem.value should not be nil");
|
||||
|
||||
|
||||
[arp release]; arp = nil;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -81,6 +81,23 @@ int main()
|
|||
"set query to item containing ampersand")
|
||||
PASS_EQUAL([components percentEncodedQuery], @"%26",
|
||||
"percent encoded query item encodes ampersand")
|
||||
|
||||
//NSURLQueryItem percent encoding/decoding test
|
||||
NSString* urlString = @"http://domain/?%D0%90%D0%B0%D0%91%D0%B1=%D0%90%D0%B0%D0%91%D0%B1";
|
||||
NSString* cyrillicStr = @"\U00000410\U00000430\U00000411\U00000431";
|
||||
NSURLComponents* components = [NSURLComponents componentsWithString:urlString];
|
||||
NSURLQueryItem* item = [[components queryItems] lastObject];
|
||||
PASS_EQUAL(item.name, cyrillicStr, "Should return decoded query item name from url");
|
||||
PASS_EQUAL(item.value, cyrillicStr, "Should return decoded query item value from url");
|
||||
|
||||
item = [NSURLQueryItem queryItemWithName:cyrillicStr value:cyrillicStr];
|
||||
[components setQueryItems:[NSArray arrayWithObject:item]];
|
||||
PASS_EQUAL([components string], urlString, "Encoded url string from unencoded item");
|
||||
PASS_EQUAL([components URL], [NSURL URLWithString:urlString], "Encoded url query part from unencoded item");
|
||||
|
||||
NSString* invalidUrlString = @"\U00000410\U00000430\U00000411\U00000431";
|
||||
PASS_EQUAL([NSURL URLWithString:invalidUrlString], nil, "nil NSURL from invalid string")
|
||||
PASS_EQUAL([NSURLComponents componentsWithString:invalidUrlString], nil, "nil NSComponents from invalid string")
|
||||
|
||||
END_SET("components")
|
||||
|
||||
|
|
|
@ -5,10 +5,16 @@ int main()
|
|||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
NSXMLParser *parser;
|
||||
Class c = NSClassFromString(@"GSSloppyXMLParser");
|
||||
|
||||
parser = [c new];
|
||||
test_alloc(@"GSSloppyXMLParser");
|
||||
test_NSObject(@"GSSloppyXMLParser", [NSArray arrayWithObject: parser]);
|
||||
|
||||
parser = [NSXMLParser new];
|
||||
test_alloc(@"NSXMLParser");
|
||||
test_NSObject(@"NSXMLParser", [NSArray arrayWithObject: parser]);
|
||||
|
||||
[arp release]; arp = nil;
|
||||
|
||||
/* Don't release the parser ... it appears that on OSX there is a bug in
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#import "ObjectTesting.h"
|
||||
#import <Foundation/NSAutoreleasePool.h>
|
||||
#import <Foundation/NSFileManager.h>
|
||||
#import <Foundation/NSStream.h>
|
||||
#import <Foundation/NSUserDefaults.h>
|
||||
#import <Foundation/NSXMLParser.h>
|
||||
#include <string.h>
|
||||
|
@ -236,17 +237,10 @@ static BOOL setShouldReportNamespacePrefixes = YES;
|
|||
static BOOL setShouldResolveExternalEntities = NO;
|
||||
|
||||
static BOOL
|
||||
testParse(NSData *xml, NSString *expect)
|
||||
testParser(NSXMLParser *parser, NSString *expect)
|
||||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
Handler *handler;
|
||||
NSXMLParser *parser;
|
||||
Class c = NSClassFromString(@"GSSloppyXMLParser");
|
||||
|
||||
c = Nil;
|
||||
if (Nil == c) c = [NSXMLParser class];
|
||||
parser = [[c alloc] initWithData: xml];
|
||||
|
||||
Handler *handler;
|
||||
|
||||
[parser setShouldProcessNamespaces: setShouldProcessNamespaces];
|
||||
[parser setShouldReportNamespacePrefixes: setShouldReportNamespacePrefixes];
|
||||
[parser setShouldResolveExternalEntities: setShouldResolveExternalEntities];
|
||||
|
@ -257,7 +251,6 @@ testParse(NSData *xml, NSString *expect)
|
|||
{
|
||||
NSLog(@"Parsing failed: %@ at %ld on %ld", [parser parserError],
|
||||
(long)[parser columnNumber], (long)[parser lineNumber]);
|
||||
[arp release];
|
||||
return NO;
|
||||
}
|
||||
else
|
||||
|
@ -265,22 +258,55 @@ testParse(NSData *xml, NSString *expect)
|
|||
if (NO == [[handler description] isEqual: expect])
|
||||
{
|
||||
NSLog(@"######## Expected:\n%@\n######## Parsed:\n%@\n########\n",
|
||||
expect, [handler description]);
|
||||
[arp release];
|
||||
expect, [handler description]);
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
[arp release];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
static BOOL
|
||||
testParseCString(const char *xmlBytes, NSString *expect)
|
||||
testParseData(NSData *xml, NSString *expect, BOOL strict)
|
||||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
NSXMLParser *parser;
|
||||
Class c = NSClassFromString(@"GSSloppyXMLParser");
|
||||
BOOL result;
|
||||
|
||||
if (strict) c = Nil;
|
||||
if (Nil == c) c = [NSXMLParser class];
|
||||
parser = [[c alloc] initWithData: xml];
|
||||
result = testParser(parser, expect);
|
||||
|
||||
[arp release];
|
||||
return result;
|
||||
}
|
||||
|
||||
static BOOL
|
||||
testParseCString(const char *xmlBytes, NSString *expect, BOOL strict)
|
||||
{
|
||||
NSData *xml;
|
||||
|
||||
xml = [NSData dataWithBytes: xmlBytes length: strlen(xmlBytes)];
|
||||
return testParse(xml, expect);
|
||||
return testParseData(xml, expect, strict);
|
||||
}
|
||||
|
||||
static BOOL
|
||||
testParseStream(NSInputStream *stream, NSString *expect, BOOL strict)
|
||||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
NSXMLParser *parser;
|
||||
Class c = NSClassFromString(@"GSSloppyXMLParser");
|
||||
BOOL result;
|
||||
|
||||
if (strict) c = Nil;
|
||||
if (Nil == c) c = [NSXMLParser class];
|
||||
parser = [[c alloc] initWithStream: stream];
|
||||
result = testParser(parser, expect);
|
||||
|
||||
[arp release];
|
||||
return result;
|
||||
}
|
||||
|
||||
int main()
|
||||
|
@ -295,8 +321,12 @@ int main()
|
|||
NSString *e1 =
|
||||
@"parserDidStartDocument:\nparser:didStartElement:namespaceURI:qualifiedName:attributes: test test {\n x = 1;\n}\nparser:didEndElement:namespaceURI:qualifiedName: test test\nparserDidEndDocument:\n";
|
||||
|
||||
PASS((testParseCString(x1, e1)), "simple document 1")
|
||||
PASS((testParseCString(x1e, e1)), "simple document 1 without header")
|
||||
PASS((testParseCString(x1, e1, YES)), "simple document 1 (strict)")
|
||||
PASS((testParseCString(x1, e1, NO)), "simple document 1 (sloppy)")
|
||||
PASS((testParseCString(x1e, e1, YES)),
|
||||
"simple document 1 (strict) without header")
|
||||
PASS((testParseCString(x1e, e1, NO)),
|
||||
"simple document 1 (sloppy) without header")
|
||||
|
||||
/* Now perform any tests using .xml and .result pairs of files in
|
||||
* the ParseData subdirectory.
|
||||
|
@ -305,18 +335,35 @@ int main()
|
|||
while ((xmlName = [dir nextObject]) != nil)
|
||||
{
|
||||
if ([[xmlName pathExtension] isEqualToString: @"xml"])
|
||||
{
|
||||
NSString *xmlPath;
|
||||
{
|
||||
NSString *xmlPath;
|
||||
NSData *xmlData;
|
||||
NSString *result;
|
||||
NSInputStream *stream;
|
||||
|
||||
xmlPath = [@"ParseData" stringByAppendingPathComponent: xmlName];
|
||||
str = [xmlPath stringByDeletingPathExtension];
|
||||
str = [str stringByAppendingPathExtension: @"result"];
|
||||
xmlPath = [@"ParseData" stringByAppendingPathComponent: xmlName];
|
||||
str = [xmlPath stringByDeletingPathExtension];
|
||||
str = [str stringByAppendingPathExtension: @"result"];
|
||||
xmlData = [NSData dataWithContentsOfFile: xmlPath];
|
||||
|
||||
result = [NSString stringWithContentsOfFile: str];
|
||||
PASS((testParse(xmlData, result)), "%s", [xmlName UTF8String])
|
||||
}
|
||||
PASS((testParseData(xmlData, result, YES)),
|
||||
"parse data (strict): %s", [xmlName UTF8String])
|
||||
|
||||
result = [NSString stringWithContentsOfFile: str];
|
||||
PASS((testParseData(xmlData, result, NO)),
|
||||
"parse data (sloppy): %s", [xmlName UTF8String])
|
||||
|
||||
stream = [NSInputStream inputStreamWithFileAtPath:xmlPath];
|
||||
PASS((testParseStream(stream, result, YES)),
|
||||
"parse stream (strict): %s", [xmlName UTF8String])
|
||||
|
||||
testHopeful = YES;
|
||||
stream = [NSInputStream inputStreamWithFileAtPath:xmlPath];
|
||||
PASS((testParseStream(stream, result, NO)),
|
||||
"parse stream (sloppy): %s", [xmlName UTF8String])
|
||||
testHopeful = NO;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -335,7 +382,8 @@ parserDidEndDocument:\n\
|
|||
@"<file>&&foo;A</file>", [mgr currentDirectoryPath]];
|
||||
|
||||
dat = [str dataUsingEncoding: NSUTF8StringEncoding];
|
||||
PASS((testParse(dat, exp)), "external entity")
|
||||
PASS((testParseData(dat, exp, YES)), "external entity (strict)")
|
||||
PASS((testParseData(dat, exp, YES)), "external entity (sloppy)")
|
||||
}
|
||||
|
||||
[arp release]; arp = nil;
|
||||
|
|
Loading…
Reference in a new issue