Move Cocotron Code To Foundation

This commit is contained in:
TheBrokenRail 2020-05-11 21:10:32 -04:00
parent c2cc878efb
commit c545562011
34 changed files with 4430 additions and 34 deletions

View File

@ -1 +0,0 @@
../../../cocotron/Foundation/NSDebug.h

25
include/Foundation/NSDebug.h Executable file
View File

@ -0,0 +1,25 @@
/* Copyright (c) 2006-2007 Christopher J. W. Lloyd
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <Foundation/NSObject.h>
FOUNDATION_EXPORT BOOL NSZombieEnabled;
FOUNDATION_EXPORT BOOL NSDebugEnabled;
FOUNDATION_EXPORT BOOL NSCooperativeThreadsEnabled;
void NSCooperativeThreadBlocking();
void NSCooperativeThreadWaiting();
FOUNDATION_EXPORT void *NSFrameAddress(NSUInteger level);
FOUNDATION_EXPORT unsigned NSCountFrames(void);
FOUNDATION_EXPORT void *NSReturnAddress(int level);
#if defined(__WIN32__) || defined(SOLARIS)
int backtrace(void **array, int size);
char **backtrace_symbols(void *const *array, int size);
#endif

View File

@ -1 +0,0 @@
../../../cocotron/Foundation/NSPlatform.h

77
include/Foundation/NSPlatform.h Executable file
View File

@ -0,0 +1,77 @@
/* Copyright (c) 2006-2007 Christopher J. W. Lloyd
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <Foundation/NSObject.h>
#import <Foundation/NSDate.h>
#import <Foundation/NSError.h>
@class NSTimeZone, NSThread, NSInputSource, NSInputSourceSet, NSError;
FOUNDATION_EXPORT NSString *const NSPlatformExecutableFileExtension;
FOUNDATION_EXPORT NSString *const NSPlatformLoadableObjectFileExtension;
FOUNDATION_EXPORT NSString *const NSPlatformLoadableObjectFilePrefix;
FOUNDATION_EXPORT NSString *const NSPlatformExecutableDirectory;
FOUNDATION_EXPORT NSString *const NSPlatformResourceNameSuffix;
@interface NSPlatform : NSObject
+ currentPlatform;
- (NSInputSource *)parentDeathInputSource;
- (Class)taskClass;
- (Class)socketClass;
- (Class)socketPortClass;
- (Class)pipeClass;
- (Class)lockClass;
- (Class)recursiveLockClass;
- (Class)conditionLockClass;
- (Class)persistantDomainClass;
- (Class)timeZoneClass;
- (Class)conditionClass;
- (NSString *)userName;
- (NSString *)fullUserName;
- (NSString *)homeDirectory;
- (NSString *)libraryDirectory;
- (NSString *)temporaryDirectory;
- (NSArray *)arguments;
- (NSDictionary *)environment;
- (NSString *)hostName;
- (NSString *)DNSHostName;
- (NSArray *)addressesForDNSHostName:(NSString *)name;
- (NSString *)hostNameByAddress:(NSString *)address;
- (void *)mapContentsOfFile:(NSString *)path length:(NSUInteger *)length;
- (void)unmapAddress:(void *)ptr length:(NSUInteger)length;
- (BOOL)writeContentsOfFile:(NSString *)path bytes:(const void *)bytes length:(NSUInteger)length options:(NSUInteger)options error:(NSError **)errorp;
- (void)checkEnvironmentKey:(NSString *)key value:(NSString *)value;
@end
FOUNDATION_EXPORT int NSPlatformProcessorCount();
FOUNDATION_EXPORT int NSPlatformProcessID();
FOUNDATION_EXPORT NSUInteger NSPlatformThreadID();
FOUNDATION_EXPORT NSTimeInterval NSPlatformTimeIntervalSinceReferenceDate();
FOUNDATION_EXPORT void NSPlatformLogString(NSString *string);
FOUNDATION_EXPORT void NSPlatformSleepThreadForTimeInterval(NSTimeInterval interval);
FOUNDATION_EXPORT void *NSPlatformContentsOfFile(NSString *path, NSUInteger *length);
// These functions are implemented in the platform subproject
NSThread *NSPlatformCurrentThread();
void NSPlatformSetCurrentThread(NSThread *thread);
#ifdef WINDOWS
NSUInteger NSPlatformDetachThread(unsigned (*__stdcall func)(void *arg), void *arg, NSError **errorp);
#else
NSUInteger NSPlatformDetachThread(void *(*func)(void *arg), void *arg, NSError **errorp);
#endif

View File

@ -1 +0,0 @@
../../../cocotron/Foundation/platform_darwin/NSPlatform_darwin.h

View File

@ -0,0 +1,15 @@
/* Copyright (c) 2006-2007 Christopher J. W. Lloyd
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <Foundation/NSPlatform.h>
#import <Foundation/NSPlatform_posix.h>
@interface NSPlatform_darwin : NSPlatform_posix {
}
@end

View File

@ -1 +0,0 @@
../../../cocotron/Foundation/platform_posix/NSPlatform_posix.h

View File

@ -0,0 +1,19 @@
/* Copyright (c) 2006-2007 Christopher J. W. Lloyd
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <Foundation/NSPlatform.h>
#define FOUNDATION_FILE_MODE S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
#define FOUNDATION_DIR_MODE S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH
@interface NSPlatform_posix : NSPlatform {
}
@end
extern char **NSPlatform_environ();

View File

@ -1 +0,0 @@
../../../cocotron/Foundation/NSException/NSRaise.h

35
include/Foundation/NSRaise.h Executable file
View File

@ -0,0 +1,35 @@
/* Copyright (c) 2006-2007 Christopher J. W. Lloyd
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
// *** FOR INTERNAL COCOTRON USE ONLY
#import <Foundation/NSException.h>
#import <Foundation/NSString.h>
static inline void _NSInvalidAbstractInvocation(SEL selector, id object, const char *file, int line) {
[NSException raise:NSInvalidArgumentException
format:@"-%s only defined for abstract class. Define -[%@ %s] in %s:%d!",
sel_getName(selector), [object class], sel_getName(selector), file, line];
}
static inline void _NSUnimplementedMethod(SEL selector, id object, const char *file, int line) {
NSLog(@"-[%@ %s] unimplemented in %s at %d", [object class], sel_getName(selector), file, line);
}
static inline void _NSUnimplementedFunction(const char *function, const char *file, int line) {
NSLog(@"%s() unimplemented in %s at %d", function, file, line);
}
#define NSInvalidAbstractInvocation() \
_NSInvalidAbstractInvocation(_cmd, self, __FILE__, __LINE__)
#define NSUnimplementedMethod() \
_NSUnimplementedMethod(_cmd, self, __FILE__, __LINE__)
#define NSUnimplementedFunction() \
_NSUnimplementedFunction(__PRETTY_FUNCTION__, __FILE__, __LINE__)

View File

@ -1 +0,0 @@
../../../cocotron/Foundation/NSException/NSRaiseException.h

View File

@ -0,0 +1,23 @@
/* Copyright (c) 2006-2007 Christopher J. W. Lloyd
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
// *** FOR INTERNAL COCOTRON USE ONLY
#import <Foundation/NSException.h>
#import <Foundation/NSString.h>
// DO NOT USE IN NEW CODE AND REPLACE USAGE. Use NSAssert().
FOUNDATION_EXPORT void NSRaiseException(NSString *name, id self, SEL cmd, NSString *fmt, ...);
// This is just a wrapper for fprintf, it doesn't handle %@
// There are situations (such as localization inside NSLog) where you don't want to use NSLog
FOUNDATION_EXPORT void NSCLogv(const char *format, va_list arguments);
FOUNDATION_EXPORT void NSCLog(const char *format, ...);
FOUNDATION_EXPORT void NSCLogThreadId();
FOUNDATION_EXPORT void NSCLogNewline();
FOUNDATION_EXPORT void NSCLogFormat(const char *format, ...);

View File

@ -1 +0,0 @@
../../../cocotron/Foundation/NSAttributedString/NSRangeEntries.h

View File

@ -0,0 +1,38 @@
/* Copyright (c) 2006-2007 Christopher J. W. Lloyd
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <Foundation/NSObject.h>
#import <Foundation/NSRange.h>
// an ordered, nonoverlapping set of NSRanges and related value
typedef struct NSRangeEntries NSRangeEntries;
typedef struct {
NSRangeEntries *self;
NSUInteger index;
} NSRangeEnumerator;
FOUNDATION_EXPORT NSRangeEntries *NSCreateRangeToOwnedPointerEntries(NSUInteger capacity);
FOUNDATION_EXPORT NSRangeEntries *NSCreateRangeToCopiedObjectEntries(NSUInteger capacity);
FOUNDATION_EXPORT void NSFreeRangeEntries(NSRangeEntries *self);
FOUNDATION_EXPORT void NSResetRangeEntries(NSRangeEntries *self);
FOUNDATION_EXPORT NSUInteger NSCountRangeEntries(NSRangeEntries *self);
FOUNDATION_EXPORT void NSRangeEntriesRemoveEntryAtIndex(NSRangeEntries *self, NSUInteger index);
FOUNDATION_EXPORT void NSRangeEntryInsert(NSRangeEntries *self, NSRange range, void *value);
FOUNDATION_EXPORT void *NSRangeEntryAtIndex(NSRangeEntries *self, NSUInteger index, NSRange *effectiveRange);
FOUNDATION_EXPORT void *NSRangeEntryAtRange(NSRangeEntries *self, NSRange range);
FOUNDATION_EXPORT NSRangeEnumerator NSRangeEntryEnumerator(NSRangeEntries *self);
FOUNDATION_EXPORT BOOL NSNextRangeEnumeratorEntry(NSRangeEnumerator *state, NSRange *rangep, void **value);
FOUNDATION_EXPORT void NSRangeEntriesExpandAndWipe(NSRangeEntries *self, NSRange range, NSInteger delta);
FOUNDATION_EXPORT void NSRangeEntriesDivideAndConquer(NSRangeEntries *self, NSRange range);
FOUNDATION_EXPORT void NSRangeEntriesDump(NSRangeEntries *self);
FOUNDATION_EXPORT void NSRangeEntriesVerify(NSRangeEntries *self, NSUInteger length);

View File

@ -1 +0,0 @@
../../../cocotron/Foundation/NSSpellEngine.h

View File

@ -0,0 +1,36 @@
//
// NSSpellEngine.h
// Foundation
//
// Created by Christopher Lloyd on 8/23/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <Foundation/NSObject.h>
#import <Foundation/NSSpellServer.h>
/* Private class which implements the delegate behavior of NSSpellServer directly, used for in-process spell checking. */
@interface NSSpellEngine : NSObject <NSSpellServerDelegate>
+ (NSArray *)allSpellEngines;
+ (NSArray *)spellEngines;
- (NSString *)vendor;
- (NSArray *)languages;
- (NSRange)checkGrammarInString:(NSString *)string language:(NSString *)language details:(NSArray **)outDetails;
- (NSArray *)checkString:(NSString *)stringToCheck offset:(NSUInteger)offset types:(NSTextCheckingTypes)checkingTypes options:(NSDictionary *)options orthography:(NSOrthography *)orthography wordCount:(NSInteger *)wordCount;
- (void)didForgetWord:(NSString *)word inLanguage:(NSString *)language;
- (void)didLearnWord:(NSString *)word inLanguage:(NSString *)language;
- (NSRange)findMisspelledWordInString:(NSString *)stringToCheck language:(NSString *)language wordCount:(NSInteger *)wordCount countOnly:(BOOL)countOnly;
- (NSArray *)suggestCompletionsForPartialWordRange:(NSRange)range inString:(NSString *)string language:(NSString *)language;
- (NSArray *)suggestGuessesForWord:(NSString *)word inLanguage:(NSString *)language;
@end

View File

@ -1 +0,0 @@
../../../cocotron/Foundation/NSSpellServer.h

View File

@ -0,0 +1,43 @@
#import <Foundation/NSObject.h>
#import <Foundation/NSRange.h>
#import <Foundation/NSTextCheckingResult.h>
@class NSSpellServer, NSArray, NSDictionary, NSOrthography;
FOUNDATION_EXPORT NSString *const NSGrammarRange;
FOUNDATION_EXPORT NSString *const NSGrammarUserDescription;
FOUNDATION_EXPORT NSString *const NSGrammarCorrections;
@protocol NSSpellServerDelegate
//@optional
- (NSRange)spellServer:(NSSpellServer *)sender checkGrammarInString:(NSString *)string language:(NSString *)language details:(NSArray **)outDetails;
- (NSArray *)spellServer:(NSSpellServer *)sender checkString:(NSString *)stringToCheck offset:(NSUInteger)offset types:(NSTextCheckingTypes)checkingTypes options:(NSDictionary *)options orthography:(NSOrthography *)orthography wordCount:(NSInteger *)wordCount;
- (void)spellServer:(NSSpellServer *)sender didForgetWord:(NSString *)word inLanguage:(NSString *)language;
- (void)spellServer:(NSSpellServer *)sender didLearnWord:(NSString *)word inLanguage:(NSString *)language;
- (NSRange)spellServer:(NSSpellServer *)sender findMisspelledWordInString:(NSString *)stringToCheck language:(NSString *)language wordCount:(NSInteger *)wordCount countOnly:(BOOL)countOnly;
- (NSArray *)spellServer:(NSSpellServer *)sender suggestCompletionsForPartialWordRange:(NSRange)range inString:(NSString *)string language:(NSString *)language;
- (NSArray *)spellServer:(NSSpellServer *)sender suggestGuessesForWord:(NSString *)word inLanguage:(NSString *)language;
@end
@interface NSSpellServer : NSObject {
}
- (id<NSSpellServerDelegate>)delegate;
- (BOOL)isWordInUserDictionaries:(NSString *)word caseSensitive:(BOOL)caseSensitive;
- (BOOL)registerLanguage:(NSString *)language byVendor:(NSString *)vendor;
- (void)run;
- (void)setDelegate:(id<NSSpellServerDelegate>)delegate;
@end

View File

@ -1 +0,0 @@
../../../cocotron/Foundation/NSUndoManager/NSUndoGroup.h

View File

@ -0,0 +1,31 @@
/* Copyright (c) 2006-2007 Christopher J. W. Lloyd
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <Foundation/NSObject.h>
@class NSArray, NSMutableArray, NSInvocation;
@interface NSUndoGroup : NSObject {
NSUndoGroup *_parentGroup;
NSMutableArray *_invocations;
}
+ (NSUndoGroup *)undoGroupWithParentGroup:(NSUndoGroup *)parentGroup;
- (id)initWithParentGroup:(NSUndoGroup *)parentGroup;
- (NSUndoGroup *)parentGroup;
- (void)addInvocation:(NSInvocation *)invocation;
- (void)addInvocationsFromArray:(NSArray *)array;
- (NSArray *)invocations;
- (void)removeInvocationsWithTarget:(id)target;
- (void)invokeInvocations;
@end

View File

@ -1 +0,0 @@
../../../cocotron/Foundation/NSUndoManager/NSUndoManager.h

View File

@ -0,0 +1,86 @@
/* Copyright (c) 2006-2007 Christopher J. W. Lloyd
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <Foundation/NSObject.h>
@class NSArray, NSMutableArray, NSInvocation;
enum {
NSUndoCloseGroupingRunLoopOrdering = 350000,
};
FOUNDATION_EXPORT NSString *const NSUndoManagerCheckpointNotification;
FOUNDATION_EXPORT NSString *const NSUndoManagerDidOpenUndoGroupNotification;
FOUNDATION_EXPORT NSString *const NSUndoManagerWillCloseUndoGroupNotification;
FOUNDATION_EXPORT NSString *const NSUndoManagerWillUndoChangeNotification;
FOUNDATION_EXPORT NSString *const NSUndoManagerDidUndoChangeNotification;
FOUNDATION_EXPORT NSString *const NSUndoManagerWillRedoChangeNotification;
FOUNDATION_EXPORT NSString *const NSUndoManagerDidRedoChangeNotification;
@interface NSUndoManager : NSObject {
NSMutableArray *_undoStack;
NSMutableArray *_redoStack;
BOOL _groupsByEvent;
NSArray *_modes;
int _disableCount;
NSInteger _levelsOfUndo;
id _currentGroup;
int _state;
NSString *_actionName;
id _preparedTarget;
BOOL _performRegistered;
}
- (NSArray *)runLoopModes;
- (NSUInteger)levelsOfUndo;
- (BOOL)groupsByEvent;
- (void)setRunLoopModes:(NSArray *)modes;
- (void)setLevelsOfUndo:(NSUInteger)levels;
- (void)setGroupsByEvent:(BOOL)flag;
- (BOOL)isUndoRegistrationEnabled;
- (void)disableUndoRegistration;
- (void)enableUndoRegistration;
- (void)beginUndoGrouping;
- (void)endUndoGrouping;
- (NSInteger)groupingLevel;
- (BOOL)canUndo;
- (void)undo;
- (void)undoNestedGroup;
- (BOOL)isUndoing;
- (BOOL)canRedo;
- (void)redo;
- (BOOL)isRedoing;
- (void)registerUndoWithTarget:(id)target selector:(SEL)selector object:(id)object;
- (void)removeAllActions;
- (void)removeAllActionsWithTarget:(id)target;
- (id)prepareWithInvocationTarget:(id)target;
- (void)forwardInvocation:(NSInvocation *)invocation;
- (NSString *)undoActionName;
- (NSString *)undoMenuItemTitle;
- (NSString *)undoMenuTitleForUndoActionName:(NSString *)name;
- (void)setActionName:(NSString *)name;
- (NSString *)redoActionName;
- (NSString *)redoMenuItemTitle;
- (NSString *)redoMenuTitleForUndoActionName:(NSString *)name;
- (void)clearRedoStackIfStateIsNormal;
@end

View File

@ -1 +0,0 @@
../../../cocotron/Foundation/xml/NSXMLDTD.h

View File

@ -0,0 +1,42 @@
/* Copyright (c) 2007 Christopher J. W. Lloyd
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <Foundation/NSXMLNode.h>
@class NSXMLDTDNode, NSURL, NSData, NSMutableArray;
@interface NSXMLDTD : NSXMLNode {
NSString *_publicID;
NSString *_systemID;
}
+ (NSXMLDTDNode *)predefinedEntityDeclarationForName:(NSString *)name;
- (instancetype)initWithData:(NSData *)data options:(NSUInteger)options error:(NSError **)error;
- (instancetype)initWithContentsOfURL:(NSURL *)url options:(NSUInteger)options error:(NSError **)error;
- (NSString *)publicID;
- (NSString *)systemID;
- (NSXMLDTDNode *)attributeDeclarationForName:(NSString *)attributeName elementName:(NSString *)elementName;
- (NSXMLDTDNode *)elementDeclarationForName:(NSString *)name;
- (NSXMLDTDNode *)entityDeclarationForName:(NSString *)name;
- (NSXMLDTDNode *)notationDeclarationForName:(NSString *)name;
- (void)setPublicID:(NSString *)publicID;
- (void)setSystemID:(NSString *)systemID;
- (void)setChildren:(NSArray *)children;
- (void)addChild:(NSXMLNode *)node;
- (void)insertChild:(NSXMLNode *)child atIndex:(NSUInteger)index;
- (void)insertChildren:(NSArray *)children atIndex:(NSUInteger)index;
- (void)removeChildAtIndex:(NSUInteger)index;
- (void)replaceChildAtIndex:(NSUInteger)index withNode:(NSXMLNode *)node;
@end

View File

@ -1 +0,0 @@
../../../cocotron/Foundation/xml/NSXMLDTDNode.h

View File

@ -0,0 +1,33 @@
/* Copyright (c) 2007 Christopher J. W. Lloyd
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <Foundation/NSXMLNode.h>
typedef int NSXMLDTDNodeKind;
@interface NSXMLDTDNode : NSXMLNode {
NSXMLDTDNodeKind _dtdKind;
NSString *_notationName;
NSString *_publicID;
NSString *_systemID;
}
- (instancetype)initWithXMLString:(NSString *)string;
- (NSXMLDTDNodeKind)DTDKind;
- (BOOL)isExternal;
- (NSString *)notationName;
- (NSString *)publicID;
- (NSString *)systemID;
- (void)setDTDKind:(NSXMLDTDNodeKind)kind;
- (void)setNotationName:(NSString *)name;
- (void)setPublicID:(NSString *)publicID;
- (void)setSystemID:(NSString *)systemID;
@end

View File

@ -1 +0,0 @@
../../../cocotron/Foundation/xml/NSXMLDocument.h

View File

@ -0,0 +1,79 @@
/* Copyright (c) 2007 Christopher J. W. Lloyd
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <Foundation/NSXMLNode.h>
#import <Foundation/NSXMLNodeOptions.h>
@class NSXMLDTD, NSURL, NSData, NSMutableArray;
enum {
NSXMLDocumentXMLKind = 0,
NSXMLDocumentXHTMLKind = 1,
NSXMLDocumentHTMLKind = 2,
NSXMLDocumentTextKind = 3,
};
typedef NSUInteger NSXMLDocumentContentKind;
@interface NSXMLDocument : NSXMLNode {
NSXMLDocumentContentKind _contentKind;
NSString *_version;
NSString *_characterEncoding;
NSString *_mimeType;
BOOL _isStandalone;
NSXMLElement *_rootElement;
NSXMLDTD *_dtd;
NSString *_uri;
// parsing state, should be moved out
NSMutableArray *_elementStack;
}
+ (Class)replacementClassForClass:(Class)aClass;
- (instancetype)initWithRootElement:(NSXMLElement *)element;
- (instancetype)initWithXMLString:(NSString *)string options:(NSUInteger)options error:(NSError **)error;
- (instancetype)initWithData:(NSData *)data options:(NSUInteger)options error:(NSError **)error;
- (instancetype)initWithContentsOfURL:(NSURL *)url options:(NSUInteger)options error:(NSError **)error;
- (NSXMLDocumentContentKind)documentContentKind;
- (NSString *)version;
- (NSString *)characterEncoding;
- (NSString *)MIMEType;
- (BOOL)isStandalone;
- (NSXMLElement *)rootElement;
- (NSXMLDTD *)DTD;
- (NSString *)URI;
- (void)setDocumentContentKind:(NSXMLDocumentContentKind)kind;
- (void)setCharacterEncoding:(NSString *)encoding;
- (void)setVersion:(NSString *)version;
- (void)setMIMEType:(NSString *)mimeType;
- (void)setStandalone:(BOOL)flag;
- (void)setRootElement:(NSXMLNode *)element;
- (void)setDTD:(NSXMLDTD *)dtd;
- (void)setURI:(NSString *)uri;
- (void)setChildren:(NSArray *)children;
- (void)addChild:(NSXMLNode *)child;
- (void)insertChild:(NSXMLNode *)child atIndex:(NSUInteger)index;
- (void)insertChildren:(NSArray *)children atIndex:(NSUInteger)index;
- (void)removeChildAtIndex:(NSUInteger)index;
- (void)replaceChildAtIndex:(NSUInteger)index withNode:(NSXMLNode *)node;
- (BOOL)validateAndReturnError:(NSError **)error;
- (NSData *)XMLData;
- (NSData *)XMLDataWithOptions:(NSUInteger)options;
- (id)objectByApplyingXSLT:(NSData *)xslt arguments:(NSDictionary *)arguments error:(NSError *)error;
- (id)objectByApplyingXSLTAtURL:(NSURL *)url arguments:(NSDictionary *)arguments error:(NSError *)error;
- (id)objectByApplyingXSLTString:(NSString *)string arguments:(NSDictionary *)arguments error:(NSError *)error;
@end

View File

@ -1 +0,0 @@
../../../cocotron/Foundation/xml/NSXMLElement.h

View File

@ -0,0 +1,53 @@
/* Copyright (c) 2007 Christopher J. W. Lloyd
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <Foundation/NSXMLNode.h>
@class NSXMLNode, NSArray, NSError, NSDictionary, NSMutableDictionary, NSMutableArray;
@interface NSXMLElement : NSXMLNode <NSCopying> {
NSMutableDictionary *_attributes;
NSMutableDictionary *_namespaces;
}
- (instancetype)initWithName:(NSString *)name;
- (instancetype)initWithName:(NSString *)name stringValue:(NSString *)string;
- (instancetype)initWithName:(NSString *)name URI:(NSString *)uri;
- (instancetype)initWithXMLString:(NSString *)xml error:(NSError **)error;
- (NSArray *)attributes;
- (NSXMLNode *)attributeForLocalName:(NSString *)name URI:(NSString *)uri;
- (NSXMLNode *)attributeForName:(NSString *)name;
- (NSArray *)elementsForLocalName:(NSString *)localName URI:(NSString *)uri;
- (NSArray *)elementsForName:(NSString *)name;
- (NSArray *)namespaces;
- (NSXMLNode *)namespaceForPrefix:(NSString *)prefix;
- (void)setAttributes:(NSArray *)attributes;
- (void)setAttributesAsDictionary:(NSDictionary *)attributes;
- (void)setChildren:(NSArray *)children;
- (void)setNamespaces:(NSArray *)namespaces;
- (void)addChild:(NSXMLNode *)child;
- (void)insertChild:(NSXMLNode *)child atIndex:(NSUInteger)index;
- (void)insertChildren:(NSArray *)children atIndex:(NSUInteger)index;
- (void)removeChildAtIndex:(NSUInteger)index;
- (void)replaceChildAtIndex:(NSUInteger)index withNode:(NSXMLNode *)node;
- (void)addAttribute:(NSXMLNode *)attribute;
- (void)removeAttributeForName:(NSString *)name;
- (void)addNamespace:(NSXMLNode *)aNamespace;
- (void)removeNamespaceForPrefix:(NSString *)prefix;
- (void)resolveNamespaceForName:(NSString *)name;
- (void)resolvePrefixForNamespaceURI:(NSString *)uri;
- (void)normalizeAdjacentTextNodesPreservingCDATA:(BOOL)preserve;
@end

View File

@ -1 +0,0 @@
../../../cocotron/Foundation/xml/NSXMLNode.h

View File

@ -0,0 +1,117 @@
/*
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <Foundation/NSObject.h>
#import <Foundation/NSXMLNodeOptions.h>
@class NSArray, NSError, NSDictionary, NSXMLElement, NSXMLNode, NSXMLDocument, NSMutableArray;
typedef enum {
NSXMLInvalidKind,
NSXMLDocumentKind,
NSXMLElementKind,
NSXMLAttributeKind,
NSXMLNamespaceKind,
NSXMLProcessingInstructionKind,
NSXMLCommentKind,
NSXMLTextKind,
NSXMLDTDKind,
NSXMLEntityDeclarationKind,
NSXMLAttributeDeclarationKind,
NSXMLElementDeclarationKind,
NSXMLNotationDeclarationKind
} NSXMLNodeKind;
enum {
NSXMLNodeOptionsNone,
NSXMLNodeIsCDATA,
NSXMLNodeExpandEmptyElement,
NSXMLNodeCompactEmptyElement,
NSXMLNodeUseSingleQuotes,
NSXMLNodeUseDoubleQuotes,
NSXMLNodePrettyPrint,
NSXMLNodePreserveNamespaceOrder,
NSXMLNodePreserveAttributeOrder,
NSXMLNodePreserveEntities,
NSXMLNodePreserveCharacterReferences,
NSXMLNodePreservePrefixes,
NSXMLNodePreserveCDATA,
NSXMLNodePreserveWhitespace,
NSXMLNodePreserveEmptyElements,
NSXMLNodePreserveQuotes,
NSXMLNodePreserveDTD,
NSXMLNodePreserveAll,
};
@interface NSXMLNode : NSObject <NSCopying> {
NSXMLNode *_parent;
NSMutableArray *_children;
NSUInteger _index;
NSXMLNodeKind _kind;
NSUInteger _options;
NSString *_name;
id _value;
}
+ (id)document;
+ (id)documentWithRootElement:(NSXMLElement *)element;
+ (id)elementWithName:(NSString *)name;
+ (id)elementWithName:(NSString *)name children:(NSArray *)children attributes:(NSArray *)attributes;
+ (id)elementWithName:(NSString *)name stringValue:(NSString *)string;
+ (id)attributeWithName:(NSString *)name stringValue:(NSString *)string;
+ (id)commentWithStringValue:(NSString *)string;
+ (id)textWithStringValue:(NSString *)string;
+ (id)processingInstructionWithName:(NSString *)name stringValue:(NSString *)string;
+ (id)DTDNodeWithXMLString:(NSString *)string;
+ (id)namespaceWithName:(NSString *)name stringValue:(NSString *)string;
+ (NSXMLNode *)predefinedNamespaceForPrefix:(NSString *)prefix;
+ (NSString *)prefixForName:(NSString *)name;
+ (NSString *)localNameForName:(NSString *)name;
- (instancetype)initWithKind:(NSXMLNodeKind)kind;
- (instancetype)initWithKind:(NSXMLNodeKind)kind options:(NSUInteger)options;
- (NSUInteger)index;
- (NSXMLNodeKind)kind;
- (NSUInteger)level;
- (NSString *)localName;
- (NSString *)name;
- (NSXMLNode *)nextNode;
- (NSXMLNode *)nextSibling;
- (NSString *)stringValue;
- (NSString *)URI;
- (id)objectValue;
- (NSXMLNode *)parent;
- (NSString *)prefix;
- (NSXMLNode *)previousNode;
- (NSXMLNode *)previousSibling;
- (NSXMLDocument *)rootDocument;
- (NSUInteger)childCount;
- (NSArray *)children;
- (NSXMLNode *)childAtIndex:(NSUInteger)index;
- (void)setName:(NSString *)name;
- (void)setObjectValue:object;
- (void)setStringValue:(NSString *)string;
- (void)setStringValue:(NSString *)string resolvingEntities:(BOOL)resolveEntities;
- (void)detach;
- (NSArray *)nodesForXPath:(NSString *)xpath error:(NSError **)error;
- (NSArray *)objectsForXQuery:(NSString *)xquery constants:(NSDictionary *)constants error:(NSError **)error;
- (NSArray *)objectsForXQuery:(NSString *)xquery error:(NSError **)error;
- (NSString *)XMLString;
- (NSString *)XMLStringWithOptions:(NSUInteger)options;
- (NSString *)XPath;
- (NSString *)canonicalXMLStringPreservingComments:(BOOL)comments;
@end

View File

@ -1 +0,0 @@
../../../cocotron/Foundation/xml/NSXMLNodeOptions.h

View File

@ -0,0 +1,4 @@
enum {
NSXMLDocumentTidyHTML = 1UL << 9,
NSXMLDocumentTidyXML = 1UL << 10
};

View File

@ -1 +0,0 @@
../../../cocotron/Foundation/xml/NSXMLParser.h

View File

@ -0,0 +1,93 @@
/* Copyright (c) 2007 Christopher J. W. Lloyd
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <Foundation/NSObject.h>
#import <Foundation/NSString.h>
#import <Foundation/NSHashTable.h>
@class NSURL, NSData, NSError, NSXMLParser, NSDictionary, NSMutableArray, NSMutableDictionary;
@protocol NSXMLParserDelegate
- (void)parserDidStartDocument:(NSXMLParser *)parser;
- (void)parserDidEndDocument:(NSXMLParser *)parser;
- (void)parser:(NSXMLParser *)parser foundElementDeclarationWithName:(NSString *)elementName model:(NSString *)model;
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributes;
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName;
- (void)parser:(NSXMLParser *)parser foundAttributeDeclarationWithName:(NSString *)attributeName forElement:(NSString *)elementName type:(NSString *)type defaultValue:(NSString *)defaultValue;
- (void)parser:(NSXMLParser *)parser didStartMappingPrefix:(NSString *)prefix toURI:(NSString *)uri;
- (void)parser:(NSXMLParser *)parser didEndMappingPrefix:(NSString *)prefix;
- (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)cdata;
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string;
- (void)parser:(NSXMLParser *)parser foundComment:(NSString *)comment;
- (void)parser:(NSXMLParser *)parser foundIgnorableWhitespace:(NSString *)whitespace;
- (void)parser:(NSXMLParser *)parser foundExternalEntityDeclarationWithName:(NSString *)entityName publicID:(NSString *)publicID systemID:(NSString *)systemID;
- (void)parser:(NSXMLParser *)parser foundInternalEntityDeclarationWithName:(NSString *)entityName value:(NSString *)value;
- (void)parser:(NSXMLParser *)parser foundNotationDeclarationWithName:(NSString *)name publicID:(NSString *)publicID systemID:(NSString *)systemID;
- (void)parser:(NSXMLParser *)parser foundProcessingInstructionWithTarget:(NSString *)target data:(NSString *)data;
- (void)parser:(NSXMLParser *)parser foundUnparsedEntityDeclarationWithName:(NSString *)name publicID:(NSString *)publicID systemID:(NSString *)systemID notationName:(NSString *)notationName;
- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError;
- (NSData *)parser:(NSXMLParser *)parser resolveExternalEntityName:(NSString *)entityName systemID:(NSString *)systemID;
- (void)parser:(NSXMLParser *)parser validationErrorOccurred:(NSError *)validationError;
@end
@interface NSXMLParser : NSObject {
NSData *_data;
id _delegate;
BOOL _shouldProcessNamespaces;
BOOL _shouldReportNamespacePrefixes;
BOOL _shouldResolveExternalEntities;
NSError *_parserError;
NSString *_systemID;
NSString *_publicID;
NSInteger _columnNumber;
NSInteger _lineNumber;
// parsing state
const uint8_t *_bytes;
NSUInteger _length;
NSRange _range;
NSMutableDictionary *_entityRefContents;
int _state;
unichar _charRef;
NSMutableArray *_elementNameStack;
NSString *_currentAttributeName;
NSMutableDictionary *_currentAttributes;
}
- (instancetype)initWithData:(NSData *)data;
- (instancetype)initWithContentsofURL:(NSURL *)url;
- (id)delegate;
- (BOOL)shouldProcessNamespaces;
- (BOOL)shouldReportNamespacePrefixes;
- (BOOL)shouldResolveExternalEntities;
- (void)setDelegate:delegate;
- (void)setShouldProcessNamespaces:(BOOL)flag;
- (void)setShouldReportNamespacePrefixes:(BOOL)flag;
- (void)setShouldResolveExternalEntities:(BOOL)flag;
- (BOOL)parse;
- (void)abortParsing;
- (NSError *)parserError;
- (NSString *)systemID;
- (NSString *)publicID;
- (NSInteger)columnNumber;
- (NSInteger)lineNumber;
@end

View File

@ -1 +0,0 @@
../../cocotron/Foundation/NSDebug.m

152
src/NSDebug.m Normal file
View File

@ -0,0 +1,152 @@
/* Copyright (c) 2006-2007 Christopher J. W. Lloyd
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <Foundation/NSDebug.h>
#import <Foundation/NSString.h>
#ifdef WINDOWS
#include <windows.h>
#endif
#if defined(LINUX) || defined(__APPLE__) || defined(FREEBSD)
#include <execinfo.h>
#endif
BOOL NSZombieEnabled=NO;
BOOL NSDebugEnabled=NO;
BOOL NSCooperativeThreadsEnabled=NO;
#ifndef DARLING
// Under Darling, this file is symlinked from external/foundation
// But _NSPrintForDebugger is already implemented in NSLog.m
const char* _NSPrintForDebugger(id object) {
if(object && [object respondsToSelector:@selector(description)]) {
return [[object description] UTF8String];
}
return NULL;
}
#endif
#ifndef WINDOWS
void NSCooperativeThreadBlocking() {
}
void NSCooperativeThreadWaiting() {
}
#else
static HANDLE NSCooperativeEvent(){
static HANDLE handle=NULL;
if(handle==NULL)
handle=CreateEvent(NULL,FALSE,FALSE,NULL);
return handle;
}
void NSCooperativeThreadBlocking() {
if(NSCooperativeThreadsEnabled){
SetEvent(NSCooperativeEvent());
}
}
void NSCooperativeThreadWaiting() {
if(NSCooperativeThreadsEnabled){
WaitForSingleObject(NSCooperativeEvent(),0);
}
}
#endif
#define _NS_RETURN_ADDRESS(x) case x: return __builtin_return_address(x + 1)
void *NSFrameAddress(NSUInteger level)
{
void* callstack[128];
if (level > 128) {
return NULL;
}
int i, frameCount = backtrace(callstack, level + 1);
if (frameCount < level + 1) {
return NULL;
}
return callstack[level + 1];
}
unsigned NSCountFrames(void)
{
unsigned x = 0;
while (NSFrameAddress(x + 1) != NULL){
x++;
}
return x;
}
void *NSReturnAddress(int level)
{
switch (level) {
_NS_RETURN_ADDRESS(0);
_NS_RETURN_ADDRESS(1);
_NS_RETURN_ADDRESS(2);
_NS_RETURN_ADDRESS(3);
_NS_RETURN_ADDRESS(4);
_NS_RETURN_ADDRESS(5);
_NS_RETURN_ADDRESS(6);
_NS_RETURN_ADDRESS(7);
_NS_RETURN_ADDRESS(8);
_NS_RETURN_ADDRESS(9);
_NS_RETURN_ADDRESS(10);
_NS_RETURN_ADDRESS(11);
_NS_RETURN_ADDRESS(12);
_NS_RETURN_ADDRESS(13);
_NS_RETURN_ADDRESS(14);
_NS_RETURN_ADDRESS(15);
_NS_RETURN_ADDRESS(16);
_NS_RETURN_ADDRESS(17);
_NS_RETURN_ADDRESS(18);
_NS_RETURN_ADDRESS(19);
_NS_RETURN_ADDRESS(20);
_NS_RETURN_ADDRESS(21);
_NS_RETURN_ADDRESS(22);
_NS_RETURN_ADDRESS(23);
_NS_RETURN_ADDRESS(24);
_NS_RETURN_ADDRESS(25);
_NS_RETURN_ADDRESS(26);
_NS_RETURN_ADDRESS(27);
_NS_RETURN_ADDRESS(28);
_NS_RETURN_ADDRESS(29);
_NS_RETURN_ADDRESS(30);
_NS_RETURN_ADDRESS(31);
_NS_RETURN_ADDRESS(32);
_NS_RETURN_ADDRESS(33);
_NS_RETURN_ADDRESS(34);
_NS_RETURN_ADDRESS(35);
_NS_RETURN_ADDRESS(36);
_NS_RETURN_ADDRESS(37);
_NS_RETURN_ADDRESS(38);
_NS_RETURN_ADDRESS(39);
_NS_RETURN_ADDRESS(40);
_NS_RETURN_ADDRESS(41);
_NS_RETURN_ADDRESS(42);
_NS_RETURN_ADDRESS(43);
_NS_RETURN_ADDRESS(44);
_NS_RETURN_ADDRESS(45);
_NS_RETURN_ADDRESS(46);
_NS_RETURN_ADDRESS(47);
_NS_RETURN_ADDRESS(48);
_NS_RETURN_ADDRESS(49);
_NS_RETURN_ADDRESS(50);
default: return NULL;
}
return NULL;
}

View File

@ -1 +0,0 @@
../../cocotron/Foundation/NSPlatform.m

162
src/NSPlatform.m Normal file
View File

@ -0,0 +1,162 @@
/* Copyright (c) 2006-2007 Christopher J. W. Lloyd
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <Foundation/NSPlatform.h>
#import <Foundation/NSThread.h>
#import <Foundation/NSString.h>
#import <Foundation/NSRaise.h>
#import <Foundation/NSDebug.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSPipe.h>
#import <Foundation/NSMutableDictionary.h>
#import <Foundation/NSNotificationCenter.h>
#import <Foundation/NSFileHandle.h>
#import <Foundation/NSRunLoop.h>
#import <Foundation/NSData.h>
#import <Foundation/NSRaiseException.h>
extern NSString *NSPlatformClassName;
@implementation NSPlatform
+currentPlatform {
return NSThreadSharedInstance(NSPlatformClassName);
}
-(NSInputSource *)parentDeathInputSource {
return nil;
}
-(Class)taskClass {
NSInvalidAbstractInvocation();
return Nil;
}
-(Class)socketClass {
NSInvalidAbstractInvocation();
return Nil;
}
-(Class)socketPortClass {
NSInvalidAbstractInvocation();
return Nil;
}
-(Class)pipeClass {
NSInvalidAbstractInvocation();
return Nil;
}
-(Class)lockClass {
NSInvalidAbstractInvocation();
return Nil;
}
-(Class)recursiveLockClass
{
NSInvalidAbstractInvocation();
return Nil;
}
-(Class)conditionLockClass {
NSInvalidAbstractInvocation();
return Nil;
}
-(Class)conditionClass;
{
NSInvalidAbstractInvocation();
return Nil;
}
-(Class)persistantDomainClass {
NSInvalidAbstractInvocation();
return Nil;
}
-(Class)timeZoneClass {
NSInvalidAbstractInvocation();
return Nil;
}
-(NSString *)userName {
NSInvalidAbstractInvocation();
return nil;
}
-(NSString *)fullUserName {
NSInvalidAbstractInvocation();
return nil;
}
-(NSString *)homeDirectory {
NSInvalidAbstractInvocation();
return nil;
}
-(NSString *)libraryDirectory {
NSInvalidAbstractInvocation();
return nil;
}
-(NSString *)temporaryDirectory {
NSInvalidAbstractInvocation();
return nil;
}
-(NSArray *)arguments {
NSInvalidAbstractInvocation();
return nil;
}
-(NSDictionary *)environment {
NSInvalidAbstractInvocation();
return nil;
}
-(NSString *)hostName {
NSInvalidAbstractInvocation();
return nil;
}
-(NSString *)DNSHostName {
NSInvalidAbstractInvocation();
return nil;
}
-(NSArray *)addressesForDNSHostName:(NSString *)name {
NSInvalidAbstractInvocation();
return nil;
}
-(NSString *)hostNameByAddress:(NSString *)address{
NSInvalidAbstractInvocation();
return nil;
}
-(void *)mapContentsOfFile:(NSString *)path length:(NSUInteger *)length {
NSInvalidAbstractInvocation();
return NULL;
}
-(void)unmapAddress:(void *)ptr length:(NSUInteger)length {
NSInvalidAbstractInvocation();
}
-(BOOL)writeContentsOfFile:(NSString *)path bytes:(const void *)bytes length:(NSUInteger)length options:(NSUInteger)options error:(NSError **)errorp {
NSInvalidAbstractInvocation();
return NO;
}
-(void)checkEnvironmentKey:(NSString *)key value:(NSString *)value {
if([key isEqualToString:@"NSZombieEnabled"]){
if((NSZombieEnabled=[value isEqual:@"YES"]))
NSCLog("NSZombieEnabled=YES");
}
}
@end

View File

@ -1 +0,0 @@
../../cocotron/Foundation/platform_darwin/NSPlatform_darwin.m

129
src/NSPlatform_darwin.m Normal file
View File

@ -0,0 +1,129 @@
/* Copyright (c) 2006-2007 Christopher J. W. Lloyd
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#ifdef __APPLE__
#import <objc/runtime.h>
#import <Foundation/Foundation.h>
#import <Foundation/NSPlatform_darwin.h>
#import <rpc/types.h>
#include <time.h>
#import <sys/param.h>
#include <netdb.h>
#include <unistd.h>
#include <crt_externs.h>
#import <sys/sysctl.h>
// Handy functions for extracting various values from sysctl.
// These should work on FreeBSD as well, though the sysctl names might be different.
static int int32SysctlByName(const char *sysctlName) {
int32_t sysctlInt32Value = 0; size_t len = sizeof(int32_t);
sysctlbyname(sysctlName, &sysctlInt32Value, &len, NULL, 0);
return(sysctlInt32Value);
}
static int64_t int64SysctlByName(const char *sysctlName) {
int64_t sysctlInt64Value = 0; size_t len = sizeof(int64_t);
sysctlbyname(sysctlName, &sysctlInt64Value, &len, NULL, 0);
return(sysctlInt64Value);
}
static NSString *stringSysctlByName(const char *sysctlName) {
char sysctlBuffer[1024]; size_t len = 1020; memset(sysctlBuffer, 0, 1024);
sysctlbyname(sysctlName, &sysctlBuffer[0], &len, NULL, 0);
return([NSString stringWithUTF8String:sysctlBuffer]);
}
NSString *NSPlatformClassName=@"NSPlatform_darwin";
@implementation NSPlatform_darwin
// nanosleep() is IEEE Std 1003.1b-1993, POSIX.1
// This can probably move down to NSPlatform_posix
void NSPlatformSleepThreadForTimeInterval(NSTimeInterval interval) {
double intervalIntegralPart, intervalFractionalPart;
struct timespec intervalTimeSpec;
intervalFractionalPart = modf((double)interval, &intervalIntegralPart);
intervalTimeSpec.tv_sec = (long)(intervalIntegralPart);
intervalTimeSpec.tv_nsec = (long)(intervalFractionalPart * 1.0E9);
nanosleep(&intervalTimeSpec, NULL);
}
/*
SVr4, 4.4BSD (this function first appeared in 4.2BSD).
POSIX.1 does not define these functions, but ISO/IEC
9945-1:1990 mentions them in B.4.4.1.
*/
-(NSString *)hostName {
char buf[MAXHOSTNAMELEN];
gethostname(buf, MAXHOSTNAMELEN);
return [NSString stringWithCString:buf];
}
-(NSString *)DNSHostName {
// if we wanted to get crazy, we could open a dummy socket
// and then get its local address, the do a gethostbyaddr on that...
return [self hostName];
}
NSString * const NSPlatformExecutableDirectory=@"Darwin";
NSString * const NSPlatformResourceNameSuffix=@"darwin";
NSString * const NSPlatformExecutableFileExtension=@"";
NSString * const NSPlatformLoadableObjectFileExtension=@"dylib";
NSString * const NSPlatformLoadableObjectFilePrefix=@"";
- (NSUInteger)processorCount
{
return((NSUInteger)int32SysctlByName("hw.ncpu"));
}
- (NSUInteger)activeProcessorCount
{
return((NSUInteger)int32SysctlByName("hw.activecpu"));
}
-(uint64_t)physicalMemory {
return((uint64_t)int64SysctlByName("hw.memsize"));
}
-(NSUInteger)operatingSystem {
return(NSMACHOperatingSystem);
}
-(NSString *)operatingSystemName {
return(@"NSMACHOperatingSystem");
}
-(NSString *)operatingSystemVersionString {
static NSString *operatingSystemVersionString = NULL;
if(operatingSystemVersionString == NULL) {
NSDictionary *operatingSystemVersionDictionary = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"];
if(operatingSystemVersionDictionary == NULL) { operatingSystemVersionDictionary = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/ServerVersion.plist"]; }
if(operatingSystemVersionDictionary != NULL) {
operatingSystemVersionString = [[NSString alloc] initWithFormat:@"Version %@ (Build %@)", [operatingSystemVersionDictionary objectForKey:@"ProductVersion"], [operatingSystemVersionDictionary objectForKey:@"ProductBuildVersion"]];
} else {
operatingSystemVersionString = [[NSString alloc] initWithFormat:@"%@ Version %@ (Build %@)", stringSysctlByName("kern.ostype"), stringSysctlByName("kern.osrelease"), stringSysctlByName("kern.osversion")];
}
}
return(operatingSystemVersionString);
}
@end
char **NSPlatform_environ() {
return *_NSGetEnviron();
}
#endif

View File

@ -1 +0,0 @@
../../cocotron/Foundation/platform_posix/NSPlatform_posix.m

373
src/NSPlatform_posix.m Normal file
View File

@ -0,0 +1,373 @@
/* Copyright (c) 2006-2007 Christopher J. W. Lloyd
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#if defined(LINUX) || defined(__APPLE__)
#import <objc/runtime.h>
#import <Foundation/Foundation.h>
#ifndef DARLING
#import <Foundation/NSSelectInputSourceSet.h>
#import <Foundation/NSFileHandle_posix.h>
#import <Foundation/NSFileManager_posix.h>
#import <Foundation/NSLock_posix.h>
#import <Foundation/NSRecursiveLock_posix.h>
#import <Foundation/NSCondition_posix.h>
#import <Foundation/NSConditionLock_posix.h>
#import <Foundation/NSPersistantDomain_posix.h>
#import <Foundation/NSTimeZone_posix.h>
#import <Foundation/NSTask_posix.h>
#import <Foundation/NSSocketPort_posix.h>
#import <Foundation/NSPipe_posix.h>
#endif
#import <Foundation/NSPlatform_posix.h>
#import <Foundation/NSRaiseException.h>
#include <pwd.h>
#include <unistd.h>
#import <rpc/types.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/param.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <netdb.h>
#include <time.h>
#include <stdio.h>
#include <poll.h>
#include <pthread.h>
#import <sys/socket.h>
#include <errno.h>
BOOL NSCurrentLocaleIsMetric(){
return NO;
}
@implementation NSPlatform_posix
#ifndef DARLING
-(Class)taskClass {
return [NSTask_posix class];
}
-(Class)socketPortClass {
return [NSSocketPort_posix class];
}
-(Class)pipeClass {
return [NSPipe_posix class];
}
-(Class)lockClass {
return [NSLock_posix class];
}
-(Class)conditionLockClass {
return [NSConditionLock_posix class];
}
-(Class)recursiveLockClass {
return [NSRecursiveLock_posix class];
}
-(Class)persistantDomainClass {
return [NSPersistantDomain_posix class];
}
-(Class)timeZoneClass {
return [NSTimeZone_posix class];
}
-(Class)conditionClass {
return [NSCondition_posix class];
}
#endif
static struct passwd *pwent = NULL;
-(void)_checkAndGetPWEnt {
if (pwent == NULL) {
pwent = getpwuid(getuid());
if (pwent == NULL)
NSRaiseException(NSInternalInconsistencyException, self, _cmd, @"Can't obtain user's information from system");
}
}
-(NSString *)userName {
[self _checkAndGetPWEnt];
return [NSString stringWithCString:pwent->pw_name];
}
-(NSString *)fullUserName {
[self _checkAndGetPWEnt];
return [NSString stringWithCString:pwent->pw_gecos];
}
-(NSString *)homeDirectory {
[self _checkAndGetPWEnt];
return [NSString stringWithCString:pwent->pw_dir];
}
-(NSString *)libraryDirectory {
return [[self homeDirectory] stringByAppendingPathComponent:@".CocotronLibrary"];
}
-(NSString *)temporaryDirectory {
return @"/tmp";
}
-(NSArray *)arguments {
#ifndef DARLING
extern int NSProcessInfoArgc;
extern const char *const *NSProcessInfoArgv;
NSMutableArray *result=[NSMutableArray array];
int i;
for(i=0;i<NSProcessInfoArgc;i++)
[result addObject:[NSString stringWithCString:NSProcessInfoArgv[i]]];
return result;
#else
// this is only called from Cocotron's NSProcessInfo,
// whereas ours takes argc/argv directly from libsystem's
// _NSGetArgc and _NSGetArgv (just like on the real macOS)
return nil;
#endif
}
-(NSDictionary *)environment {
id *objects,*keys;
NSUInteger count;
char **env;
char *keyValue;
NSInteger i,len,max;
env = NSPlatform_environ();
max=0;
for(count=0;env[count];count++)
if((len=strlen(env[count]))>max)
max=len;
keyValue=__builtin_alloca(max+1);
objects=__builtin_alloca(sizeof(id)*count);
keys=__builtin_alloca(sizeof(id)*count);
for(count=0;env[count];count++){
len=strlen(strcpy(keyValue,env[count]));
for(i=0;i<len;i++)
if(keyValue[i]=='=')
break;
keyValue[i]='\0';
objects[count]=[NSString stringWithCString:keyValue+i+1];
keys[count]=[NSString stringWithCString:keyValue];
[self checkEnvironmentKey:keys[count] value:objects[count]];
}
return [[NSDictionary allocWithZone:NULL] initWithObjects:objects forKeys:keys count:count];
}
// silly me, we need microsecond granularity!
NSTimeInterval NSPlatformTimeIntervalSinceReferenceDate() {
NSTimeInterval result;
struct timeval tp;
gettimeofday(&tp, NULL);
result = (((NSTimeInterval)tp.tv_sec) - NSTimeIntervalSince1970);
result += (((NSTimeInterval)tp.tv_usec) / ((NSTimeInterval)1000000.0));
return result;
}
int NSPlatformProcessID() {
return getpid();
}
NSUInteger NSPlatformThreadID() {
return (NSUInteger)pthread_self();
}
-(NSArray *)addressesForDNSHostName:(NSString *)name {
NSMutableArray *result=[NSMutableArray array];
char cString[MAXHOSTNAMELEN+1];
struct hostent *hp;
[name getCString:cString maxLength:MAXHOSTNAMELEN];
if((hp=gethostbyname(cString))==NULL) {
return nil;
}
else {
uint32_t **addr_list=(uint32_t **)hp->h_addr_list;
int i;
for(i=0;addr_list[i]!=NULL;i++){
struct in_addr addr;
NSString *string;
addr.s_addr=*addr_list[i];
string=[NSString stringWithCString:inet_ntoa(addr)];
[result addObject:string];
}
return result;
}
}
-(NSString *)hostNameByAddress:(NSString *)address
{
struct in_addr addr;
struct hostent *remoteHost;
if ([address length] == 0) {
return nil;
}
addr.s_addr = inet_addr([address cString]);
if (addr.s_addr == INADDR_NONE) {
return nil;
}
remoteHost = gethostbyaddr((char *) &addr, 4, AF_INET);
if(remoteHost == NULL)
return nil;
return [NSString stringWithCString:remoteHost->h_name];
}
void NSPlatformLogString(NSString *string) {
fprintf(stderr, "%s\n", [string UTF8String]);
}
void *NSPlatformContentsOfFile(NSString *path,NSUInteger *lengthp) {
int fd = open([path fileSystemRepresentation], O_RDONLY);
char *buf;
off_t pos, total = 0;
*lengthp = 0;
if (fd == -1)
return NULL;
pos = lseek(fd, 0, SEEK_END);
if (pos == -1)
return NULL;
if (lseek(fd, 0, SEEK_SET) == -1)
return NULL;
if ((buf = malloc(pos)) == NULL)
return NULL;
do {
off_t bytesRead = read(fd, buf+total, pos);
if (bytesRead == -1) {
close(fd);
return NULL;
}
total += bytesRead;
} while (total < pos);
close(fd);
*lengthp = pos;
return buf;
}
/*
SVr4, POSIX.1b (formerly POSIX.4), 4.4BSD. Svr4 documents
additional error codes ENXIO and ENODEV.
*/
-(void *)mapContentsOfFile:(NSString *)path length:(NSUInteger *)lengthp {
int fd = open([path fileSystemRepresentation], O_RDONLY);
void *result;
*lengthp = 0;
if (fd == -1)
return NULL;
*lengthp = lseek(fd, 0, SEEK_END);
lseek(fd, 0, SEEK_SET);
result = mmap(NULL, *lengthp, PROT_READ, MAP_SHARED, fd, 0);
if (result == MAP_FAILED)
result = NULL;
close(fd);
return result;
}
-(void)unmapAddress:(void *)ptr length:(NSUInteger)length {
if(length>0){
if (munmap(ptr, length) == -1)
NSRaiseException(NSInvalidArgumentException, self, _cmd, @"munmap() returned -1");
}
}
-(BOOL)writeContentsOfFile:(NSString *)path bytes:(const void *)bytes length:(NSUInteger)length options:(NSUInteger)options error:(NSError **)errorp {
BOOL atomically = (options & NSAtomicWrite);
NSString *atomic = nil;
int fd;
size_t total = 0;
if (atomically) {
do {
atomic = [path stringByAppendingString:@"1"];
} while ([[NSFileManager defaultManager] fileExistsAtPath:atomic] == YES);
fd = open([atomic fileSystemRepresentation], O_WRONLY|O_CREAT, FOUNDATION_FILE_MODE);
if (fd == -1) {
if (errorp) *errorp = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:nil];
return NO;
}
}
else {
fd = open([path fileSystemRepresentation], O_WRONLY|O_CREAT, FOUNDATION_FILE_MODE);
if (fd == -1) {
if (errorp) *errorp = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:nil];
return NO;
}
}
do {
size_t written = write(fd, bytes+total, length);
if (written == -1) {
if (errorp) *errorp = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:nil];
close(fd);
return NO;
}
total += written;
} while (total < length);
close(fd);
if (atomically)
if (rename([atomic fileSystemRepresentation], [path fileSystemRepresentation]) == -1) {
if (errorp) *errorp = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:nil];
return NO;
}
return YES;
}
@end
#endif

View File

@ -1 +0,0 @@
../../cocotron/Foundation/NSException/NSRaise.m

70
src/NSRaise.m Normal file
View File

@ -0,0 +1,70 @@
/* Copyright (c) 2006-2007 Christopher J. W. Lloyd
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <Foundation/NSRaise.h>
#import <Foundation/NSString.h>
#import <objc/runtime.h>
#include <stdio.h>
#ifdef WINDOWS
#include <windows.h>
#endif
// DO NOT USE IN NEW CODE AND REPLACE USAGE. Use NSAssert().
void NSRaiseException(NSString *name,id self,SEL cmd,NSString *fmt,...) {
NSString *where=[NSString stringWithFormat:@"-[%@ %s]",[self class],sel_getName(cmd)];
NSString *why;
va_list args;
va_start(args,fmt);
why=[[[NSString allocWithZone:NULL] initWithFormat:fmt arguments:args] autorelease];
va_end(args);
[NSException raise:name format:@"%@ %@",where,why];
}
void NSCLogThreadId(){
#ifdef WINDOWS
fprintf(stderr,"threadId=%p:tick=%d:",GetCurrentThreadId(),GetTickCount());
#endif
}
void NSCLogNewline(){
#ifdef WINDOWS
fprintf(stderr,"\n",GetCurrentThreadId());
#else
fprintf(stderr,"\n");
#endif
fflush(stderr);
}
void NSCLogFormatWithArguments(const char *format,va_list arguments){
vfprintf(stderr,format,arguments);
fflush(stderr);
}
void NSCLogFormat(const char *format,...){
va_list arguments;
va_start(arguments,format);
NSCLogFormatWithArguments(format,arguments);
va_end(arguments);
}
void NSCLogv(const char *format,va_list arguments) {
NSCLogThreadId();
NSCLogFormatWithArguments(format,arguments);
NSCLogNewline();
}
void NSCLog(const char *format,...) {
va_list arguments;
va_start(arguments,format);
NSCLogv(format,arguments);
va_end(arguments);
}

View File

@ -1 +0,0 @@
../../cocotron/Foundation/NSAttributedString/NSRangeEntries.m

419
src/NSRangeEntries.m Normal file
View File

@ -0,0 +1,419 @@
/* Copyright (c) 2006-2007 Christopher J. W. Lloyd
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <Foundation/NSRangeEntries.h>
#import <Foundation/NSString.h>
/* this could be improved with more merging of adjacent entries after insert/remove */
typedef struct NSRangeEntry {
NSRange range;
void *value;
} NSRangeEntry;
struct NSRangeEntries {
NSUInteger capacity;
NSUInteger count;
struct NSRangeEntry *entries;
BOOL objects;
};
NSRangeEntries *NSCreateRangeToOwnedPointerEntries(NSUInteger capacity) {
NSRangeEntries *result=NSZoneMalloc(NULL,sizeof(NSRangeEntries));
result->capacity=(capacity<4)?4:capacity;
result->count=0;
result->entries=NSZoneMalloc(NULL,sizeof(NSRangeEntry)*result->capacity);
result->objects=NO;
return result;
}
NSRangeEntries *NSCreateRangeToCopiedObjectEntries(NSUInteger capacity) {
NSRangeEntries *result=NSCreateRangeToOwnedPointerEntries(capacity);
result->objects=YES;
return result;
}
void NSFreeRangeEntries(NSRangeEntries *self)
{
if (self == NULL) {
return;
}
NSResetRangeEntries(self);
NSZoneFree(NULL, self->entries);
NSZoneFree(NULL, self);
}
void NSResetRangeEntries(NSRangeEntries *self) {
NSInteger i;
for(i=0;i<self->count;i++)
if(self->objects)
[(id)self->entries[i].value release];
else
NSZoneFree(NULL,self->entries[i].value);
self->count=0;
}
NSUInteger NSCountRangeEntries(NSRangeEntries *self) {
return self->count;
}
static inline void removeEntryAtIndex(NSRangeEntries *self,NSUInteger index){
if(self->objects)
[(id)self->entries[index].value release];
else
NSZoneFree(NULL,self->entries[index].value);
self->count--;
for(;index<self->count;index++)
self->entries[index]=self->entries[index+1];
}
static inline void insertEntryAtIndex(NSRangeEntries *self,NSUInteger index,NSRange range,void *value){
NSInteger i;
self->count++;
if(self->count>self->capacity){
self->capacity*=2;
self->entries=NSZoneRealloc(NULL,self->entries,sizeof(NSRangeEntry)*self->capacity);
}
for(i=self->count;--i>index;)
self->entries[i]=self->entries[i-1];
if(self->objects)
value=[(id)value copy];
self->entries[index].range=range;
self->entries[index].value=value;
}
void NSRangeEntryInsert(NSRangeEntries *self,NSRange range,void *value) {
NSInteger count=self->count;
NSInteger bottom=0,top=count;
NSInteger insertAt=0;
if(count>0){
while(top>=bottom){
NSInteger mid=(bottom+top)/2;
NSRange check=self->entries[mid].range;
if(range.location>=NSMaxRange(check)){
NSInteger next=mid+1;
if(next>=count || NSMaxRange(range)<=self->entries[next].range.location){
insertAt=next;
break;
}
bottom=mid+1;
}
else {
NSInteger prev=mid-1;
if(prev<0 || range.location>=NSMaxRange(self->entries[prev].range)){
insertAt=mid;
break;
}
top=mid-1;
}
}
}
BOOL merged = NO;
if (range.length == 0) {
// We'll just try to merge entries around the location
if(self->objects && insertAt>0 && insertAt<self->count){
id prev = self->entries[insertAt-1].value;
id next = self->entries[insertAt].value;
if ([prev isEqual:next]) {
range = NSUnionRange(self->entries[insertAt].range,self->entries[insertAt-1].range);
self->entries[insertAt-1].range=range;
removeEntryAtIndex(self, insertAt);
}
}
// We don't really want to insert a 0 length entry
return;
} else {
if(self->objects){
if(insertAt>0){
// Check if we can just merge the new entry with the previous one
if(range.length == 0 || [(id)(self->entries[insertAt-1].value) isEqual:value]){
range = NSUnionRange(self->entries[insertAt-1].range,range);
self->entries[insertAt-1].range=range;
merged = YES;
}
}
if(insertAt<self->count){
// Check if we can just merge the new entry with the next one
if(range.length == 0 || [(id)(self->entries[insertAt].value) isEqual:value]){
range = NSUnionRange(self->entries[insertAt].range,range);
if (merged) {
// We merged with both the previous entry and the next one - the next one isn't needed anymore
// so just merge it with the previous one
self->entries[insertAt-1].range=range;
removeEntryAtIndex(self, insertAt);
} else {
self->entries[insertAt].range=range;
}
merged = YES;;
}
}
}
}
if (merged == NO) {
insertEntryAtIndex(self,insertAt,range,value);
}
}
void *NSRangeEntryAtIndex(NSRangeEntries *self,NSUInteger location,NSRange *effectiveRangep) {
NSInteger count=self->count;
NSInteger bottom=0,top=count;
if(top==0){
if(effectiveRangep!=NULL)
*effectiveRangep=NSMakeRange(0,NSNotFound);
return NULL;
}
while(top>=bottom){
NSInteger mid=(bottom+top)/2;
NSRange check=self->entries[mid].range;
if(NSLocationInRange(location,check)){
if(effectiveRangep!=NULL)
*effectiveRangep=check;
return self->entries[mid].value;
}
else if(location>=NSMaxRange(check)){
NSInteger next=mid+1;
if(next>=count){
if(effectiveRangep!=NULL){
effectiveRangep->location=NSMaxRange(check);
effectiveRangep->length=NSNotFound;
}
return NULL;
}
else if(location<self->entries[next].range.location){
if(effectiveRangep!=NULL){
effectiveRangep->location=NSMaxRange(check);
effectiveRangep->length=self->entries[next].range.location-NSMaxRange(check);
}
return NULL;
}
bottom=mid+1;
}
else {
NSInteger prev=mid-1;
if(prev<0){
if(effectiveRangep!=NULL){
effectiveRangep->location=0;
effectiveRangep->length=check.location;
}
return NULL;
}
else if(location>=NSMaxRange(self->entries[prev].range)){
if(effectiveRangep!=NULL){
effectiveRangep->location=NSMaxRange(self->entries[prev].range);
effectiveRangep->length=check.location-effectiveRangep->location;
}
return NULL;
}
top=mid-1;
}
}
NSLog(@"not supposed to get here %d",__LINE__);
return NULL;
}
void *NSRangeEntryAtRange(NSRangeEntries *self,NSRange range) {
NSInteger bottom=0,top=self->count;
if(top>0){
while(top>=bottom){
NSInteger mid=(bottom+top)/2;
NSRange check=self->entries[mid].range;
if(NSEqualRanges(range,check))
return self->entries[mid].value;
else if(range.location>=NSMaxRange(check))
bottom=mid+1;
else
top=mid-1;
}
}
return NULL;
}
NSRangeEnumerator NSRangeEntryEnumerator(NSRangeEntries *self) {
NSRangeEnumerator result;
result.self=self;
result.index=0;
return result;
}
BOOL NSNextRangeEnumeratorEntry(NSRangeEnumerator *state,NSRange *rangep,void **valuep) {
NSRangeEntries *self=state->self;
if(state->index>=self->count)
return NO;
*rangep=self->entries[state->index].range;
*valuep=self->entries[state->index].value;
state->index++;
return YES;
}
void NSRangeEntriesRemoveEntryAtIndex(NSRangeEntries *self,NSUInteger index)
{
removeEntryAtIndex(self, index);
}
void NSRangeEntriesExpandAndWipe(NSRangeEntries *self,NSRange range,NSInteger delta) {
NSInteger count=self->count;
NSUInteger max=NSMaxRange(range);
enum { useBefore, useFirst, useAfter, useNone } useAttributes;
//NSLog(@"expand wipe %d %d by %d",range.location,range.length,delta);
if(range.length>0)
useAttributes=useFirst;
else if(range.location>0)
useAttributes=useBefore;
else
useAttributes=useAfter;
while(--count>=0){
NSRange check=self->entries[count].range;
if(check.location>max)
self->entries[count].range.location+=delta;
else if(check.location==max){
if(useAttributes==useAfter)
self->entries[count].range.length+=delta;
else
self->entries[count].range.location+=delta;
}
else if(check.location>range.location){
if(NSMaxRange(check)<=max)
removeEntryAtIndex(self,count);
else
self->entries[count].range=NSMakeRange(max+delta,NSMaxRange(check)-max);
}
else if(check.location==range.location){
if(delta<0 && -delta>=check.length)
removeEntryAtIndex(self,count);
else if(useAttributes==useFirst){
self->entries[count].range.length=MAX(max+delta,NSMaxRange(check)+delta)-check.location;
useAttributes=useNone;
}
}
else if(check.location<range.location){
if(NSMaxRange(check)<range.location)
break;
if(NSMaxRange(check)>=max)
self->entries[count].range.length+=delta;
else if(useAttributes==useBefore || useAttributes==useFirst)
self->entries[count].range.length=(max+delta)-check.location;
else
self->entries[count].range.length=range.location-check.location;
}
}
}
void NSRangeEntriesDivideAndConquer(NSRangeEntries *self,NSRange range) {
NSInteger count=self->count;
NSUInteger max=NSMaxRange(range);
while(--count>=0){
NSRange check=self->entries[count].range;
if(check.location<max){
NSUInteger maxCheck=NSMaxRange(check);
if(check.location>=range.location){
if(maxCheck<=max) {
// The entry is completely covered by the added range - it's not needed anymore
removeEntryAtIndex(self,count);
} else {
// Remove the part of the entry covered by the added range
self->entries[count].range.length=maxCheck-max;
self->entries[count].range.location=max;
}
} else if(maxCheck<=range.location) {
// The entry is completely before the new range - we're done
break;
} else {
// The end of the entry is covered by the added one
if(maxCheck>max) {
insertEntryAtIndex(self,count+1,NSMakeRange(max,maxCheck-max),self->entries[count].value);
}
// Shorten the entry to make room for the added one
self->entries[count].range.length=range.location-check.location;
}
}
}
}
void NSRangeEntriesDump(NSRangeEntries *self) {
NSInteger i;
NSLog(@"DUMP BEGIN");
for(i=0;i<self->count;i++)
NSLog(@"**** %d %d %p",self->entries[i].range.location, self->entries[i].range.length,self->entries[i].value);
NSLog(@"DUMP END");
}
void NSRangeEntriesDumpAndAbort(NSRangeEntries *self)
{
NSRangeEntriesDump(self);
__builtin_trap();
}
void NSRangeEntriesVerify(NSRangeEntries *self,NSUInteger length) {
#if 0
NSUInteger last=0;
NSInteger i;
for(i=0;i<self->count;i++){
NSRange range=self->entries[i].range;
if(range.length==0 && length>0){
NSLog(@"ZERO RANGE");
NSRangeEntriesDumpAndAbort (self);
}
if(range.location!=last){
NSLog(@"RANGE GAP");
NSRangeEntriesDumpAndAbort (self);
}
last=NSMaxRange(range);
}
if(last!=length){
NSLog(@"SHORT RANGES %d",length);
NSRangeEntriesDumpAndAbort (self);
}
if(self->count==0)
NSLog(@"EMPTY");
#endif
}

View File

@ -1 +0,0 @@
../../cocotron/Foundation/NSSpellEngine.m

115
src/NSSpellEngine.m Normal file
View File

@ -0,0 +1,115 @@
//
// NSSpellEngine.m
// Foundation
//
// Created by Christopher Lloyd on 8/23/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <Foundation/NSSpellEngine.h>
#import <Foundation/NSRaise.h>
#import <Foundation/NSBundle.h>
#import <Foundation/NSArray.h>
@implementation NSSpellEngine
static NSMutableArray *_allSpellEngines=nil;
+(void)initialize {
if(self==[NSSpellEngine class]){
NSArray *allPaths=[[NSBundle bundleForClass:self] pathsForResourcesOfType:@"spellEngine" inDirectory:nil];
int i,count=[allPaths count];
_allSpellEngines=[[NSMutableArray alloc] init];
for(i=0;i<count;i++){
NSString *path=[allPaths objectAtIndex:i];
NSBundle *check=[NSBundle bundleWithPath:path];
Class cls=[check principalClass];
//unused
//NSArray *engines=[cls spellEngines];
[_allSpellEngines addObjectsFromArray:[cls spellEngines]];
}
}
}
+(NSArray *)allSpellEngines {
return _allSpellEngines;
}
+(NSArray *)spellEngines {
return nil;
}
-(NSString *)vendor {
return nil;
}
-(NSArray *)languages {
return nil;
}
-(NSRange)checkGrammarInString:(NSString *)string language:(NSString *)language details:(NSArray **)outDetails {
NSUnimplementedMethod();
return NSMakeRange(0,0);
}
-(NSArray *)checkString:(NSString *)stringToCheck offset:(NSUInteger)offset types:(NSTextCheckingTypes)checkingTypes options:(NSDictionary *)options orthography:(NSOrthography *)orthography wordCount:(NSInteger *)wordCount {
NSUnimplementedMethod();
return nil;
}
-(void)didForgetWord:(NSString *)word inLanguage:(NSString *)language {
NSUnimplementedMethod();
}
-(void)didLearnWord:(NSString *)word inLanguage:(NSString *)language {
NSUnimplementedMethod();
}
-(NSRange)findMisspelledWordInString:(NSString *)stringToCheck language:(NSString *)language wordCount:(NSInteger *)wordCount countOnly:(BOOL)countOnly {
NSUnimplementedMethod();
return NSMakeRange(0,0);
}
-(NSArray *)suggestCompletionsForPartialWordRange:(NSRange)range inString:(NSString *)string language:(NSString *)language {
NSUnimplementedMethod();
return nil;
}
-(NSArray *)suggestGuessesForWord:(NSString *)word inLanguage:(NSString *)language {
NSUnimplementedMethod();
return nil;
}
-(NSRange)spellServer:(NSSpellServer *)sender checkGrammarInString:(NSString *)string language:(NSString *)language details:(NSArray **)outDetails {
return [self checkGrammarInString:string language:language details:outDetails];
}
-(NSArray *)spellServer:(NSSpellServer *)sender checkString:(NSString *)stringToCheck offset:(NSUInteger)offset types:(NSTextCheckingTypes)checkingTypes options:(NSDictionary *)options orthography:(NSOrthography *)orthography wordCount:(NSInteger *)wordCount {
return [self checkString:stringToCheck offset:offset types:checkingTypes options:options orthography:orthography wordCount:wordCount];
}
-(void)spellServer:(NSSpellServer *)sender didForgetWord:(NSString *)word inLanguage:(NSString *)language {
return [self didForgetWord:word inLanguage:language];
}
-(void)spellServer:(NSSpellServer *)sender didLearnWord:(NSString *)word inLanguage:(NSString *)language {
return [self didLearnWord:word inLanguage:language];
}
-(NSRange)spellServer:(NSSpellServer *)sender findMisspelledWordInString:(NSString *)stringToCheck language:(NSString *)language wordCount:(NSInteger *)wordCount countOnly:(BOOL)countOnly {
return [self findMisspelledWordInString:stringToCheck language:language wordCount:wordCount countOnly:countOnly];
}
-(NSArray *)spellServer:(NSSpellServer *)sender suggestCompletionsForPartialWordRange:(NSRange)range inString:(NSString *)string language:(NSString *)language {
return [self suggestCompletionsForPartialWordRange:range inString:string language:language];
}
-(NSArray *)spellServer:(NSSpellServer *)sender suggestGuessesForWord:(NSString *)word inLanguage:(NSString *)language {
return [self suggestGuessesForWord:word inLanguage:language];
}
@end

View File

@ -1 +0,0 @@
../../cocotron/Foundation/NSSpellServer.m

6
src/NSSpellServer.m Normal file
View File

@ -0,0 +1,6 @@
#import <Foundation/NSSpellServer.h>
#import <Foundation/NSString.h>
NSString *const NSGrammarRange=@"NSGrammarRange";
NSString *const NSGrammarUserDescription=@"NSGrammarUserDescription";
NSString *const NSGrammarCorrections=@"NSGrammarCorrections";

View File

@ -1 +0,0 @@
../../cocotron/Foundation/NSUndoManager/NSUndoGroup.m

82
src/NSUndoGroup.m Normal file
View File

@ -0,0 +1,82 @@
/* Copyright (c) 2006-2007 Christopher J. W. Lloyd
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
// Original - David Young <daver@geeks.org>
#import <Foundation/NSUndoGroup.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSInvocation.h>
#import <Foundation/NSString.h>
@implementation NSUndoGroup
+ (NSUndoGroup *)undoGroupWithParentGroup:(NSUndoGroup *)parentGroup
{
return [[[self alloc] initWithParentGroup:parentGroup] autorelease];
}
- (id)initWithParentGroup:(NSUndoGroup *)parentGroup
{
_parentGroup = [parentGroup retain];
_invocations = [[NSMutableArray alloc] init];
return self;
}
- (void)dealloc
{
[_parentGroup release];
[_invocations release];
[super dealloc];
}
- (NSUndoGroup *)parentGroup
{
return _parentGroup;
}
- (void)addInvocation:(NSInvocation *)invocation
{
[_invocations addObject:invocation];
}
- (void)addInvocationsFromArray:(NSArray *)array
{
[_invocations addObjectsFromArray:array];
}
- (NSArray *)invocations
{
return _invocations;
}
- (void)removeInvocationsWithTarget:(id)target
{
int i;
for (i = 0; i < [_invocations count]; ++i)
if ([[_invocations objectAtIndex:i] target] == target)
[_invocations removeObjectAtIndex:i];
}
- (void)invokeInvocations
{
// LIFO
while ([_invocations count] > 0) {
[[_invocations lastObject] invoke];
[_invocations removeLastObject];
}
}
- (NSString *)description
{
return [NSString stringWithFormat:@"<%@[0x%lx] parentGroup: %@, %d invocations>",
[self class], self, _parentGroup, [_invocations count]];
}
@end

View File

@ -1 +0,0 @@
../../cocotron/Foundation/NSUndoManager/NSUndoManager.m

468
src/NSUndoManager.m Normal file
View File

@ -0,0 +1,468 @@
/* Copyright (c) 2006-2007 Christopher J. W. Lloyd
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <Foundation/NSUndoManager.h>
#import <Foundation/NSUndoGroup.h>
#import <Foundation/NSString.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSRunLoop.h>
#import <Foundation/NSNotificationCenter.h>
#import <Foundation/NSException.h>
#import <Foundation/NSRaise.h>
#import <Foundation/NSInvocation.h>
enum _NSUndoManagerState {
NSUndoManagerNormal,
NSUndoManagerUndoing,
NSUndoManagerRedoing
};
NSString * const NSUndoManagerCheckpointNotification=@"NSUndoManagerCheckpointNotification";
NSString * const NSUndoManagerDidOpenUndoGroupNotification=@"NSUndoManagerDidOpenUndoGroupNotification";
NSString * const NSUndoManagerWillCloseUndoGroupNotification=@"NSUndoManagerWillCloseUndoGroupNotification";
NSString * const NSUndoManagerWillUndoChangeNotification=@"NSUndoManagerWillUndoChangeNotification";
NSString * const NSUndoManagerDidUndoChangeNotification=@"NSUndoManagerDidUndoChangeNotification";
NSString * const NSUndoManagerWillRedoChangeNotification=@"NSUndoManagerWillRedoChangeNotification";
NSString * const NSUndoManagerDidRedoChangeNotification=@"NSUndoManagerDidRedoChangeNotification";
@implementation NSUndoManager
-(void)_registerPerform {
if(!_performRegistered){
_performRegistered=YES;
[[NSRunLoop currentRunLoop] performSelector:@selector(runLoopUndo:) target:self argument:nil order:NSUndoCloseGroupingRunLoopOrdering modes:_modes];
}
}
-(void)_unregisterPerform {
if(_performRegistered){
_performRegistered=NO;
[[NSRunLoop currentRunLoop] cancelPerformSelector:@selector(runLoopUndo:) target:self argument:nil];
}
}
- (id)init
{
_undoStack = [[NSMutableArray alloc] init];
_redoStack = [[NSMutableArray alloc] init];
_state = NSUndoManagerNormal;
[self setRunLoopModes:[NSArray arrayWithObject:NSDefaultRunLoopMode]];
[self setGroupsByEvent:YES];
_performRegistered=NO;
return self;
}
- (void)dealloc
{
[self _unregisterPerform];
[_undoStack release];
[_redoStack release];
[_currentGroup release];
[_modes release];
[_actionName release];
[super dealloc];
}
- (NSArray *)runLoopModes
{
return _modes;
}
- (NSUInteger)levelsOfUndo
{
return _levelsOfUndo;
}
- (BOOL)groupsByEvent
{
return _groupsByEvent;
}
- (void)setRunLoopModes:(NSArray *)modes
{
[_modes release];
_modes = [modes retain];
[self _unregisterPerform];
if (_groupsByEvent)
[self _registerPerform];
}
- (void)setLevelsOfUndo:(NSUInteger)levels
{
_levelsOfUndo = levels;
while ([_undoStack count] > _levelsOfUndo)
[_undoStack removeObjectAtIndex:0];
while ([_redoStack count] > _levelsOfUndo)
[_redoStack removeObjectAtIndex:0];
}
- (void)setGroupsByEvent:(BOOL)flag {
_groupsByEvent = flag;
if (_groupsByEvent)
[self _registerPerform];
else
[self _unregisterPerform];
}
- (BOOL)isUndoRegistrationEnabled
{
return (_disableCount == 0);
}
- (void)disableUndoRegistration
{
_disableCount++;
}
- (void)enableUndoRegistration
{
if (_disableCount == 0)
[NSException raise:NSInternalInconsistencyException
format:@"Attempt to enable registration with no disable message in effect"];
_disableCount--;
}
- (void)beginUndoGrouping
{
NSUndoGroup *undoGroup = [NSUndoGroup undoGroupWithParentGroup:_currentGroup];
if (!([_currentGroup parentGroup] == nil && _state == NSUndoManagerUndoing))
[[NSNotificationCenter defaultCenter] postNotificationName:NSUndoManagerCheckpointNotification
object:self];
[_currentGroup release];
_currentGroup = [undoGroup retain];
[[NSNotificationCenter defaultCenter] postNotificationName:NSUndoManagerDidOpenUndoGroupNotification object:self];
}
- (void)endUndoGrouping
{
NSMutableArray *stack = nil;
NSUndoGroup *parentGroup = [[_currentGroup parentGroup] retain];
if (_currentGroup == nil)
[NSException raise:NSInternalInconsistencyException
format:@"endUndoGrouping called without first calling beginUndoGrouping"];
[[NSNotificationCenter defaultCenter] postNotificationName:NSUndoManagerCheckpointNotification
object:self];
if (parentGroup == nil && [[_currentGroup invocations] count] > 0) {
switch (_state) {
case NSUndoManagerNormal:
[[NSNotificationCenter defaultCenter] postNotificationName:NSUndoManagerWillCloseUndoGroupNotification object:self];
case NSUndoManagerRedoing:
stack = _undoStack;
break;
case NSUndoManagerUndoing:
stack = _redoStack;
break;
}
[stack addObject:_currentGroup];
if (_levelsOfUndo > 0)
if ([stack count] > _levelsOfUndo)
[stack removeObjectAtIndex:0];
}
else {
// a nested group was closed. fold its invocations into its parent, preserving the
// order for future changes on the parent.
[parentGroup addInvocationsFromArray:[_currentGroup invocations]];
}
[_currentGroup release];
_currentGroup = parentGroup;
}
- (NSInteger)groupingLevel
{
NSUndoGroup *temp = _currentGroup;
int level = (_currentGroup != nil);
while ((temp = [temp parentGroup])!=nil)
level++;
return level;
}
- (void)runLoopUndo:(id)dummy
{
if (_groupsByEvent == YES) {
if (_currentGroup != nil)
[self endUndoGrouping];
_performRegistered=NO;
}
}
- (BOOL)canUndo
{
if ([_undoStack count] > 0)
return YES;
if ([[_currentGroup invocations] count] > 0)
return YES;
return NO;
}
- (void)undoNestedGroup
{
NSUndoGroup *undoGroup;
if (_currentGroup != nil)
[NSException raise:NSInternalInconsistencyException
format:@"undo called with open nested group"];
[[NSNotificationCenter defaultCenter] postNotificationName:NSUndoManagerCheckpointNotification
object:self];
[[NSNotificationCenter defaultCenter] postNotificationName:NSUndoManagerWillUndoChangeNotification
object:self];
_state = NSUndoManagerUndoing;
undoGroup = [[_undoStack lastObject] retain];
[_undoStack removeLastObject];
[self beginUndoGrouping];
[undoGroup invokeInvocations];
[self endUndoGrouping];
[undoGroup release];
_state = NSUndoManagerNormal;
[[NSNotificationCenter defaultCenter] postNotificationName:NSUndoManagerDidUndoChangeNotification
object:self];
}
- (void)undo
{
if ([self groupingLevel] == 1)
[self endUndoGrouping];
[self undoNestedGroup];
}
- (BOOL)isUndoing
{
return (_state == NSUndoManagerUndoing);
}
- (BOOL)canRedo
{
[[NSNotificationCenter defaultCenter] postNotificationName:NSUndoManagerCheckpointNotification
object:self];
return ([_redoStack count] > 0);
}
- (void)redo
{
NSUndoGroup *undoGroup;
if (_state == NSUndoManagerUndoing)
[NSException raise:NSInternalInconsistencyException
format:@"redo called while undoing"];
[[NSNotificationCenter defaultCenter] postNotificationName:NSUndoManagerCheckpointNotification
object:self];
[[NSNotificationCenter defaultCenter] postNotificationName:NSUndoManagerWillRedoChangeNotification
object:self];
_state = NSUndoManagerRedoing;
undoGroup = [[_redoStack lastObject] retain];
[_redoStack removeLastObject];
[self beginUndoGrouping];
[undoGroup invokeInvocations];
[self endUndoGrouping];
[undoGroup release];
_state = NSUndoManagerNormal;
[[NSNotificationCenter defaultCenter] postNotificationName:NSUndoManagerDidRedoChangeNotification
object:self];
}
- (BOOL)isRedoing
{
return (_state == NSUndoManagerRedoing);
}
- (void)registerUndoWithTarget:(id)target selector:(SEL)selector object:(id)object
{
NSInvocation *invocation;
NSMethodSignature *signature;
if (_disableCount > 0)
return;
if (_groupsByEvent && _currentGroup == nil) {
[self _registerPerform];
[self beginUndoGrouping];
}
if (_currentGroup == nil)
[NSException raise:NSInternalInconsistencyException
format:@"forwardInvocation called without first opening an undo group"];
signature = [target methodSignatureForSelector:selector];
invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setTarget:target];
[invocation setSelector:selector];
[invocation setArgument:&object atIndex:2];
[invocation retainArguments];
[_currentGroup addInvocation:invocation];
if (_state == NSUndoManagerNormal)
[_redoStack removeAllObjects];
}
- (void)removeAllActions
{
[_undoStack removeAllObjects];
[_redoStack removeAllObjects];
_disableCount = 0;
}
- (void)removeAllActionsWithTarget:(id)target
{
NSUndoGroup *undoGroup;
int i;
[_currentGroup removeInvocationsWithTarget:target];
for (i = 0; i < [_undoStack count]; ++i) {
undoGroup = [_undoStack objectAtIndex:i];
[undoGroup removeInvocationsWithTarget:target];
if ([[undoGroup invocations] count] == 0)
[_undoStack removeObject:undoGroup];
}
for (i = 0; i < [_redoStack count]; ++i) {
undoGroup = [_redoStack objectAtIndex:i];
[undoGroup removeInvocationsWithTarget:target];
if ([[undoGroup invocations] count] == 0)
[_redoStack removeObject:undoGroup];
}
}
- (id)prepareWithInvocationTarget:(id)target
{
_preparedTarget = [target retain];
return self;
}
-(NSMethodSignature *)methodSignatureForSelector:(SEL)selector {
return [_preparedTarget methodSignatureForSelector:selector];
}
- (void)forwardInvocation:(NSInvocation *)invocation
{
if (_disableCount > 0)
return;
if (_preparedTarget == nil)
[NSException raise:NSInternalInconsistencyException
format:@"forwardInvocation called without first preparing a target"];
if (_groupsByEvent && _currentGroup == nil) {
[self _registerPerform];
[self beginUndoGrouping];
}
if (_currentGroup == nil)
[NSException raise:NSInternalInconsistencyException
format:@"forwardInvocation called without first opening an undo group"];
[invocation setTarget:_preparedTarget];
[_currentGroup addInvocation:invocation];
[invocation retainArguments];
if (_state == NSUndoManagerNormal)
[_redoStack removeAllObjects];
[_preparedTarget release];
_preparedTarget = nil;
}
- (void)setActionName:(NSString *)name
{
[_actionName release];
_actionName = [name retain];
}
- (NSString *)undoActionName
{
if ([self canUndo])
return _actionName;
return nil;
}
- (NSString *)undoMenuItemTitle
{
return [self undoMenuTitleForUndoActionName:[self undoActionName]];
}
// needs localization
- (NSString *)undoMenuTitleForUndoActionName:(NSString *)name
{
if (name != nil) {
if ([name length] > 0)
return [NSString stringWithFormat:@"Undo %@", name];
return @"Undo";
}
return name;
}
- (NSString *)redoActionName
{
if ([self canRedo])
return _actionName;
return nil;
}
- (NSString *)redoMenuItemTitle
{
return [self redoMenuTitleForUndoActionName:[self redoActionName]];
}
- (NSString *)redoMenuTitleForUndoActionName:(NSString *)name
{
if (name != nil) {
if ([name length] > 0)
return [NSString stringWithFormat:@"Redo %@", name];
return @"Redo";
}
return name;
}
- (void)clearRedoStackIfStateIsNormal
{
if (_state == NSUndoManagerNormal)
[_redoStack removeAllObjects];
}
@end

View File

@ -1 +0,0 @@
../../cocotron/Foundation/xml/NSXMLDTD.m

97
src/NSXMLDTD.m Normal file
View File

@ -0,0 +1,97 @@
/* Copyright (c) 2007 Christopher J. W. Lloyd
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <Foundation/NSXMLDTD.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSRaise.h>
@implementation NSXMLDTD
+(NSXMLDTDNode *)predefinedEntityDeclarationForName:(NSString *)name {
NSUnimplementedMethod();
return nil;
}
-initWithData:(NSData *)data options:(NSUInteger)options error:(NSError **)error {
NSUnimplementedMethod();
return nil;
}
-initWithContentsOfURL:(NSURL *)url options:(NSUInteger)options error:(NSError **)error {
NSUnimplementedMethod();
return nil;
}
-(NSString *)publicID {
return _publicID;
}
-(NSString *)systemID {
return _systemID;
}
-(NSXMLDTDNode *)attributeDeclarationForName:(NSString *)attributeName elementName:(NSString *)elementName {
NSUnimplementedMethod();
return nil;
}
-(NSXMLDTDNode *)elementDeclarationForName:(NSString *)name {
NSUnimplementedMethod();
return nil;
}
-(NSXMLDTDNode *)entityDeclarationForName:(NSString *)name {
NSUnimplementedMethod();
return nil;
}
-(NSXMLDTDNode *)notationDeclarationForName:(NSString *)name {
NSUnimplementedMethod();
return nil;
}
-(void)setPublicID:(NSString *)publicID {
publicID=[publicID copy];
[_publicID release];
_publicID=publicID;
}
-(void)setSystemID:(NSString *)systemID {
systemID=[systemID copy];
[_systemID release];
_systemID=systemID;
}
-(void)setChildren:(NSArray *)children {
[_children setArray:children];
}
-(void)addChild:(NSXMLNode *)node {
[_children addObject:node];
}
-(void)insertChild:(NSXMLNode *)child atIndex:(NSUInteger)index {
[_children insertObject:child atIndex:index];
}
-(void)insertChildren:(NSArray *)children atIndex:(NSUInteger)index {
NSInteger i,count=[children count];
for(i=0;i<count;i++)
[_children insertObject:[children objectAtIndex:i] atIndex:index+i];
}
-(void)removeChildAtIndex:(NSUInteger)index {
[_children removeObjectAtIndex:index];
}
-(void)replaceChildAtIndex:(NSUInteger)index withNode:(NSXMLNode *)node {
[_children replaceObjectAtIndex:index withObject:node];
}
@end

View File

@ -1 +0,0 @@
../../cocotron/Foundation/xml/NSXMLDTDNode.m

60
src/NSXMLDTDNode.m Normal file
View File

@ -0,0 +1,60 @@
/* Copyright (c) 2007 Christopher J. W. Lloyd
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <Foundation/NSXMLDTDNode.h>
#import <Foundation/NSString.h>
@implementation NSXMLDTDNode
-initWithXMLString:(NSString *)string {
return nil;
}
-(NSXMLDTDNodeKind)DTDKind {
return _dtdKind;
}
-(BOOL)isExternal {
return 0;
}
-(NSString *)notationName {
return _notationName;
}
-(NSString *)publicID {
return _publicID;
}
-(NSString *)systemID {
return _systemID;
}
-(void)setDTDKind:(NSXMLDTDNodeKind)kind {
_dtdKind=kind;
}
-(void)setNotationName:(NSString *)name {
name=[name copy];
[_notationName release];
_notationName=name;
}
-(void)setPublicID:(NSString *)publicID {
publicID=[publicID copy];
[_publicID release];
_publicID=publicID;
}
-(void)setSystemID:(NSString *)systemID {
systemID=[systemID copy];
[_systemID release];
_systemID=systemID;
}
@end

View File

@ -1 +0,0 @@
../../cocotron/Foundation/xml/NSXMLDocument.m

259
src/NSXMLDocument.m Normal file
View File

@ -0,0 +1,259 @@
/* Copyright (c) 2007 Christopher J. W. Lloyd
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <Foundation/NSXMLDocument.h>
#import <Foundation/NSXMLElement.h>
#import <Foundation/NSXMLDTD.h>
#import <Foundation/NSXMLParser.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSData.h>
#import <Foundation/NSRaise.h>
@implementation NSXMLDocument
+(Class)replacementClassForClass:(Class)class {
return class;
}
-init {
[super initWithKind:NSXMLDocumentKind options:NSXMLNodeOptionsNone];
return self;
}
-initWithRootElement:(NSXMLElement *)element {
NSUnimplementedMethod();
return nil;
}
-initWithXMLString:(NSString *)string options:(NSUInteger)options error:(NSError **)error {
NSUnimplementedMethod();
return nil;
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributes {
NSXMLElement *element=[[NSXMLElement alloc] initWithName:elementName];
// NSLog(@"element=%@",[element name]);
[element setAttributesAsDictionary:attributes];
NSXMLElement *parent=[_elementStack lastObject];
// NSLog(@"parent=%@",[parent name]);
[parent addChild:element];
[_elementStack addObject:element];
if([_elementStack count]==1)
[self addChild:element];
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName {
[_elementStack removeLastObject];
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
NSXMLElement *element=[_elementStack lastObject];
// NSLog(@"foundCharacters=%@",string);
[element setStringValue:[[element stringValue] stringByAppendingString:string]];
}
-(void)parser:(NSXMLParser *)parser foundIgnorableWhitespace:(NSString *)whitespace {
if(_options&NSXMLDocumentTidyXML)
return;
[self parser:parser foundCharacters:whitespace];
}
-initWithData:(NSData *)data options:(NSUInteger)options error:(NSError **)error {
[super initWithKind:NSXMLDocumentKind options:NSXMLNodeOptionsNone];
// NSLog(@"xml=%@",[[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease]);
NSXMLParser *parser=[[NSXMLParser alloc] initWithData:data];
[parser setDelegate:self];
_options=options;
_elementStack=[[NSMutableArray alloc] init];
if(![parser parse]){
[self dealloc];
if(error!=NULL)
*error=[[[parser parserError] retain] autorelease];
[parser release];
return nil;
}
[parser release];
return self;
}
-initWithContentsOfURL:(NSURL *)url options:(NSUInteger)options error:(NSError **)error {
NSData *data=[NSData dataWithContentsOfURL:url options:0 error:error];
if(data==nil){
[self dealloc];
return nil;
}
return [self initWithData:data options:options error:error];
}
-(void)dealloc {
[_elementStack release];
[_rootElement release];
[super dealloc];
}
-(NSXMLDocumentContentKind)documentContentKind {
return _contentKind;
}
-(NSString *)version {
return _version;
}
-(NSString *)characterEncoding {
return _characterEncoding;
}
-(NSString *)MIMEType {
return _mimeType;
}
-(BOOL)isStandalone {
return _isStandalone;
}
-(NSXMLElement *)rootElement {
return [_children count]?[_children objectAtIndex:0]:nil;
}
-(NSXMLDTD *)DTD {
return _dtd;
}
-(NSString *)URI {
return _uri;
}
-(void)setDocumentContentKind:(NSXMLDocumentContentKind)kind {
_contentKind=kind;
}
-(void)setCharacterEncoding:(NSString *)encoding {
encoding=[encoding copy];
[_characterEncoding release];
_characterEncoding=encoding;
}
-(void)setVersion:(NSString *)version {
version=[version copy];
[_version release];
_version=version;
}
-(void)setMIMEType:(NSString *)mimeType {
mimeType=[mimeType copy];
[_mimeType release];
_mimeType=mimeType;
}
-(void)setStandalone:(BOOL)flag {
_isStandalone=flag;
}
-(void)setRootElement:(NSXMLNode *)element {
element=[element retain];
[_rootElement release];
_rootElement=(NSXMLElement *)element;
}
-(void)setDTD:(NSXMLDTD *)dtd {
dtd=[dtd retain];
[_dtd release];
_dtd=dtd;
}
-(void)setURI:(NSString *)uri {
uri=[uri copy];
[_uri release];
_uri=uri;
}
-(void)setChildren:(NSArray *)children {
[_children setArray:children];
}
-(void)addChild:(NSXMLNode *)node {
[_children addObject:node];
}
-(void)insertChild:(NSXMLNode *)child atIndex:(NSUInteger)index {
[_children insertObject:child atIndex:index];
}
-(void)insertChildren:(NSArray *)children atIndex:(NSUInteger)index {
NSInteger i,count=[children count];
for(i=0;i<count;i++)
[_children insertObject:[children objectAtIndex:i] atIndex:index+i];
}
-(void)removeChildAtIndex:(NSUInteger)index {
[_children removeObjectAtIndex:index];
}
-(void)replaceChildAtIndex:(NSUInteger)index withNode:(NSXMLNode *)node {
[_children replaceObjectAtIndex:index withObject:node];
}
-(BOOL)validateAndReturnError:(NSError **)error {
NSUnimplementedMethod();
return NO;
}
-(NSString *)XMLStringWithOptions:(NSUInteger)options {
NSMutableString *result=[NSMutableString string];
[result appendString:@"<?xml version=\"1.0\" standalone=\"yes\"?>"];
for(NSXMLNode *node in _children)
[result appendString:[node XMLStringWithOptions:options]];
return result;
}
-(NSData *)XMLData {
return [self XMLDataWithOptions:NSXMLNodeOptionsNone];
}
-(NSData *)XMLDataWithOptions:(NSUInteger)options {
NSString *string=[self XMLStringWithOptions:options];
return [string dataUsingEncoding:NSUTF8StringEncoding];
}
-objectByApplyingXSLT:(NSData *)xslt arguments:(NSDictionary *)arguments error:(NSError *)error {
NSUnimplementedMethod();
return nil;
}
-objectByApplyingXSLTAtURL:(NSURL *)url arguments:(NSDictionary *)arguments error:(NSError *)error {
NSUnimplementedMethod();
return nil;
}
-objectByApplyingXSLTString:(NSString *)string arguments:(NSDictionary *)arguments error:(NSError *)error {
NSUnimplementedMethod();
return nil;
}
@end

View File

@ -1 +0,0 @@
../../cocotron/Foundation/xml/NSXMLElement.m

241
src/NSXMLElement.m Normal file
View File

@ -0,0 +1,241 @@
/* Copyright (c) 2007 Christopher J. W. Lloyd
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <Foundation/NSXMLElement.h>
#import <Foundation/NSXMLNode.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSEnumerator.h>
#import <Foundation/NSRaise.h>
@implementation NSXMLElement
-initWithName:(NSString *)name {
[super initWithKind:NSXMLElementKind options:NSXMLNodeOptionsNone];
_name=[name copy];
_attributes=[[NSMutableDictionary alloc] init];
_namespaces=[[NSMutableDictionary alloc] init];
return self;
}
-initWithName:(NSString *)name stringValue:(NSString *)string {
[self initWithName:name];
_value=[string copy];
return self;
}
-initWithName:(NSString *)name URI:(NSString *)uri {
NSUnimplementedMethod();
return 0;
}
-initWithXMLString:(NSString *)xml error:(NSError **)error {
NSUnimplementedMethod();
return 0;
}
-copyWithZone:(NSZone *)zone {
NSUnimplementedMethod();
return 0;
}
-(NSArray *)attributes {
return [_attributes allValues];
}
-(NSXMLNode *)attributeForLocalName:(NSString *)name URI:(NSString *)uri {
NSUnimplementedMethod();
return 0;
}
-(NSXMLNode *)attributeForName:(NSString *)name {
return [_attributes objectForKey:name];
}
-(NSArray *)elementsForLocalName:(NSString *)localName URI:(NSString *)uri {
NSUnimplementedMethod();
return 0;
}
-(NSArray *)elementsForName:(NSString *)name {
NSMutableArray *result=[NSMutableArray array];
for(NSXMLNode *node in _children)
if([[node name] isEqualToString:name])
[result addObject:node];
return result;
}
-(NSArray *)namespaces {
NSUnimplementedMethod();
return 0;
}
-(NSXMLNode *)namespaceForPrefix:(NSString *)prefix {
NSUnimplementedMethod();
return 0;
}
-(void)setAttributes:(NSArray *)attributes {
NSInteger i,count=[attributes count];
[_attributes removeAllObjects];
for(i=0;i<count;i++){
NSXMLNode *add=[attributes objectAtIndex:i];
[_attributes setObject:add forKey:[add name]];
}
}
-(void)setAttributesAsDictionary:(NSDictionary *)attributes {
NSEnumerator *state=[attributes keyEnumerator];
NSString *name;
[_attributes removeAllObjects];
while((name=[state nextObject])!=nil){
NSString *value=[attributes objectForKey:name];
NSXMLNode *node=[NSXMLNode attributeWithName:name stringValue:value];
[_attributes setObject:node forKey:name];
}
}
-(void)setChildren:(NSArray *)children {
[_children setArray:children];
}
-(void)setNamespaces:(NSArray *)namespaces {
[_namespaces removeAllObjects];
}
-(void)addChild:(NSXMLNode *)node {
node->_parent=self;
[_children addObject:node];
}
-(void)insertChild:(NSXMLNode *)child atIndex:(NSUInteger)index {
[_children insertObject:child atIndex:index];
}
-(void)insertChildren:(NSArray *)children atIndex:(NSUInteger)index {
NSInteger i,count=[children count];
for(i=0;i<count;i++)
[_children insertObject:[children objectAtIndex:i] atIndex:index+i];
}
-(void)removeChildAtIndex:(NSUInteger)index {
[_children removeObjectAtIndex:index];
}
-(void)replaceChildAtIndex:(NSUInteger)index withNode:(NSXMLNode *)node {
[_children replaceObjectAtIndex:index withObject:node];
}
-(void)addAttribute:(NSXMLNode *)attribute {
[_attributes setObject:attribute forKey:[attribute name]];
}
-(void)removeAttributeForName:(NSString *)name {
[_attributes removeObjectForKey:name];
}
-(void)addNamespace:(NSXMLNode *)namespace {
[_namespaces setObject:namespace forKey:[namespace prefix]];
}
-(void)removeNamespaceForPrefix:(NSString *)prefix {
[_namespaces removeObjectForKey:prefix];
}
-(void)resolveNamespaceForName:(NSString *)name {
NSUnimplementedMethod();
}
-(void)resolvePrefixForNamespaceURI:(NSString *)uri {
NSUnimplementedMethod();
}
-(void)normalizeAdjacentTextNodesPreservingCDATA:(BOOL)preserve {
NSUnimplementedMethod();
}
static void appendStringWithCharacterEntities(NSMutableString *result,NSString *string){
NSUInteger i,length=[string length],location=0;
unichar buffer[length];
[string getCharacters:buffer];
for(i=0;i<length;i++){
unichar code=buffer[i];
NSString *entity=nil;
if(code=='<')
entity=@"&lt;";
else if(code=='&')
entity=@"&amp;";
else if(code=='>')
entity=@"&gt;";
else if(code=='\"')
entity=@"&quot;";
else if(code=='\'')
entity=@"&apos;";
if(entity!=nil){
if(i-location>0){
NSString *chunk=[[NSString alloc] initWithCharacters:buffer+location length:i-location];
[result appendString:chunk];
[chunk release];
}
[result appendString:entity];
location=i+1;
}
}
if(location==0)
[result appendString:string];
else if(i-location>0){
NSString *chunk=[[NSString alloc] initWithCharacters:buffer+location length:i-location];
[result appendString:chunk];
[chunk release];
}
}
-(NSString *)XMLStringWithOptions:(NSUInteger)options {
NSMutableString *result=[NSMutableString string];
[result appendString:@"<"];
[result appendString:[self name]];
for(NSXMLNode *attribute in [self attributes]){
[result appendString:@" "];
[result appendString:[attribute XMLStringWithOptions:options]];
}
[result appendString:@">"];
for(NSXMLNode *element in [self children]){
[result appendString:@" "];
[result appendString:[element XMLStringWithOptions:options]];
}
appendStringWithCharacterEntities(result,[self stringValue]);
[result appendString:@"</"];
[result appendString:[self name]];
[result appendString:@">\n"];
return result;
}
@end

View File

@ -1 +0,0 @@
../../cocotron/Foundation/xml/NSXMLNode.m

361
src/NSXMLNode.m Normal file
View File

@ -0,0 +1,361 @@
/* Copyright (c) 2007 Christopher J. W. Lloyd
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <Foundation/NSXMLNode.h>
#import <Foundation/NSXMLDTDNode.h>
#import <Foundation/NSXMLElement.h>
#import <Foundation/NSXMLDocument.h>
#import <Foundation/NSRaise.h>
#import <Foundation/NSArray.h>
@implementation NSXMLNode
+document {
return [[[NSXMLDocument alloc] init] autorelease];
}
+documentWithRootElement:(NSXMLElement *)element {
return [[[NSXMLDocument alloc] initWithRootElement:element] autorelease];
}
+elementWithName:(NSString *)name {
return [[[NSXMLElement alloc] initWithName:name] autorelease];
}
+elementWithName:(NSString *)name children:(NSArray *)children attributes:(NSArray *)attributes {
NSXMLElement *result=[[[NSXMLElement alloc] initWithName:name] autorelease];
[result setChildren:children];
[result setAttributes:attributes];
return result;
}
+elementWithName:(NSString *)name stringValue:(NSString *)string {
return [[[NSXMLElement alloc] initWithName:name stringValue:string] autorelease];
}
+attributeWithName:(NSString *)name stringValue:(NSString *)string {
NSXMLNode *result=[[[self alloc] initWithKind:NSXMLAttributeKind] autorelease];
[result setName:name];
[result setStringValue:string];
return result;
}
+commentWithStringValue:(NSString *)string {
NSXMLNode *result=[[[self alloc] initWithKind:NSXMLCommentKind] autorelease];
[result setStringValue:string];
return result;
}
+textWithStringValue:(NSString *)string {
NSXMLNode *result=[[[self alloc] initWithKind:NSXMLTextKind] autorelease];
[result setStringValue:string];
return result;
}
+processingInstructionWithName:(NSString *)name stringValue:(NSString *)string {
NSXMLNode *result=[[[self alloc] initWithKind:NSXMLProcessingInstructionKind] autorelease];
[result setName:name];
[result setStringValue:string];
return result;
}
+DTDNodeWithXMLString:(NSString *)string {
return [[[NSXMLDTDNode alloc] initWithXMLString:string] autorelease];
}
+namespaceWithName:(NSString *)name stringValue:(NSString *)string {
NSXMLNode *result=[[[self alloc] initWithKind:NSXMLNamespaceKind] autorelease];
[result setName:name];
[result setStringValue:string];
return result;
}
+(NSXMLNode *)predefinedNamespaceForPrefix:(NSString *)prefix {
NSUnimplementedMethod();
return nil;
}
+(NSString *)prefixForName:(NSString *)name {
NSUnimplementedMethod();
return nil;
}
+(NSString *)localNameForName:(NSString *)name {
NSUnimplementedMethod();
return nil;
}
-initWithKind:(NSXMLNodeKind)kind {
return [self initWithKind:kind options:NSXMLNodeOptionsNone];
}
-initWithKind:(NSXMLNodeKind)kind options:(NSUInteger)options {
_parent=nil;
_children=[[NSMutableArray alloc] init];
_index=0;
_kind=kind;
_options=options;
_name=nil;
_value=@""; // Behavior is empty string not null
return self;
}
-(void)dealloc {
_parent=nil;
[_children release];
[_name release];
[_value release];
[super dealloc];
}
-copyWithZone:(NSZone *)zone {
NSXMLNode *copy=NSCopyObject(self,0,zone);
copy->_name=[_name copy];
copy->_value=[_value copy];
return copy;
}
-(NSUInteger)index {
return _index;
}
-(NSXMLNodeKind)kind {
return _kind;
}
-(NSUInteger)level {
NSUnimplementedMethod();
return 0;
}
-(NSString *)localName {
NSUnimplementedMethod();
return nil;
}
-(NSString *)name {
return _name;
}
-(NSXMLNode *)nextNode {
NSUnimplementedMethod();
return nil;
}
-(NSXMLNode *)nextSibling {
NSUnimplementedMethod();
return nil;
}
-(NSString *)stringValue {
return _value;
}
-(NSString *)URI {
NSUnimplementedMethod();
return nil;
}
-objectValue {
return _value;
}
-(NSXMLNode *)parent {
return _parent;
}
-(NSString *)prefix {
NSUnimplementedMethod();
return nil;
}
-(NSXMLNode *)previousNode {
NSUnimplementedMethod();
return nil;
}
-(NSXMLNode *)previousSibling {
NSUnimplementedMethod();
return nil;
}
-(NSXMLDocument *)rootDocument {
NSUnimplementedMethod();
return nil;
}
-(NSUInteger)childCount {
return [_children count];
}
-(NSArray *)children {
return _children;
}
-(NSXMLNode *)childAtIndex:(NSUInteger)index {
return [_children objectAtIndex:index];
}
-(void)setName:(NSString *)name {
name=[name copy];
[_name release];
_name=name;
}
-(void)setObjectValue:object {
object=[object retain];
[_value release];
_value=object;
}
-(void)setStringValue:(NSString *)string {
string=[string copy];
[_value release];
_value=string;
}
-(void)setStringValue:(NSString *)string resolvingEntities:(BOOL)resolveEntities {
NSUnimplementedMethod();
}
-(void)detach {
// [_parent removeChild:self];
_parent=nil;
}
-(NSArray *)nodesForXPath:(NSString *)xpath error:(NSError **)error {
NSMutableArray *result=[NSMutableArray array];
NSRange range=[xpath rangeOfString:@"/"];
if(range.location==NSNotFound){
for(NSXMLNode *node in _children){
if([xpath isEqualToString:@"*"])
[result addObject:node];
if([xpath isEqualToString:[node name]])
[result addObject:node];
}
}
else {
NSString *firstComponent=[xpath substringWithRange:NSMakeRange(0,range.location)];
NSString *remainder=[xpath substringFromIndex:NSMaxRange(range)];
for(NSXMLNode *node in _children){
if([firstComponent isEqualToString:@"*"])
[result addObjectsFromArray:[node nodesForXPath:remainder error:error]];
if([firstComponent isEqualToString:[node name]])
[result addObjectsFromArray:[node nodesForXPath:remainder error:error]];
}
}
return result;
}
-(NSArray *)objectsForXQuery:(NSString *)xquery constants:(NSDictionary *)constants error:(NSError **)error {
NSUnimplementedMethod();
return nil;
}
-(NSArray *)objectsForXQuery:(NSString *)xquery error:(NSError **)error {
NSUnimplementedMethod();
return nil;
}
-(NSString *)XMLString {
return [self XMLStringWithOptions:0];
}
-(NSString *)XMLStringWithOptions:(NSUInteger)options {
NSMutableString *result=[NSMutableString string];
switch([self kind]){
case NSXMLInvalidKind:
break;
case NSXMLDocumentKind:
// Handled in subclass
break;
case NSXMLElementKind:
// Handled in subclass
break;
case NSXMLAttributeKind:
[result appendString:[self name]];
[result appendString:@"=\""];
[result appendString:[self stringValue]];
[result appendString:@"\""];
break;
case NSXMLNamespaceKind:
break;
case NSXMLProcessingInstructionKind:
break;
case NSXMLCommentKind:
break;
case NSXMLTextKind:
break;
case NSXMLDTDKind:
break;
case NSXMLEntityDeclarationKind:
break;
case NSXMLAttributeDeclarationKind:
break;
case NSXMLElementDeclarationKind:
break;
case NSXMLNotationDeclarationKind:
break;
}
return result;
}
-(NSString *)XPath {
NSUnimplementedMethod();
return nil;
}
-(NSString *)canonicalXMLStringPreservingComments:(BOOL)comments {
NSUnimplementedMethod();
return nil;
}
-(NSString *)description {
return [self XMLString];
}
@end

View File

@ -1 +0,0 @@
../../cocotron/Foundation/xml/NSXMLParser.m

587
src/NSXMLParser.m Normal file
View File

@ -0,0 +1,587 @@
/* Copyright (c) 2007 Christopher J. W. Lloyd
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <Foundation/NSXMLParser.h>
#import <Foundation/NSData.h>
#import <Foundation/NSRaise.h>
#import <Foundation/NSMutableDictionary.h>
#import <Foundation/NSMutableArray.h>
#import <Foundation/NSAutoreleasePool.h>
#import <string.h>
enum {
STATE_content,
STATE_ignoreable_content,
STATE_Reference,
STATE_CharRef,
STATE_CharRef_hex,
STATE_CharRef_decimal,
STATE_EntityRef_Name,
STATE_Tag,
STATE_ignore_unhandled,
STATE_STag,
STATE_ETag,
STATE_ETag_whitespace,
STATE_Attributes,
STATE_EmptyElementTag,
STATE_Attribute_Name,
STATE_Attribute_Name_whitespace,
STATE_Attribute_Equal,
STATE_Attribute_Value,
STATE_Attribute_Value_DoubleQuote,
STATE_Attribute_Value_SingleQuote,
STATE_CDATA
};
@implementation NSXMLParser
-initWithData:(NSData *)data {
_data=[data retain];
_bytes=[data bytes];
_length=[data length];
_range=NSMakeRange(0,0);
_entityRefContents=[NSMutableDictionary new];
[_entityRefContents setObject:@"&" forKey:@"amp"];
[_entityRefContents setObject:@"<" forKey:@"lt"];
[_entityRefContents setObject:@">" forKey:@"gt"];
[_entityRefContents setObject:@"\'" forKey:@"apos"];
[_entityRefContents setObject:@"\"" forKey:@"quot"];
_state=STATE_content;
_elementNameStack=[[NSMutableArray alloc] init];
return self;
}
-initWithContentsofURL:(NSURL *)url {
NSData *data=[NSData dataWithContentsOfURL:url];
if(data==nil){
[self dealloc];
return nil;
}
return [self initWithData:data];
}
-(void)dealloc {
[_data release];
[_entityRefContents release];
[_elementNameStack release];
[_currentAttributes release];
[super dealloc];
}
-delegate {
return _delegate;
}
-(BOOL)shouldProcessNamespaces {
return _shouldProcessNamespaces;
}
-(BOOL)shouldReportNamespacePrefixes {
return _shouldReportNamespacePrefixes;
}
-(BOOL)shouldResolveExternalEntities {
return _shouldResolveExternalEntities;
}
-(void)setDelegate:delegate {
_delegate=delegate;
}
-(void)setShouldProcessNamespaces:(BOOL)flag {
_shouldProcessNamespaces=flag;
}
-(void)setShouldReportNamespacePrefixes:(BOOL)flag {
_shouldReportNamespacePrefixes=flag;
}
-(void)setShouldResolveExternalEntities:(BOOL)flag {
_shouldResolveExternalEntities=flag;
}
-(NSString *)createCurrentString {
return [[NSString alloc] initWithBytes:_bytes+_range.location length:_range.length encoding:NSUTF8StringEncoding];
}
-(void)content:(NSString *)string {
if([_delegate respondsToSelector:@selector(parser:foundCharacters:)])
[_delegate parser:self foundCharacters:string];
}
-(void)ignoreableWhitespace:(NSString *)string {
if([_delegate respondsToSelector:@selector(parser:foundIgnorableWhitespace:)])
[_delegate parser:self foundIgnorableWhitespace:string];
}
-(void)charRef:(NSString *)charRef {
if([_delegate respondsToSelector:@selector(parser:foundCharacters:)])
[_delegate parser:self foundCharacters:charRef];
}
-(void)entityRef:(NSString *)entityRef {
NSString *key=[self createCurrentString];
NSString *contents=[_entityRefContents objectForKey:key];
if(contents!=nil){
if([_delegate respondsToSelector:@selector(parser:foundCharacters:)])
[_delegate parser:self foundCharacters:contents];
}
else
NSLog(@"unknown entity=%@",key);
[key release];
}
-(void)sTag:(NSString *)sTag {
[_elementNameStack addObject:sTag];
}
-(void)didStartElement {
NSString *elementName=[_elementNameStack lastObject];
if([_delegate respondsToSelector:@selector(parser:didStartElement:namespaceURI:qualifiedName:attributes:)])
[_delegate parser:self didStartElement:elementName namespaceURI:nil qualifiedName:nil attributes:_currentAttributes];
[_currentAttributes release];
_currentAttributes=nil;
}
-(void)didEndElement {
NSString *elementName=[_elementNameStack lastObject];
[_delegate parser:self didEndElement:elementName namespaceURI:nil qualifiedName:nil];
[_elementNameStack removeLastObject];
}
-(void)eTag:(NSString *)eTag {
// FIX, maybe double check name here
[self didEndElement];
}
-(void)attributeName:(NSString *)name {
_currentAttributeName=[name copy];
}
-(void)attributeValue:(NSString *)value {
if(_currentAttributes==nil)
_currentAttributes=[[NSMutableDictionary alloc] init];
[_currentAttributes setObject:value forKey:_currentAttributeName];
[_currentAttributeName release];
_currentAttributeName=nil;
}
-(NSString *)currentString {
return [[self createCurrentString] autorelease];
}
static inline BOOL codeIsIgnoreableWhitespace(uint8_t code){
if(code==0x0A || code==0x0D || code==0x09)
return YES;
return NO;
}
static inline BOOL codeIsWhitespace(uint8_t code){
if(code==0x20 || codeIsIgnoreableWhitespace(code))
return YES;
return NO;
}
static inline BOOL codeIsNameStart(uint8_t code){
if((code>='A' && code<='Z') ||
(code>='a' && code<='z') ||
code==':' || code=='_')
return YES;
return NO;
}
static inline BOOL codeIsNameContinue(uint8_t code){
if((code>='A' && code<='Z') ||
(code>='a' && code<='z') ||
code==':' || code=='_' ||
(code>='0' && code<='9') ||
code=='.' || code=='-')
return YES;
return NO;
}
-(void)unexpectedIn:(NSString *)state {
NSUInteger position=NSMaxRange(_range)-1;
uint8_t code=_bytes[position];
[NSException raise:@"" format:@"Unexpected character %c in %@, position=%d",code,state,position];
}
-(BOOL)parse {
int createNewPool=0;
NSAutoreleasePool *pool=nil;
while(NSMaxRange(_range)<_length){
if(pool==nil)
pool=[NSAutoreleasePool new];
uint8_t code=_bytes[NSMaxRange(_range)];
enum {
extendLength,
advanceLocationToNext,
advanceLocationToCurrent,
} rangeAction=extendLength;
switch(_state){
case STATE_content:
if(code=='&'){
if(_range.length>0)
[self content:[self currentString]];
_state=STATE_Reference;
rangeAction=advanceLocationToNext;
}
else if(code=='<'){
if(_range.length>0)
[self content:[self currentString]];
_state=STATE_Tag;
rangeAction=advanceLocationToNext;
}
else if(codeIsIgnoreableWhitespace(code)){
if(_range.length>0)
[self content:[self currentString]];
_state=STATE_ignoreable_content;
rangeAction=advanceLocationToCurrent;
}
else {
_state=STATE_content;
}
break;
case STATE_ignoreable_content:
if(!codeIsIgnoreableWhitespace(code)){
if(_range.length>0)
[self ignoreableWhitespace:[self currentString]];
_state=STATE_content;
rangeAction=advanceLocationToCurrent;
}
break;
case STATE_Reference:
if(code=='#'){
_charRef=0;
_state=STATE_CharRef;
rangeAction=advanceLocationToNext;
}
else if(codeIsNameStart(code)){
_state=STATE_EntityRef_Name;
rangeAction=advanceLocationToCurrent;
}
else {
[self unexpectedIn:@"Reference"];
return NO;
}
break;
case STATE_CharRef:
if(code=='x'){
_state=STATE_CharRef_hex;
rangeAction=advanceLocationToCurrent;
}
else if(code>='0' && code<='9'){
_charRef=code-'0';
_state=STATE_CharRef_decimal;
rangeAction=advanceLocationToCurrent;
}
else {
[self unexpectedIn:@"CharRef"];
return NO;
}
break;
case STATE_CharRef_hex:
if(code>='0' && code<='9'){
_charRef=_charRef*16+code-'0';
_state=STATE_CharRef_hex;
}
else if(code>='a' && code<='z'){
_charRef=_charRef*16+code-'a'+10;
_state=STATE_CharRef_hex;
}
else if(code>='A' && code<='Z'){
_charRef=_charRef*16+code-'A'+10;
_state=STATE_CharRef_hex;
}
else if(code==';'){
[self charRef:[NSString stringWithCharacters:&_charRef length:1]];
_state=STATE_content;
rangeAction=advanceLocationToNext;
}
else{
[self unexpectedIn:@"hexadecimal CharRef"];
return NO;
}
break;
case STATE_CharRef_decimal:
if(code>='0' && code<='9'){
_charRef=_charRef*10+code-'0';
_state=STATE_CharRef_decimal;
}
else if(code==';'){
[self charRef:[NSString stringWithCharacters:&_charRef length:1]];
_state=STATE_content;
rangeAction=advanceLocationToNext;
}
else {
[self unexpectedIn:@"decimal CharRef"];
return NO;
}
break;
case STATE_EntityRef_Name:
if(codeIsNameContinue(code))
_state=STATE_EntityRef_Name;
else if(code==';'){
[self entityRef:[self currentString]];
_state=STATE_content;
rangeAction=advanceLocationToNext;
}
else {
[self unexpectedIn:@"EntityRef Name"];
return NO;
}
break;
case STATE_Tag:
if(code=='/'){
_state=STATE_ETag;
rangeAction=advanceLocationToNext;
}
else if(codeIsNameStart(code)){
_state=STATE_STag;
rangeAction=advanceLocationToCurrent;
}
else if(code=='?'){ // FIX, to just get through ?xml
_state=STATE_ignore_unhandled;
rangeAction=advanceLocationToNext;
}
else if(code=='!'){
if (NSMaxRange(_range)+8 < _length) {
if (0 == memcmp(_bytes + NSMaxRange(_range), "![CDATA[", 8)) {
_state = STATE_CDATA;
_range.length += 8;
rangeAction = advanceLocationToCurrent;
}
}
if (_state != STATE_CDATA) { // get through !DOCTYPE
_state=STATE_ignore_unhandled;
rangeAction=advanceLocationToNext;
}
}
else {
[self unexpectedIn:@"Tag"];
return NO;
}
break;
case STATE_CDATA:
if (code==']' && NSMaxRange(_range)+3 < _length) {
if (0 == memcmp(_bytes + NSMaxRange(_range), "]]>", 3)) {
if(_range.length>0)
[self content:[self currentString]];
_state = STATE_content;
_range.length += 3;
rangeAction = advanceLocationToCurrent;
}
}
break;
case STATE_ignore_unhandled:
rangeAction=advanceLocationToNext;
if(code=='>')
_state=STATE_content;
break;
case STATE_STag:
if(codeIsNameContinue(code))
_state=STATE_STag;
else {
[self sTag:[self currentString]];
_state=STATE_Attributes;
rangeAction=advanceLocationToCurrent;
}
break;
case STATE_ETag:
if(codeIsNameContinue(code))
_state=STATE_ETag;
else {
[self eTag:[self currentString]];
_state=STATE_ETag_whitespace;
rangeAction=advanceLocationToCurrent;
}
break;
case STATE_ETag_whitespace:
if(codeIsWhitespace(code))
_state=STATE_ETag_whitespace;
else if(code=='>'){
_state=STATE_content;
rangeAction=advanceLocationToNext;
}
else {
[self unexpectedIn:@"ETag"];
return NO;
}
break;
case STATE_Attributes:
if(codeIsWhitespace(code))
_state=STATE_Attributes;
else if(code=='/')
_state=STATE_EmptyElementTag;
else if(code=='>'){
[self didStartElement];
_state=STATE_content;
rangeAction=advanceLocationToNext;
}
else if(codeIsNameStart(code)){
_state=STATE_Attribute_Name;
rangeAction=advanceLocationToCurrent;
}
break;
case STATE_EmptyElementTag:
if(code=='>'){
[self didStartElement];
[self didEndElement];
_state=STATE_content;
rangeAction=advanceLocationToNext;
}
else {
[self unexpectedIn:@"EmptyElementTag"];
return NO;
}
break;
case STATE_Attribute_Name:
if(codeIsNameContinue(code))
_state=STATE_Attribute_Name;
else {
[self attributeName:[self currentString]];
_state=STATE_Attribute_Name_whitespace;
rangeAction=advanceLocationToCurrent;
}
break;
case STATE_Attribute_Name_whitespace:
if(codeIsWhitespace(code))
_state=STATE_Attribute_Name_whitespace;
else if(code=='=')
_state=STATE_Attribute_Equal;
break;
case STATE_Attribute_Equal:
if(codeIsWhitespace(code))
_state=STATE_Attribute_Equal;
else {
rangeAction=advanceLocationToCurrent;
_state=STATE_Attribute_Value;
}
break;
case STATE_Attribute_Value:
if(code=='\"'){
_state=STATE_Attribute_Value_DoubleQuote;
rangeAction=advanceLocationToNext;
}
else if(code=='\''){
_state=STATE_Attribute_Value_SingleQuote;
rangeAction=advanceLocationToNext;
}
else {
[self unexpectedIn:@"Attribute Value"];
return NO;
}
break;
case STATE_Attribute_Value_DoubleQuote:
if(code=='\"'){
[self attributeValue:[self currentString]];
_state=STATE_Attributes;
rangeAction=advanceLocationToNext;
}
break;
case STATE_Attribute_Value_SingleQuote:
if(code=='\''){
[self attributeValue:[self currentString]];
_state=STATE_Attributes;
rangeAction=advanceLocationToNext;
}
break;
}
switch(rangeAction){
case extendLength:
_range.length++;
break;
case advanceLocationToNext:
_range.location=NSMaxRange(_range)+1;
_range.length=0;
break;
case advanceLocationToCurrent:
_range.location=NSMaxRange(_range);
_range.length=0;
break;
}
createNewPool++;
if((createNewPool%1000)==0){
[pool release];
pool=nil;
}
}
return YES;
}
-(void)abortParsing {
NSUnimplementedMethod();
}
-(NSError *)parserError {
return _parserError;
}
-(NSString *)systemID {
return _systemID;
}
-(NSString *)publicID {
return _publicID;
}
-(NSInteger)columnNumber {
return _columnNumber;
}
-(NSInteger)lineNumber {
return _lineNumber;
}
@end