Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 9 commits
  • 63 files changed
  • 0 commit comments
  • 1 contributor
Showing with 41 additions and 1,973 deletions.
  1. +16 −9 .gitignore
  2. 0  Classes/{lib/Core → }/CoreSupport.h
  3. 0  Classes/{lib/Core → }/NSData+Additions.h
  4. 0  Classes/{lib/Core → }/NSData+Additions.m
  5. 0  Classes/{lib/Core → }/NSObject+PropertySupport.h
  6. 0  Classes/{lib/Core → }/NSObject+PropertySupport.m
  7. 0  Classes/{lib/Core → }/NSString+GSub.h
  8. 0  Classes/{lib/Core → }/NSString+GSub.m
  9. 0  Classes/{lib/Core/Inflections → }/NSString+InflectionSupport.h
  10. 0  Classes/{lib/Core/Inflections → }/NSString+InflectionSupport.m
  11. 0  Classes/{lib/Core → }/ObjectiveResourceDateFormatter.h
  12. 0  Classes/{lib/Core → }/ObjectiveResourceDateFormatter.m
  13. +2 −2 Classes/{lib/Core → }/ObjectiveSupport.h
  14. 0  Classes/{lib/Serialization/JSON → Serialization}/JSONSerializable.h
  15. 0  Classes/{lib/Serialization/JSON → Serialization}/JSONSerializableSupport.h
  16. 0  Classes/{lib/Serialization/JSON → Serialization}/NSArray+JSONSerializableSupport.h
  17. +1 −1  Classes/{lib/Serialization/JSON → Serialization}/NSArray+JSONSerializableSupport.m
  18. 0  Classes/{lib → }/Serialization/NSDate+Serialize.h
  19. 0  Classes/{lib → }/Serialization/NSDate+Serialize.m
  20. 0  Classes/{lib/Serialization/JSON → Serialization}/NSDictionary+JSONSerializableSupport.h
  21. +1 −1  Classes/{lib/Serialization/JSON → Serialization}/NSDictionary+JSONSerializableSupport.m
  22. 0  Classes/{lib → }/Serialization/NSDictionary+KeyTranslation.h
  23. 0  Classes/{lib → }/Serialization/NSDictionary+KeyTranslation.m
  24. +1 −0  Classes/{lib/Serialization/JSON → Serialization}/NSObject+JSONSerializableSupport.h
  25. +14 −5 Classes/{lib/Serialization/JSON → Serialization}/NSObject+JSONSerializableSupport.m
  26. 0  Classes/{lib → }/Serialization/NSObject+Serialize.h
  27. 0  Classes/{lib → }/Serialization/NSObject+Serialize.m
  28. 0  Classes/{lib → }/Serialization/NSString+Serialize.h
  29. 0  Classes/{lib → }/Serialization/NSString+Serialize.m
  30. 0  Classes/{lib → }/Serialization/Serialize.h
  31. +0 −32 Classes/lib/Serialization/XML/FromXMLElementDelegate.h
  32. +0 −188 Classes/lib/Serialization/XML/FromXMLElementDelegate.m
  33. +0 −13 Classes/lib/Serialization/XML/NSArray+XMLSerializableSupport.h
  34. +0 −35 Classes/lib/Serialization/XML/NSArray+XMLSerializableSupport.m
  35. +0 −13 Classes/lib/Serialization/XML/NSDate+XMLSerializableSupport.h
  36. +0 −35 Classes/lib/Serialization/XML/NSDate+XMLSerializableSupport.m
  37. +0 −17 Classes/lib/Serialization/XML/NSDictionary+XMLSerializableSupport.h
  38. +0 −37 Classes/lib/Serialization/XML/NSDictionary+XMLSerializableSupport.m
  39. +0 −11 Classes/lib/Serialization/XML/NSNull+XMLSerializableSupport.h
  40. +0 −17 Classes/lib/Serialization/XML/NSNull+XMLSerializableSupport.m
  41. +0 −12 Classes/lib/Serialization/XML/NSNumber+XMLSerializableSupport.h
  42. +0 −25 Classes/lib/Serialization/XML/NSNumber+XMLSerializableSupport.m
  43. +0 −54 Classes/lib/Serialization/XML/NSObject+XMLSerializableSupport.h
  44. +0 −132 Classes/lib/Serialization/XML/NSObject+XMLSerializableSupport.m
  45. +0 −20 Classes/lib/Serialization/XML/NSString+XMLSerializableSupport.h
  46. +0 −33 Classes/lib/Serialization/XML/NSString+XMLSerializableSupport.m
  47. +0 −79 Classes/lib/Serialization/XML/XMLSerializable.h
  48. +0 −14 Classes/lib/Serialization/XML/XMLSerializableSupport.h
  49. +0 −11 Classes/lib/json-framework/JSONFramework.h
  50. +0 −60 Classes/lib/json-framework/NSObject+SBJSON.h
  51. +0 −57 Classes/lib/json-framework/NSObject+SBJSON.m
  52. +0 −41 Classes/lib/json-framework/NSString+SBJSON.h
  53. +0 −60 Classes/lib/json-framework/NSString+SBJSON.m
  54. +0 −137 Classes/lib/json-framework/SBJSON.h
  55. +0 −740 Classes/lib/json-framework/SBJSON.m
  56. +0 −16 Classes/unit_tests/XMLDeserializeTest.h
  57. +0 −66 Classes/unit_tests/XMLDeserializeTest.m
  58. +1 −0  Config.xcconfig
  59. 0  {Classes → Demo}/objective_supportAppDelegate.h
  60. 0  {Classes → Demo}/objective_supportAppDelegate.m
  61. +5 −0 KitSpec
  62. 0  {Classes → }/unit_tests/NSDateTest.h
  63. 0  {Classes → }/unit_tests/NSDateTest.m
View
25 .gitignore
@@ -1,12 +1,19 @@
-# osx noise
-.DS_Store
-profile
-
-# xcode noise
-build/*
+# Xcode noise
+build/**
*.pbxuser
+*.perspectivev3
*.mode1v3
-*.mode2v3
-#svn
-*.svn
+# Xcode 4 noise
+*.xcworkspace
+xcuserdata
+
+# old skool
+.svn
+.cvs
+
+# osx noise
+.DS_Store
+
+# Kit
+dist
View
0  Classes/lib/Core/CoreSupport.h → Classes/CoreSupport.h
File renamed without changes
View
0  Classes/lib/Core/NSData+Additions.h → Classes/NSData+Additions.h
File renamed without changes
View
0  Classes/lib/Core/NSData+Additions.m → Classes/NSData+Additions.m
File renamed without changes
View
0  Classes/lib/Core/NSObject+PropertySupport.h → Classes/NSObject+PropertySupport.h
File renamed without changes
View
0  Classes/lib/Core/NSObject+PropertySupport.m → Classes/NSObject+PropertySupport.m
File renamed without changes
View
0  Classes/lib/Core/NSString+GSub.h → Classes/NSString+GSub.h
File renamed without changes
View
0  Classes/lib/Core/NSString+GSub.m → Classes/NSString+GSub.m
File renamed without changes
View
0  ...lib/Core/Inflections/NSString+InflectionSupport.h → Classes/NSString+InflectionSupport.h
File renamed without changes
View
0  ...lib/Core/Inflections/NSString+InflectionSupport.m → Classes/NSString+InflectionSupport.m
File renamed without changes
View
0  Classes/lib/Core/ObjectiveResourceDateFormatter.h → Classes/ObjectiveResourceDateFormatter.h
File renamed without changes
View
0  Classes/lib/Core/ObjectiveResourceDateFormatter.m → Classes/ObjectiveResourceDateFormatter.m
File renamed without changes
View
4 Classes/lib/Core/ObjectiveSupport.h → Classes/ObjectiveSupport.h
@@ -7,5 +7,5 @@
//
#import "CoreSupport.h"
-#import "XMLSerializableSupport.h"
-#import "JSONSerializableSupport.h"
+#import "Serialization/JSONSerializableSupport.h"
+#import "ObjectiveResourceDateFormatter.h"
View
0  Classes/lib/Serialization/JSON/JSONSerializable.h → Classes/Serialization/JSONSerializable.h
File renamed without changes
View
0  .../lib/Serialization/JSON/JSONSerializableSupport.h → Classes/Serialization/JSONSerializableSupport.h
File renamed without changes
View
0  ...ialization/JSON/NSArray+JSONSerializableSupport.h → ...s/Serialization/NSArray+JSONSerializableSupport.h
File renamed without changes
View
2  ...ialization/JSON/NSArray+JSONSerializableSupport.m → ...s/Serialization/NSArray+JSONSerializableSupport.m
@@ -6,7 +6,7 @@
// Copyright 2009 Burkaprojects. All rights reserved.
//
-#import "JSONFramework.h"
+#import "JSON.h"
#import "NSObject+JSONSerializableSupport.h"
#import "NSArray+JSONSerializableSupport.h"
View
0  Classes/lib/Serialization/NSDate+Serialize.h → Classes/Serialization/NSDate+Serialize.h
File renamed without changes
View
0  Classes/lib/Serialization/NSDate+Serialize.m → Classes/Serialization/NSDate+Serialize.m
File renamed without changes
View
0  ...ation/JSON/NSDictionary+JSONSerializableSupport.h → ...ialization/NSDictionary+JSONSerializableSupport.h
File renamed without changes
View
2  ...ation/JSON/NSDictionary+JSONSerializableSupport.m → ...ialization/NSDictionary+JSONSerializableSupport.m
@@ -6,7 +6,7 @@
// Copyright 2009 Burkaprojects. All rights reserved.
//
-#import "JSONFramework.h"
+#import "JSON.h"
#import "NSDictionary+KeyTranslation.h"
#import "NSDictionary+JSONSerializableSupport.h"
#import "ObjectiveSupport.h"
View
0  ...s/lib/Serialization/NSDictionary+KeyTranslation.h → Classes/Serialization/NSDictionary+KeyTranslation.h
File renamed without changes
View
0  ...s/lib/Serialization/NSDictionary+KeyTranslation.m → Classes/Serialization/NSDictionary+KeyTranslation.m
File renamed without changes
View
1  ...alization/JSON/NSObject+JSONSerializableSupport.h → .../Serialization/NSObject+JSONSerializableSupport.h
@@ -12,6 +12,7 @@
@interface NSObject (JSONSerializableSupport) <JSONSerializable>
+ (id)fromJSONData:(NSData *)data;
++ (id) deserializeJSON:(id)jsonObject;
+ (id) deserializeJSON:(id)jsonObject asClass:(Class) claz;
- (NSString *)toJSON;
- (NSString *)toJSONExcluding:(NSArray *)exclusions;
View
19 ...alization/JSON/NSObject+JSONSerializableSupport.m → .../Serialization/NSObject+JSONSerializableSupport.m
@@ -9,11 +9,11 @@
#import "NSObject+JSONSerializableSupport.h"
#import "NSDictionary+JSONSerializableSupport.h"
#import "Serialize.h"
-#import "JSONFramework.h"
+#import "JSON.h"
#import "ObjectiveSupport.h"
+#import "NSObject+Extensions.h"
@interface NSObject (JSONSerializableSupport_Private)
-+ (id) deserializeJSON:(id)jsonObject;
- (NSString *) convertProperty:(NSString *)propertyName andClassName:(NSString *)className;
@end
@@ -79,10 +79,10 @@ + (id) deserializeJSON:(id)jsonObject asClass:(Class) claz {
if ([[objectPropertyNames allKeys] containsObject:propertyCamalized]) {
Class propertyClass = [self propertyClass:[objectPropertyNames objectForKey:propertyCamalized]];
if ([[NSDictionary class] isSubclassOfClass:propertyClass]) {
- [result setValue:[jsonObject objectForKey:property] forKey:propertyCamalized];
+ [result setValue:[[jsonObject objectForKey:property]niledNull] forKey:propertyCamalized];
}
else {
- [result setValue:[self deserializeJSON:[propertyClass deserializeJSON:[jsonObject objectForKey:property] asClass:propertyClass]] forKey:propertyCamalized];
+ [result setValue:[[self deserializeJSON:[propertyClass deserializeJSON:[jsonObject objectForKey:property] asClass:propertyClass]]niledNull] forKey:propertyCamalized];
}
}
}
@@ -104,6 +104,15 @@ + (id) deserializeJSON:(id)jsonObject {
}
}
else if ([jsonObject isKindOfClass:[NSDictionary class]]) {
+ // if dict has no keys
+ if ([(NSDictionary *)jsonObject allKeys].count == 0) {
+ return result;
+ }
+
+ if (![[[(NSDictionary *)jsonObject allValues] objectAtIndex:0] isKindOfClass:[NSDictionary class]]) {
+ return result;
+ }
+
//JSON object
//this assumes we are dealing with JSON in the form rails provides:
// {className : { property1 : value, property2 : {class2Name : {property 3 : value }}}}
@@ -123,7 +132,7 @@ + (id) deserializeJSON:(id)jsonObject {
NSString *propertyCamalized = [[self convertProperty:property andClassName:objectName] camelize];
if ([[objectPropertyNames allKeys]containsObject:propertyCamalized]) {
Class propertyClass = [self propertyClass:[objectPropertyNames objectForKey:propertyCamalized]];
- [result setValue:[self deserializeJSON:[propertyClass deserialize:[properties objectForKey:property]]] forKey:propertyCamalized];
+ [result setValue:[[self deserializeJSON:[propertyClass deserialize:[properties objectForKey:property]]]niledNull] forKey:propertyCamalized];
}
}
}
View
0  Classes/lib/Serialization/NSObject+Serialize.h → Classes/Serialization/NSObject+Serialize.h
File renamed without changes
View
0  Classes/lib/Serialization/NSObject+Serialize.m → Classes/Serialization/NSObject+Serialize.m
File renamed without changes
View
0  Classes/lib/Serialization/NSString+Serialize.h → Classes/Serialization/NSString+Serialize.h
File renamed without changes
View
0  Classes/lib/Serialization/NSString+Serialize.m → Classes/Serialization/NSString+Serialize.m
File renamed without changes
View
0  Classes/lib/Serialization/Serialize.h → Classes/Serialization/Serialize.h
File renamed without changes
View
32 Classes/lib/Serialization/XML/FromXMLElementDelegate.h
@@ -1,32 +0,0 @@
-//
-// FromXMLElementDelegate.h
-//
-//
-// Created by Ryan Daigle on 7/31/08.
-// Copyright 2008 yFactorial, LLC. All rights reserved.
-//
-
-@interface FromXMLElementDelegate : NSObject {
- Class targetClass;
- id parsedObject;
- NSString *currentPropertyName;
- NSMutableString *contentOfCurrentProperty;
- NSMutableArray *unclosedProperties;
- NSString *currentPropertyType;
-}
-
-@property (nonatomic, retain) Class targetClass;
-@property (nonatomic, retain) id parsedObject;
-@property (nonatomic, retain) NSString *currentPropertyName;
-@property (nonatomic, retain) NSMutableString *contentOfCurrentProperty;
-@property (nonatomic, retain) NSMutableArray *unclosedProperties;
-@property (nonatomic, retain) NSString *currentPropertyType;
-
-+ (FromXMLElementDelegate *)delegateForClass:(Class)targetClass;
-
-- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict;
-- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string;
-- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName;
-- (NSString *)convertElementName:(NSString *)anElementName;
-
-@end
View
188 Classes/lib/Serialization/XML/FromXMLElementDelegate.m
@@ -1,188 +0,0 @@
-//
-// FromXMLElementDelegate.m
-//
-//
-// Created by Ryan Daigle on 7/31/08.
-// Copyright 2008 yFactorial, LLC. All rights reserved.
-//
-
-#import "FromXMLElementDelegate.h"
-#import "XMLSerializableSupport.h"
-#import "CoreSupport.h"
-
-@implementation FromXMLElementDelegate
-
-@synthesize targetClass, parsedObject, currentPropertyName, contentOfCurrentProperty, unclosedProperties, currentPropertyType;
-
-+ (FromXMLElementDelegate *)delegateForClass:(Class)targetClass {
- FromXMLElementDelegate *delegate = [[[self alloc] init] autorelease];
- [delegate setTargetClass:targetClass];
- return delegate;
-}
-
-
-- (id)init {
- super;
- self.unclosedProperties = [NSMutableArray array];
- return self;
-}
-
-
-- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
-{
- if ([@"nil-classes" isEqualToString:elementName]) {
- //empty result set, do nothing
- }
-
- //Start of the root object
- else if (parsedObject == nil) {
- if ([elementName isEqualToString:[self.targetClass xmlElementName]]) {
- self.parsedObject = [[[self.targetClass alloc] init] autorelease];
- }
- else if ([@"array" isEqualToString:[attributeDict objectForKey:@"type"]]) {
- self.parsedObject = [NSMutableArray array];
- }
- [self.unclosedProperties addObject:[NSArray arrayWithObjects:elementName, self.parsedObject, nil]];
- self.currentPropertyName = elementName;
- }
-
- else {
- //if we are inside another element and it is not the current parent object,
- // then create an object for that parent element
- if(self.currentPropertyName != nil && (![self.currentPropertyName isEqualToString:[[self.parsedObject class] xmlElementName]])) {
- Class elementClass = NSClassFromString([currentPropertyName toClassName]);
- if (elementClass != nil) {
- //classname matches, instantiate a new instance of the class and set it as the current parent object
- self.parsedObject = [[[elementClass alloc] init] autorelease];
- [self.unclosedProperties addObject:[NSArray arrayWithObjects:self.currentPropertyName, self.parsedObject, nil]];
- }
- }
-
- // If we recognize an element that corresponds to a known property of the current parent object, or if the
- // current parent is an array then start collecting content for this child element
-
- if (([self.parsedObject isKindOfClass:[NSArray class]]) ||
- ([[[self.parsedObject class] propertyNames] containsObject:[[self convertElementName:elementName] camelize]])) {
- self.currentPropertyName = [self convertElementName:elementName];
- if ([@"array" isEqualToString:[attributeDict objectForKey:@"type"]]) {
- self.parsedObject = [NSMutableArray array];
- [self.unclosedProperties addObject:[NSArray arrayWithObjects:elementName, self.parsedObject, nil]];
- }
- else {
- self.contentOfCurrentProperty = [NSMutableString string];
- self.currentPropertyType = [attributeDict objectForKey:@"type"];
- }
- }
- else {
- // The element isn't one that we care about, so set the property that holds the
- // character content of the current element to nil. That way, in the parser:foundCharacters:
- // callback, the string that the parser reports will be ignored.
- self.currentPropertyName = nil;
- self.contentOfCurrentProperty = nil;
- }
- }
-}
-
-// Characters (i.e. an element value - retarded, I know) are given to us in chunks,
-// so we need to append them onto the current property value.
-- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
-{
-
- // If the current property is nil, then we know we're currently at
- // an element that we don't know about or don't care about
- if (self.contentOfCurrentProperty) {
-
- // Append string value on since we're given them in chunks
- [self.contentOfCurrentProperty appendString:string];
- }
-}
-
-//Basic type conversion based on the ObjectiveResource "type" attribute
-- (id) convertProperty:(NSString *)propertyValue toType:(NSString *)type {
- if ([type isEqualToString:@"datetime" ]) {
- return [NSDate fromXMLDateTimeString:propertyValue];
- }
- else if ([type isEqualToString:@"date"]) {
- return [NSDate fromXMLDateString:propertyValue];
- }
-
- // uncomment this if you what to support NSNumber and NSDecimalNumber
- // if you do your classId must be a NSNumber since rails will pass it as such
- //else if ([type isEqualToString:@"decimal"]) {
- // return [NSDecimalNumber decimalNumberWithString:propertyValue];
- //}
- //else if ([type isEqualToString:@"integer"]) {
- // return [NSNumber numberWithInt:[propertyValue intValue]];
- //}
-
- else {
- return [NSString fromXmlString:propertyValue];
- }
-}
-
-// Converts the Id element to modelNameId
-- (NSString *) convertElementName:(NSString *)anElementName {
-
- if([anElementName isEqualToString:@"id"]) {
- return [NSString stringWithFormat:@"%@Id",[[[self.parsedObject class]xmlElementName] camelize]];
- // return [NSString stringWithFormat:@"%@_%@" , [NSStringFromClass([self.parsedObject class])
-// stringByReplacingCharactersInRange:NSMakeRange(0, 1)
-// withString:[[NSStringFromClass([self.parsedObject class])
-// substringWithRange:NSMakeRange(0,1)]
-// lowercaseString]], anElementName];
- }
- else {
-
- return anElementName;
-
- }
-
-}
-
-// We're done receiving the value of a particular element, so take the value we've collected and
-// set it on the current object
-- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
-{
- if(self.contentOfCurrentProperty != nil && self.currentPropertyName != nil) {
- [self.parsedObject
- setValue:[self convertProperty:self.contentOfCurrentProperty toType:self.currentPropertyType]
- forKey:[self.currentPropertyName camelize]];
- }
- else if ([self.currentPropertyName isEqualToString:[self convertElementName:elementName]]) {
- //element is closed, pop it from the stack
- [self.unclosedProperties removeLastObject];
- //check for a parent object on the stack
- if ([self.unclosedProperties count] > 0) {
- //handle arrays as a special case
- if ([[[self.unclosedProperties lastObject] objectAtIndex:1] isKindOfClass:[NSArray class]]) {
- [[[self.unclosedProperties lastObject] objectAtIndex:1] addObject:self.parsedObject];
- }
- else {
- [[[self.unclosedProperties lastObject] objectAtIndex:1] setValue:self.parsedObject forKey:[self convertElementName:[elementName camelize]]];
- }
- self.parsedObject = [[self.unclosedProperties lastObject] objectAtIndex:1];
- }
- }
-
- self.contentOfCurrentProperty = nil;
-
- //set the parent object, if one exists, as the current element
- if ([self.unclosedProperties count] > 0) {
- self.currentPropertyName = [[self.unclosedProperties lastObject] objectAtIndex:0];
- }
-}
-
-
-#pragma mark cleanup
-
-- (void)dealloc {
- [targetClass release];
- [currentPropertyName release];
- [parsedObject release];
- [contentOfCurrentProperty release];
- [unclosedProperties release];
- [currentPropertyType release];
- [super dealloc];
-}
-
-@end
View
13 Classes/lib/Serialization/XML/NSArray+XMLSerializableSupport.h
@@ -1,13 +0,0 @@
-//
-// NSArray+XMLSerializableSupport.h
-//
-//
-// Created by vickeryj on 9/29/08.
-// Copyright 2008 Joshua Vickery. All rights reserved.
-//
-
-#import <Foundation/Foundation.h>
-
-@interface NSArray (XMLSerializableSupport)
-- (NSString *)toXMLValue;
-@end
View
35 Classes/lib/Serialization/XML/NSArray+XMLSerializableSupport.m
@@ -1,35 +0,0 @@
-//
-// NSArray+XMLSerializableSupport.m
-//
-//
-// Created by vickeryj on 9/29/08.
-// Copyright 2008 Joshua Vickery. All rights reserved.
-//
-
-#import "NSArray+XMLSerializableSupport.h"
-#import "NSObject+XMLSerializableSupport.h"
-
-
-@implementation NSArray (XMLSerializableSupport)
-
-- (NSString *)toXMLValue {
- NSMutableString *result = [NSMutableString string];
-
- for (id element in self) {
- [result appendString:[element toXMLElement]];
- }
-
- return result;
-}
-
-- (NSString *)toXMLElementAs:(NSString *)rootName excludingInArray:(NSArray *)exclusions
- withTranslations:(NSDictionary *)keyTranslations {
- NSMutableString *elementValue = [NSMutableString string];
- for (id element in self) {
- [elementValue appendString:[element toXMLElementAs:[[element class] xmlElementName] excludingInArray:exclusions withTranslations:keyTranslations]];
- }
- return [[self class] buildXmlElementAs:rootName withInnerXml:elementValue andType:@"array"];
-}
-
-
-@end
View
13 Classes/lib/Serialization/XML/NSDate+XMLSerializableSupport.h
@@ -1,13 +0,0 @@
-//
-// NSDate+XMLSerializableSupport.h
-//
-//
-// Created by Ryan Daigle on 7/31/08.
-// Copyright 2008 yFactorial, LLC. All rights reserved.
-//
-
-@interface NSDate (XMLSerializableSupport)
-- (NSString *)toXMLValue;
-+ (NSDate *)fromXMLDateTimeString:(NSString *)xmlString;
-+ (NSDate *)fromXMLDateString:(NSString *)xmlString;
-@end
View
35 Classes/lib/Serialization/XML/NSDate+XMLSerializableSupport.m
@@ -1,35 +0,0 @@
-//
-// NSDate+XMLSerializableSupport.m
-//
-//
-// Created by Ryan Daigle on 7/31/08.
-// Copyright 2008 yFactorial, LLC. All rights reserved.
-//
-
-#import "NSDate+XMLSerializableSupport.h"
-#import "NSObject+XMLSerializableSupport.h"
-#import "ObjectiveResourceDateFormatter.h"
-
-@implementation NSDate (XMLSerializableSupport)
-
-//FIXME we should have one formatter for the entire app
-
-- (NSString *)toXMLValue {
- return [ ObjectiveResourceDateFormatter formatDate:self];
-}
-
-- (NSString *)toXMLElementAs:(NSString *)rootName excludingInArray:(NSArray *)exclusions
- withTranslations:(NSDictionary *)keyTranslations {
- return [[self class] buildXmlElementAs:rootName withInnerXml:[self toXMLValue] andType:[[self class] xmlTypeFor:self]];
-}
-
-+ (NSDate *)fromXMLDateTimeString:(NSString *)xmlString {
- return [ ObjectiveResourceDateFormatter parseDateTime:xmlString];
-}
-
-+ (NSDate *)fromXMLDateString:(NSString *)xmlString {
- return [ ObjectiveResourceDateFormatter parseDate:xmlString];
-}
-
-
-@end
View
17 Classes/lib/Serialization/XML/NSDictionary+XMLSerializableSupport.h
@@ -1,17 +0,0 @@
-//
-// NSDictionary+XMLSerializableSupport.h
-//
-//
-// Created by Ryan Daigle on 7/31/08.
-// Copyright 2008 yFactorial, LLC. All rights reserved.
-//
-
-
-@interface NSDictionary (XMLSerializableSupport)
-
-- (NSString *)toXMLElementAs:(NSString *)rootName excludingInArray:(NSArray *)exclusions
- withTranslations:(NSDictionary *)keyTranslations andType:(NSString *)xmlType;
-
-- (NSString *)toXMLElementAs:(NSString *)rootName excludingInArray:(NSArray *)exclusions
- withTranslations:(NSDictionary *)keyTranslations;
-@end
View
37 Classes/lib/Serialization/XML/NSDictionary+XMLSerializableSupport.m
@@ -1,37 +0,0 @@
-//
-// NSDictionary+XMLSerializableSupport.m
-//
-//
-// Created by Ryan Daigle on 7/31/08.
-// Copyright 2008 yFactorial, LLC. All rights reserved.
-//
-
-#import "NSObject+XMLSerializableSupport.h"
-#import "NSDictionary+KeyTranslation.h"
-
-@implementation NSDictionary (XMLSerializableSupport)
-
-
-- (NSString *)toXMLElementAs:(NSString *)rootName excludingInArray:(NSArray *)exclusions
- withTranslations:(NSDictionary *)keyTranslations andType:(NSString *)xmlType {
-
- NSMutableString* elementValue = [NSMutableString string];
- id value;
- NSString *propertyRootName;
- for (NSString *key in self) {
- // Create XML if key not in exclusion list
- if(![exclusions containsObject:key]) {
- value = [self valueForKey:key];
- propertyRootName = [[self class] translationForKey:key withTranslations:keyTranslations];
- [elementValue appendString:[value toXMLElementAs:propertyRootName]];
- }
- }
- return [[self class] buildXmlElementAs:rootName withInnerXml:elementValue andType:xmlType];
-}
-
-- (NSString *)toXMLElementAs:(NSString *)rootName excludingInArray:(NSArray *)exclusions
- withTranslations:(NSDictionary *)keyTranslations {
- return [self toXMLElementAs:rootName excludingInArray:exclusions withTranslations:keyTranslations andType:nil];
-}
-
-@end
View
11 Classes/lib/Serialization/XML/NSNull+XMLSerializableSupport.h
@@ -1,11 +0,0 @@
-//
-// NSNull+XMLSerializableSupport.h
-//
-//
-// Created by Ryan Daigle on 7/31/08.
-// Copyright 2008 yFactorial, LLC. All rights reserved.
-//
-
-@interface NSNull (XMLSerializableSupport)
-- (NSString *)toXMLValue;
-@end
View
17 Classes/lib/Serialization/XML/NSNull+XMLSerializableSupport.m
@@ -1,17 +0,0 @@
-//
-// NSNull+XMLSerializableSupport.m
-//
-//
-// Created by Ryan Daigle on 7/31/08.
-// Copyright 2008 yFactorial, LLC. All rights reserved.
-//
-
-#import "NSNull+XMLSerializableSupport.h"
-
-@implementation NSNull (XMLSerializableSupport)
-
-- (NSString *)toXMLValue {
- return @"";
-}
-
-@end
View
12 Classes/lib/Serialization/XML/NSNumber+XMLSerializableSupport.h
@@ -1,12 +0,0 @@
-//
-// NSNumber+XMLSerializableSupport.h
-// objective_support
-//
-// Created by James Burka on 2/17/09.
-// Copyright 2009 Burkaprojects. All rights reserved.
-//
-
-@interface NSNumber(XMLSerializableSupport)
-- (NSString *)toXMLValue;
-
-@end
View
25 Classes/lib/Serialization/XML/NSNumber+XMLSerializableSupport.m
@@ -1,25 +0,0 @@
-//
-// NSNumber+XMLSerializableSupport.m
-// objective_support
-//
-// Created by James Burka on 2/17/09.
-// Copyright 2009 Burkaprojects. All rights reserved.
-//
-
-#import "NSObject+XMLSerializableSupport.h"
-#import "NSNumber+XMLSerializableSupport.h"
-
-
-@implementation NSNumber(XMLSerializableSupport)
-
-- (NSString *)toXMLValue {
- return [self stringValue];
-}
-
-- (NSString *)toXMLElementAs:(NSString *)rootName excludingInArray:(NSArray *)exclusions
- withTranslations:(NSDictionary *)keyTranslations {
- return [[self class] buildXmlElementAs:rootName withInnerXml:[self toXMLValue] andType:[[self class] xmlTypeFor:self]];
-}
-
-
-@end
View
54 Classes/lib/Serialization/XML/NSObject+XMLSerializableSupport.h
@@ -1,54 +0,0 @@
-//
-// XMLSerializableSupport.h
-//
-//
-// Created by Ryan Daigle on 7/31/08.
-// Copyright 2008 yFactorial, LLC. All rights reserved.
-//
-
-#import "XMLSerializable.h"
-
-@interface NSObject (XMLSerializableSupport) <XMLSerializable>
-
-+ (NSString *)xmlTypeFor:(NSObject *)value;
-+ (NSString *)buildXmlElementAs:(NSString *)rootName withInnerXml:(NSString *)value andType:(NSString *)xmlType;
-
-/**
- * Construct a string representation of the given value object, assuming
- * the given root element name , the NSObjects's toXmlValue is called.
- */
-+ (NSString *)buildXMLElementAs:(NSString *)rootName withValue:(NSObject *)value;
-
-/**
- *
- * Constructs the actual xml node as a string
- *
- */
-+ (NSString *)buildXmlElementAs:(NSString *)rootName withInnerXml:(NSString *)value;
-
-/**
- * What is the element name for this object when serialized to XML.
- * Defaults to lower case and dasherized form of class name.
- * I.e. [[Person class] xmlElementName] //> @"person"
- */
-+ (NSString *)xmlElementName;
-
-/**
- * Construct the XML string representation of this particular object.
- * Only construct the markup for the value of this object, don't assume
- * any naming. For instance:
- *
- * [myObject toXMLValue] //> @"xmlSerializedValue"
- *
- * and not
- *
- * [myObject toXMLValue] //> @"<value>xmlSerializedValue</value>"
- *
- * For simple objects like strings, numbers etc this will be the text value of
- * the corresponding element. For complex objects this can include further markup:
- *
- * [myPersonObject toXMLValue] //> @"<first-name>Ryan</first-name><last-name>Daigle</last-name>"
- */
-- (NSString *)toXMLValue;
-
-@end
View
132 Classes/lib/Serialization/XML/NSObject+XMLSerializableSupport.m
@@ -1,132 +0,0 @@
-//
-// XMLSerializableSupport.m
-//
-//
-// Created by Ryan Daigle on 7/31/08.
-// Copyright 2008 yFactorial, LLC. All rights reserved.
-//
-
-#import "NSObject+XMLSerializableSupport.h"
-#import "NSDictionary+XMLSerializableSupport.h"
-#import "CoreSupport.h"
-#import "FromXMLElementDelegate.h"
-
-@implementation NSObject (XMLSerializableSupport)
-
-# pragma mark XML utility methods
-
-/**
- * Get the appropriate xml type, if any, for the given value.
- * I.e. "integer" or "decimal" etc... for use in element attributes:
- *
- * <element-name type="integer">1</element-name>
- */
-+ (NSString *)xmlTypeFor:(NSObject *)value {
-
- // Can't do this with NSDictionary w/ Class keys. Explore more elegant solutions.
- // TODO: Account for NSValue native types here?
- if ([value isKindOfClass:[NSDate class]]) {
- return @"datetime";
- } else if ([value isKindOfClass:[NSDecimalNumber class]]) {
- return @"decimal";
- } else if ([value isKindOfClass:[NSNumber class]]) {
- if (0 == strcmp("f",[(NSNumber *)value objCType]) ||
- 0 == strcmp("d",[(NSNumber *)value objCType]))
- {
- return @"decimal";
- }
- else {
- return @"integer";
- }
- } else if ([value isKindOfClass:[NSArray class]]) {
- return @"array";
- } else {
- return nil;
- }
-}
-
-+ (NSString *)buildXmlElementAs:(NSString *)rootName withInnerXml:(NSString *)value andType:(NSString *)xmlType{
- NSString *dashedName = [rootName dasherize];
-
- if (xmlType != nil) {
- return [NSString stringWithFormat:@"<%@ type=\"%@\">%@</%@>", dashedName, xmlType, value, dashedName];
- } else {
- return [NSString stringWithFormat:@"<%@>%@</%@>", dashedName, value, dashedName];
- }
-}
-
-+ (NSString *)buildXmlElementAs:(NSString *)rootName withInnerXml:(NSString *)value {
- return [[self class] buildXmlElementAs:rootName withInnerXml:value andType:nil];
-}
-
-+ (NSString *)buildXMLElementAs:(NSString *)rootName withValue:(NSObject *)value {
- return [[self class] buildXmlElementAs:rootName withInnerXml:[value toXMLValue] andType:[self xmlTypeFor:value]];
-}
-
-+ (NSString *)xmlElementName {
- NSString *className = NSStringFromClass(self);
- return [[className stringByReplacingCharactersInRange:NSMakeRange(0, 1) withString:[[className substringToIndex:1] lowercaseString]] dasherize];
-}
-
-# pragma mark XMLSerializable implementation methods
-
-- (NSString *)toXMLElement {
- return [self toXMLElementAs:[[self class] xmlElementName] excludingInArray:[NSArray array] withTranslations:[NSDictionary dictionary]];
-}
-
-- (NSString *)toXMLElementExcluding:(NSArray *)exclusions {
- return [self toXMLElementAs:[[self class] xmlElementName] excludingInArray:exclusions withTranslations:[NSDictionary dictionary]];
-}
-
-- (NSString *)toXMLElementAs:(NSString *)rootName {
- return [self toXMLElementAs:rootName excludingInArray:[NSArray array] withTranslations:[NSDictionary dictionary]];
-}
-
-- (NSString *)toXMLElementAs:(NSString *)rootName excludingInArray:(NSArray *)exclusions {
- return [self toXMLElementAs:rootName excludingInArray:exclusions withTranslations:[NSDictionary dictionary]];
-}
-
-- (NSString *)toXMLElementAs:(NSString *)rootName withTranslations:(NSDictionary *)keyTranslations {
- return [self toXMLElementAs:rootName excludingInArray:[NSArray array] withTranslations:keyTranslations];
-}
-
-/**
- * Override in complex objects to account for nested properties
- **/
-- (NSString *)toXMLElementAs:(NSString *)rootName excludingInArray:(NSArray *)exclusions
- withTranslations:(NSDictionary *)keyTranslations {
- return [[self properties] toXMLElementAs:rootName excludingInArray:exclusions withTranslations:keyTranslations andType:[[self class] xmlTypeFor:self]];
-}
-
-# pragma mark XML Serialization convenience methods
-
-/**
- * Override in objects that need special formatting before being printed to XML
- **/
-- (NSString *)toXMLValue {
- return [NSString stringWithFormat:@"%@", self];
-}
-
-# pragma mark XML Serialization input methods
-
-+ (id)fromXMLData:(NSData *)data {
-
- NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data];
- FromXMLElementDelegate *delegate = [FromXMLElementDelegate delegateForClass:self];
- [parser setDelegate:delegate];
-
- // Turn off all those XML nits
- [parser setShouldProcessNamespaces:NO];
- [parser setShouldReportNamespacePrefixes:NO];
- [parser setShouldResolveExternalEntities:NO];
-
- // Let'er rip
- [parser parse];
- [parser release];
- return delegate.parsedObject;
-}
-
-+ (NSArray *)allFromXMLData:(NSData *)data {
- return [self fromXMLData:data];
-}
-@end
View
20 Classes/lib/Serialization/XML/NSString+XMLSerializableSupport.h
@@ -1,20 +0,0 @@
-//
-// NSString+XMLSerializableSupport.h
-// active_resource
-//
-// Created by James Burka on 1/6/09.
-// Copyright 2009 Burkaprojects. All rights reserved.
-//
-
-#import <UIKit/UIKit.h>
-
-
-@interface NSString(XMLSerializableSupport)
-
-+ (NSString *)fromXmlString:(NSString *)aString;
-- (NSString *)toXMLValue;
-- (NSString *)toXMLElementAs:(NSString *)rootName excludingInArray:(NSArray *)exclusions
- withTranslations:(NSDictionary *)keyTranslations;
-
-
-@end
View
33 Classes/lib/Serialization/XML/NSString+XMLSerializableSupport.m
@@ -1,33 +0,0 @@
-//
-// NSString+XMLSerializableSupport.m
-// active_resource
-//
-// Created by James Burka on 1/6/09.
-// Copyright 2009 Burkaprojects. All rights reserved.
-//
-
-#import "NSString+XMLSerializableSupport.h"
-#import "NSObject+XMLSerializableSupport.h"
-#import "NSString+GSub.h"
-
-
-@implementation NSString(XMLSerializableSupport)
-
-+ (NSString *)fromXmlString:(NSString *)aString {
- NSDictionary* escapeChars = [NSDictionary dictionaryWithObjectsAndKeys:@"&",@"&amp;",@"\"",@"&quot;",@"'",@"&apos;"
- ,@"<",@"&lt;",@">",@"&gt;",nil];
- return [aString gsub:escapeChars];
-
-}
-
-- (NSString *)toXMLValue {
- NSString *temp = [self gsub:[NSDictionary dictionaryWithObject:@"&amp;" forKey:@"&"]];
- NSDictionary* escapeChars = [NSDictionary dictionaryWithObjectsAndKeys:@"&quot;",@"\"",@"&apos;",@"'",@"&lt;",@"<",@"&gt;",@">",nil];
- return [temp gsub:escapeChars];
-}
-- (NSString *)toXMLElementAs:(NSString *)rootName excludingInArray:(NSArray *)exclusions
- withTranslations:(NSDictionary *)keyTranslations {
- return [[self class] buildXmlElementAs:rootName withInnerXml:[self toXMLValue]];
-}
-
-@end
View
79 Classes/lib/Serialization/XML/XMLSerializable.h
@@ -1,79 +0,0 @@
-//
-// XMLSerializable.h
-//
-//
-// Created by Ryan Daigle on 7/31/08.
-// Copyright 2008 yFactorial, LLC. All rights reserved.
-//
-
-@protocol XMLSerializable
-
-/**
- * Instantiate a single instance of this class from the given XML data.
- */
-+ (id)fromXMLData:(NSData *)data;
-
-/**
- * Instantiate a collectionof instances of this class from the given XML data.
- */
-+ (NSArray *)allFromXMLData:(NSData *)data;
-
-/**
- * Get the full XML representation of this object (minus the xml directive)
- * using the default element name:
- *
- * [myPerson toXMLElement] //> @"<person><first_name>Ryan</first_name>...</person>"
- */
-- (NSString *)toXMLElement;
-
-
-/**
- * Gets the full representation of this object minus the elements in the exclusions array
- *
- *
- *
- */
-- (NSString *)toXMLElementExcluding:(NSArray *)exclusions;
-
-/**
- * Get the full XML representation of this object (minus the xml directive)
- * using the given element name:
- *
- * [myPerson toXMLElementAs:@"human"] //> @"<human><first_name>Ryan</first_name>...</human>"
- */
-- (NSString *)toXMLElementAs:(NSString *)rootName;
-
-/**
- * Get the full XML representation of this object (minus the xml directive)
- * using the given element name and excluding the given properties.
- *
- * [myPerson toXMLElementAs:@"human" excludingInArray:[NSArray arrayWithObjects:@"firstName", nil]]
- *
- * //> @"<human><last-name>Daigle</last-name></human>
- */
-- (NSString *)toXMLElementAs:(NSString *)rootName excludingInArray:(NSArray *)exclusions;
-
-/**
- * Get the full XML representation of this object (minus the xml directive)
- * using the given element name and translating property names with the keyTranslations mapping.
- *
- * [myPerson toXMLElementAs:@"human" withTranslations:[NSDictionary dictionaryWithObjectsAndKeys:@"lastName", @"surname", nil]]
- *
- * //> @"<human><first-name>Ryan</first-name><surname>Daigle</surname></human>
- */
-- (NSString *)toXMLElementAs:(NSString *)rootName withTranslations:(NSDictionary *)keyTranslations;
-
-/**
- * Get the full XML representation of this object (minus the xml directive)
- * using the given element name, excluding the given properties, and translating
- * property names with the keyTranslations mapping.
- *
- * [myPerson toXMLElementAs:@"human" excludingInArray:[NSArray arrayWithObjects:@"firstName", nil]
- * withTranslations:[NSDictionary dictionaryWithObjectsAndKeys:@"lastName", @"surname", nil]]
- *
- * //> @"<human><surname>Daigle</surname></human>
- */
-- (NSString *)toXMLElementAs:(NSString *)rootName excludingInArray:(NSArray *)exclusions
- withTranslations:(NSDictionary *)keyTranslations;
-
-@end
View
14 Classes/lib/Serialization/XML/XMLSerializableSupport.h
@@ -1,14 +0,0 @@
-//
-// XMLSerializableSupport.h
-//
-//
-// Created by Ryan Daigle on 7/31/08.
-// Copyright 2008 yFactorial, LLC. All rights reserved.
-//
-
-#import "XMLSerializable.h"
-#import "CoreSupport.h"
-#import "NSObject+XMLSerializableSupport.h"
-#import "NSNull+XMLSerializableSupport.h"
-#import "NSDate+XMLSerializableSupport.h"
-#import "NSString+XMLSerializableSupport.h"
View
11 Classes/lib/json-framework/JSONFramework.h
@@ -1,11 +0,0 @@
-//
-// JSONFramework.h
-// iphoneAndRails1
-//
-// Created by vickeryj on 12/11/08.
-// Copyright 2008 Joshua Vickery. All rights reserved.
-//
-
-#import "SBJSON.h"
-#import "NSObject+SBJSON.h"
-#import "NSString+SBJSON.h"
View
60 Classes/lib/json-framework/NSObject+SBJSON.h
@@ -1,60 +0,0 @@
-/*
-Copyright (C) 2007 Stig Brautaset. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
- Redistributions of source code must retain the above copyright notice, this
- list of conditions and the following disclaimer.
-
- Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-
- Neither the name of the author nor the names of its contributors may be used
- to endorse or promote products derived from this software without specific
- prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
-FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#import <Foundation/Foundation.h>
-
-
-/// Adds JSON generation to NSObject subclasses
-@interface NSObject (NSObject_SBJSON)
-
-/**
- @brief Returns a string containing the receiver encoded as a JSON fragment.
-
- This method is added as a category on NSObject but is only actually
- supported for the following objects:
- @li NSDictionary
- @li NSArray
- @li NSString
- @li NSNumber (also used for booleans)
- @li NSNull
- */
-- (NSString *)JSONFragment;
-
-/**
- @brief Returns a string containing the receiver encoded in JSON.
-
- This method is added as a category on NSObject but is only actually
- supported for the following objects:
- @li NSDictionary
- @li NSArray
- */
-- (NSString *)JSONRepresentation;
-
-@end
-
View
57 Classes/lib/json-framework/NSObject+SBJSON.m
@@ -1,57 +0,0 @@
-/*
-Copyright (C) 2007 Stig Brautaset. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
- Redistributions of source code must retain the above copyright notice, this
- list of conditions and the following disclaimer.
-
- Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-
- Neither the name of the author nor the names of its contributors may be used
- to endorse or promote products derived from this software without specific
- prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
-FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#import "NSObject+SBJSON.h"
-#import "SBJSON.h"
-
-@implementation NSObject (NSObject_SBJSON)
-
-- (NSString *)JSONFragment {
- SBJSON *generator = [[SBJSON new] autorelease];
-
- NSError *error;
- NSString *json = [generator stringWithFragment:self error:&error];
-
- if (!json)
- NSLog(@"%@", error);
- return json;
-}
-
-- (NSString *)JSONRepresentation {
- SBJSON *generator = [[SBJSON new] autorelease];
-
- NSError *error;
- NSString *json = [generator stringWithObject:self error:&error];
-
- if (!json)
- NSLog(@"%@", error);
- return json;
-}
-
-@end
View
41 Classes/lib/json-framework/NSString+SBJSON.h
@@ -1,41 +0,0 @@
-/*
-Copyright (C) 2007 Stig Brautaset. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
- Redistributions of source code must retain the above copyright notice, this
- list of conditions and the following disclaimer.
-
- Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-
- Neither the name of the author nor the names of its contributors may be used
- to endorse or promote products derived from this software without specific
- prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
-FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#import <Foundation/Foundation.h>
-
-/// Adds JSON parsing to NSString
-@interface NSString (NSString_SBJSON)
-
-/// Returns the object represented in the receiver, or nil on error.
-- (id)JSONFragmentValue;
-
-/// Returns the dictionary or array represented in the receiver, or nil on error.
-- (id)JSONValue;
-
-@end
View
60 Classes/lib/json-framework/NSString+SBJSON.m
@@ -1,60 +0,0 @@
-/*
-Copyright (C) 2007 Stig Brautaset. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
- Redistributions of source code must retain the above copyright notice, this
- list of conditions and the following disclaimer.
-
- Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-
- Neither the name of the author nor the names of its contributors may be used
- to endorse or promote products derived from this software without specific
- prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
-FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#import "NSString+SBJSON.h"
-#import "SBJSON.h"
-
-
-@implementation NSString (NSString_SBJSON)
-
-- (id)JSONFragmentValue
-{
- SBJSON *json = [[SBJSON new] autorelease];
-
- NSError *error;
- id o = [json fragmentWithString:self error:&error];
-
- if (!o)
- NSLog(@"%@", error);
- return o;
-}
-
-- (id)JSONValue
-{
- SBJSON *json = [[SBJSON new] autorelease];
-
- NSError *error;
- id o = [json objectWithString:self error:&error];
-
- if (!o)
- NSLog(@"%@", error);
- return o;
-}
-
-@end
View
137 Classes/lib/json-framework/SBJSON.h
@@ -1,137 +0,0 @@
-/*
-Copyright (C) 2008 Stig Brautaset. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
- Redistributions of source code must retain the above copyright notice, this
- list of conditions and the following disclaimer.
-
- Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-
- Neither the name of the author nor the names of its contributors may be used
- to endorse or promote products derived from this software without specific
- prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
-FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#import <Foundation/Foundation.h>
-
-extern NSString * SBJSONErrorDomain;
-
-enum {
- EUNSUPPORTED = 1,
- EPARSENUM,
- EPARSE,
- EFRAGMENT,
- ECTRL,
- EUNICODE,
- EDEPTH,
- EESCAPE,
- ETRAILCOMMA,
- ETRAILGARBAGE,
- EEOF,
- EINPUT
-};
-
-/**
-@brief A strict JSON parser and generator
-
-This is the parser and generator underlying the categories added to
-NSString and various other objects.
-
-Objective-C types are mapped to JSON types and back in the following way:
-
-@li NSNull -> Null -> NSNull
-@li NSString -> String -> NSMutableString
-@li NSArray -> Array -> NSMutableArray
-@li NSDictionary -> Object -> NSMutableDictionary
-@li NSNumber (-initWithBool:) -> Boolean -> NSNumber -initWithBool:
-@li NSNumber -> Number -> NSDecimalNumber
-
-In JSON the keys of an object must be strings. NSDictionary keys need
-not be, but attempting to convert an NSDictionary with non-string keys
-into JSON will throw an exception.
-
-NSNumber instances created with the +numberWithBool: method are
-converted into the JSON boolean "true" and "false" values, and vice
-versa. Any other NSNumber instances are converted to a JSON number the
-way you would expect. JSON numbers turn into NSDecimalNumber instances,
-as we can thus avoid any loss of precision.
-
-Strictly speaking correctly formed JSON text must have <strong>exactly
-one top-level container</strong>. (Either an Array or an Object.) Scalars,
-i.e. nulls, numbers, booleans and strings, are not valid JSON on their own.
-It can be quite convenient to pretend that such fragments are valid
-JSON however, and this class lets you do so.
-
-This class does its best to be as strict as possible, both in what it
-accepts and what it generates. (Other than the above mentioned support
-for JSON fragments.) For example, it does not support trailing commas
-in arrays or objects. Nor does it support embedded comments, or
-anything else not in the JSON specification.
-
-*/
-@interface SBJSON : NSObject {
- BOOL humanReadable;
- BOOL sortKeys;
- NSUInteger maxDepth;
-
-@private
- // Used temporarily during scanning/generation
- NSUInteger depth;
- const char *c;
-}
-
-/// Whether we are generating human-readable (multiline) JSON
-/**
- Set whether or not to generate human-readable JSON. The default is NO, which produces
- JSON without any whitespace. (Except inside strings.) If set to YES, generates human-readable
- JSON with linebreaks after each array value and dictionary key/value pair, indented two
- spaces per nesting level.
- */
-@property BOOL humanReadable;
-
-/// Whether or not to sort the dictionary keys in the output
-/** The default is to not sort the keys. */
-@property BOOL sortKeys;
-
-/// The maximum depth the parser will go to
-/** Defaults to 512. */
-@property NSUInteger maxDepth;
-
-/// Return JSON representation of an array or dictionary
-- (NSString*)stringWithObject:(id)value error:(NSError**)error;
-
-/// Return JSON representation of any legal JSON value
-- (NSString*)stringWithFragment:(id)value error:(NSError**)error;
-
-/// Return the object represented by the given string
-- (id)objectWithString:(NSString*)jsonrep error:(NSError**)error;
-
-/// Return the fragment represented by the given string
-- (id)fragmentWithString:(NSString*)jsonrep error:(NSError**)error;
-
-/// Return JSON representation (or fragment) for the given object
-- (NSString*)stringWithObject:(id)value
- allowScalar:(BOOL)x
- error:(NSError**)error;
-
-/// Parse the string and return the represented object (or scalar)
-- (id)objectWithString:(id)value
- allowScalar:(BOOL)x
- error:(NSError**)error;
-
-@end
View
740 Classes/lib/json-framework/SBJSON.m
@@ -1,740 +0,0 @@
-/*
-Copyright (C) 2008 Stig Brautaset. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
- Redistributions of source code must retain the above copyright notice, this
- list of conditions and the following disclaimer.
-
- Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-
- Neither the name of the author nor the names of its contributors may be used
- to endorse or promote products derived from this software without specific
- prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
-FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#import "SBJSON.h"
-
-NSString * SBJSONErrorDomain = @"org.brautaset.JSON.ErrorDomain";
-
-@interface SBJSON (Generator)
-
-- (BOOL)appendValue:(id)fragment into:(NSMutableString*)json error:(NSError**)error;
-- (BOOL)appendArray:(NSArray*)fragment into:(NSMutableString*)json error:(NSError**)error;
-- (BOOL)appendDictionary:(NSDictionary*)fragment into:(NSMutableString*)json error:(NSError**)error;
-- (BOOL)appendString:(NSString*)fragment into:(NSMutableString*)json error:(NSError**)error;
-
-- (NSString*)indent;
-
-@end
-
-@interface SBJSON (Scanner)
-
-- (BOOL)scanValue:(NSObject **)o error:(NSError **)error;
-
-- (BOOL)scanRestOfArray:(NSMutableArray **)o error:(NSError **)error;
-- (BOOL)scanRestOfDictionary:(NSMutableDictionary **)o error:(NSError **)error;
-- (BOOL)scanRestOfNull:(NSNull **)o error:(NSError **)error;
-- (BOOL)scanRestOfFalse:(NSNumber **)o error:(NSError **)error;
-- (BOOL)scanRestOfTrue:(NSNumber **)o error:(NSError **)error;
-- (BOOL)scanRestOfString:(NSMutableString **)o error:(NSError **)error;
-
-// Cannot manage without looking at the first digit
-- (BOOL)scanNumber:(NSNumber **)o error:(NSError **)error;
-
-- (BOOL)scanHexQuad:(unichar *)x error:(NSError **)error;
-- (BOOL)scanUnicodeChar:(unichar *)x error:(NSError **)error;
-
-- (BOOL)scanIsAtEnd;
-
-@end
-
-#pragma mark Private utilities
-
-#define skipWhitespace(c) while (isspace(*c)) c++
-#define skipDigits(c) while (isdigit(*c)) c++
-
-static NSError *err(int code, NSString *str) {
- NSDictionary *ui = [NSDictionary dictionaryWithObject:str forKey:NSLocalizedDescriptionKey];
- return [NSError errorWithDomain:SBJSONErrorDomain code:code userInfo:ui];
-}
-
-static NSError *errWithUnderlier(int code, NSError **u, NSString *str) {
- if (!u)
- return err(code, str);
-
- NSDictionary *ui = [NSDictionary dictionaryWithObjectsAndKeys:
- str, NSLocalizedDescriptionKey,
- *u, NSUnderlyingErrorKey,
- nil];
- return [NSError errorWithDomain:SBJSONErrorDomain code:code userInfo:ui];
-}
-
-
-@implementation SBJSON
-
-static char ctrl[0x22];
-
-+ (void)initialize
-{
- ctrl[0] = '\"';
- ctrl[1] = '\\';
- for (int i = 1; i < 0x20; i++)
- ctrl[i+1] = i;
- ctrl[0x21] = 0;
-}
-
-- (id)init {
- if (self = [super init]) {
- [self setMaxDepth:512];
- }
- return self;
-}
-
-#pragma mark Generator
-
-
-/**
- Returns a string containing JSON representation of the passed in value, or nil on error.
- If nil is returned and @p error is not NULL, @p *error can be interrogated to find the cause of the error.
-
- @param value any instance that can be represented as a JSON fragment
- @param allowScalar wether to return json fragments for scalar objects
- @param error used to return an error by reference (pass NULL if this is not desired)
- */
-- (NSString*)stringWithObject:(id)value allowScalar:(BOOL)allowScalar error:(NSError**)error {
- depth = 0;
- NSMutableString *json = [NSMutableString stringWithCapacity:128];
-
- NSError *err2 = nil;
- if (!allowScalar && ![value isKindOfClass:[NSDictionary class]] && ![value isKindOfClass:[NSArray class]]) {
- err2 = err(EFRAGMENT, @"Not valid type for JSON");
-
- } else if ([self appendValue:value into:json error:&err2]) {
- return json;
- }
-
- if (error)
- *error = err2;
- return nil;
-}
-
-/**
- Returns a string containing JSON representation of the passed in value, or nil on error.
- If nil is returned and @p error is not NULL, @p error can be interrogated to find the cause of the error.
-
- @param value any instance that can be represented as a JSON fragment
- @param error used to return an error by reference (pass NULL if this is not desired)
- */
-- (NSString*)stringWithFragment:(id)value error:(NSError**)error {
- return [self stringWithObject:value allowScalar:YES error:error];
-}
-
-/**
- Returns a string containing JSON representation of the passed in value, or nil on error.
- If nil is returned and @p error is not NULL, @p error can be interrogated to find the cause of the error.
-
- @param value a NSDictionary or NSArray instance
- @param error used to return an error by reference (pass NULL if this is not desired)
- */
-- (NSString*)stringWithObject:(id)value error:(NSError**)error {
- return [self stringWithObject:value allowScalar:NO error:error];
-}
-
-
-- (NSString*)indent {
- return [@"\n" stringByPaddingToLength:1 + 2 * depth withString:@" " startingAtIndex:0];
-}
-
-- (BOOL)appendValue:(id)fragment into:(NSMutableString*)json error:(NSError**)error {
- if ([fragment isKindOfClass:[NSDictionary class]]) {
- if (![self appendDictionary:fragment into:json error:error])
- return NO;
-
- } else if ([fragment isKindOfClass:[NSArray class]]) {
- if (![self appendArray:fragment into:json error:error])
- return NO;
-
- } else if ([fragment isKindOfClass:[NSString class]]) {
- if (![self appendString:fragment into:json error:error])
- return NO;
-
- } else if ([fragment isKindOfClass:[NSNumber class]]) {
- if ('c' == *[fragment objCType])
- [json appendString:[fragment boolValue] ? @"true" : @"false"];
- else
- [json appendString:[fragment stringValue]];
-
- } else if ([fragment isKindOfClass:[NSNull class]]) {
- [json appendString:@"null"];
-
- } else {
- *error = err(EUNSUPPORTED, [NSString stringWithFormat:@"JSON serialisation not supported for %@", [fragment class]]);
- return NO;
- }
- return YES;
-}
-
-- (BOOL)appendArray:(NSArray*)fragment into:(NSMutableString*)json error:(NSError**)error {
- [json appendString:@"["];
- depth++;
-
- BOOL addComma = NO;
- for (id value in fragment) {
- if (addComma)
- [json appendString:@","];
- else
- addComma = YES;
-
- if ([self humanReadable])
- [json appendString:[self indent]];
-
- if (![self appendValue:value into:json error:error]) {
- return NO;
- }
- }
-
- depth--;
- if ([self humanReadable] && [fragment count])
- [json appendString:[self indent]];
- [json appendString:@"]"];
- return YES;
-}
-
-- (BOOL)appendDictionary:(NSDictionary*)fragment into:(NSMutableString*)json error:(NSError**)error {
- [json appendString:@"{"];
- depth++;
-
- NSString *colon = [self humanReadable] ? @" : " : @":";
- BOOL addComma = NO;
- NSArray *keys = [fragment allKeys];
- if (self.sortKeys)
- keys = [keys sortedArrayUsingSelector:@selector(compare:)];
-
- for (id value in keys) {
- if (addComma)
- [json appendString:@","];
- else
- addComma = YES;
-
- if ([self humanReadable])
- [json appendString:[self indent]];
-
- if (![value isKindOfClass:[NSString class]]) {
- *error = err(EUNSUPPORTED, @"JSON object key must be string");
- return NO;
- }
-
- if (![self appendString:value into:json error:error])
- return NO;
-
- [json appendString:colon];
- if (![self appendValue:[fragment objectForKey:value] into:json error:error]) {
- *error = err(EUNSUPPORTED, [NSString stringWithFormat:@"Unsupported value for key %@ in object", value]);
- return NO;
- }
- }
-
- depth--;
- if ([self humanReadable] && [fragment count])
- [json appendString:[self indent]];
- [json appendString:@"}"];
- return YES;
-}
-
-- (BOOL)appendString:(NSString*)fragment into:(NSMutableString*)json error:(NSError**)error {
-
- static NSMutableCharacterSet *kEscapeChars;
- if( ! kEscapeChars ) {
- kEscapeChars = [[NSMutableCharacterSet characterSetWithRange: NSMakeRange(0,32)] retain];
- [kEscapeChars addCharactersInString: @"\"\\"];
- }
-
- [json appendString:@"\""];
-
- NSRange esc = [fragment rangeOfCharacterFromSet:kEscapeChars];
- if ( !esc.length ) {
- // No special chars -- can just add the raw string:
- [json appendString:fragment];
-
- } else {
- NSUInteger length = [fragment length];
- for (NSUInteger i = 0; i < length; i++) {
- unichar uc = [fragment characterAtIndex:i];
- switch (uc) {
- case '"': [json appendString:@"\\\""]; break;
- case '\\': [json appendString:@"\\\\"]; break;
- case '\t': [json appendString:@"\\t"]; break;
- case '\n': [json appendString:@"\\n"]; break;
- case '\r': [json appendString:@"\\r"]; break;
- case '\b': [json appendString:@"\\b"]; break;
- case '\f': [json appendString:@"\\f"]; break;
- default:
- if (uc < 0x20) {
- [json appendFormat:@"\\u%04x", uc];
- } else {
- [json appendFormat:@"%C", uc];
- }
- break;
-
- }
- }
- }
-
- [json appendString:@"\""];
- return YES;
-}
-
-#pragma mark Parser
-
-/**
- Returns the object represented by the passed-in string or nil on error. The returned object can be
- a string, number, boolean, null, array or dictionary.
-
- @param repr the json string to parse
- @param allowScalar whether to return objects for JSON fragments
- @param error used to return an error by reference (pass NULL if this is not desired)
- */
-- (id)objectWithString:(id)repr allowScalar:(BOOL)allowScalar error:(NSError**)error {
-
- if (!repr) {
- if (error)
- *error = err(EINPUT, @"Input was 'nil'");
- return nil;
- }
-
- depth = 0;
- c = [repr UTF8String];
-
- id o;
- NSError *err2 = nil;
- if (![self scanValue:&o error:&err2]) {
- if (error)
- *error = err2;
- return nil;
- }
-
- // We found some valid JSON. But did it also contain something else?
- if (![self scanIsAtEnd]) {
- if (error)
- *error = err(ETRAILGARBAGE, @"Garbage after JSON");
- return nil;
- }
-
- // If we don't allow scalars, check that the object we've found is a valid JSON container.
- if (!allowScalar && ![o isKindOfClass:[NSDictionary class]] && ![o isKindOfClass:[NSArray class]]) {
- if (error)
- *error = err(EFRAGMENT, @"Valid fragment, but not JSON");
- return nil;
- }
-
- NSAssert1(o, @"Should have a valid object from %@", repr);
- return o;
-}
-
-/**
- Returns the object represented by the passed-in string or nil on error. The returned object can be
- a string, number, boolean, null, array or dictionary.
-
- @param repr the json string to parse
- @param error used to return an error by reference (pass NULL if this is not desired)
- */
-- (id)fragmentWithString:(NSString*)repr error:(NSError**)error {
- return [self objectWithString:repr allowScalar:YES error:error];
-}
-
-/**
- Returns the object represented by the passed-in string or nil on error. The returned object
- will be either a dictionary or an array.
-
- @param repr the json string to parse
- @param error used to return an error by reference (pass NULL if this is not desired)
- */
-- (id)objectWithString:(NSString*)repr error:(NSError**)error {
- return [self objectWithString:repr allowScalar:NO error:error];
-}
-
-/*
- In contrast to the public methods, it is an error to omit the error parameter here.
- */
-- (BOOL)scanValue:(NSObject **)o error:(NSError **)error
-{
- skipWhitespace(c);
-
- switch (*c++) {
- case '{':
- return [self scanRestOfDictionary:(NSMutableDictionary **)o error:error];
- break;
- case '[':
- return [self scanRestOfArray:(NSMutableArray **)o error:error];
- break;
- case '"':
- return [self scanRestOfString:(NSMutableString **)o error:error];
- break;
- case 'f':
- return [self scanRestOfFalse:(NSNumber **)o error:error];
- break;
- case 't':
- return [self scanRestOfTrue:(NSNumber **)o error:error];
- break;
- case 'n':
- return [self scanRestOfNull:(NSNull **)o error:error];
- break;
- case '-':
- case '0'...'9':
- c--; // cannot verify number correctly without the first character
- return [self scanNumber:(NSNumber **)o error:error];
- break;
- case '+':
- *error = err(EPARSENUM, @"Leading + disallowed in number");
- return NO;
- break;
- case 0x0:
- *error = err(EEOF, @"Unexpected end of string");
- return NO;
- break;
- default:
- *error = err(EPARSE, @"Unrecognised leading character");
- return NO;
- break;
- }
-
- NSAssert(0, @"Should never get here");
- return NO;
-}
-
-- (BOOL)scanRestOfTrue:(NSNumber **)o error:(NSError **)error
-{
- if (!strncmp(c, "rue", 3)) {
- c += 3;
- *o = [NSNumber numberWithBool:YES];
- return YES;
- }
- *error = err(EPARSE, @"Expected 'true'");
- return NO;
-}
-
-- (BOOL)scanRestOfFalse:(NSNumber **)o error:(NSError **)error
-{
- if (!strncmp(c, "alse", 4)) {
- c += 4;
- *o = [NSNumber numberWithBool:NO];
- return YES;
- }
- *error = err(EPARSE, @"Expected 'false'");
- return NO;
-}
-
-- (BOOL)scanRestOfNull:(NSNull **)o error:(NSError **)error
-{
- if (!strncmp(c, "ull", 3)) {
- c += 3;
- *o = [NSNull null];
- return YES;
- }
- *error = err(EPARSE, @"Expected 'null'");
- return NO;
-}
-
-- (BOOL)scanRestOfArray:(NSMutableArray **)o error:(NSError **)error
-{
- if (maxDepth && ++depth > maxDepth) {
- *error = err(EDEPTH, @"Nested too deep");
- return NO;
- }
-
- *o = [NSMutableArray arrayWithCapacity:8];
-
- for (; *c ;) {
- id v;
-
- skipWhitespace(c);
- if (*c == ']' && c++) {
- depth--;
- return YES;
- }
-
- if (![self scanValue:&v error:error]) {
- *error = errWithUnderlier(EPARSE, error, @"Expected value while parsing array");
- return NO;
- }
-
- [*o addObject:v];
-
- skipWhitespace(c);
- if (*c == ',' && c++) {
- skipWhitespace(c);
- if (*c == ']') {
- *error = err(ETRAILCOMMA, @"Trailing comma disallowed in array");
- return NO;
- }
- }
- }
-
- *error = err(EEOF, @"End of input while parsing array");
- return NO;
-}
-
-- (BOOL)scanRestOfDictionary:(NSMutableDictionary **)o error:(NSError **)error
-{
- if (maxDepth && ++depth > maxDepth) {
- *error = err(EDEPTH, @"Nested too deep");
- return NO;
- }
-
- *o = [NSMutableDictionary dictionaryWithCapacity:7];
-
- for (; *c ;) {
- id k, v;
-
- skipWhitespace(c);
- if (*c == '}' && c++) {
- depth--;
- return YES;
- }
-
- if (!(*c == '\"' && c++ && [self scanRestOfString:&k error:error])) {
- *error = errWithUnderlier(EPARSE, error, @"Object key string expected");
- return NO;
- }
-
- skipWhitespace(c);
- if (*c != ':') {
- *error = err(EPARSE, @"Expected ':' separating key and value");
- return NO;
- }
-
- c++;
- if (![self scanValue:&v error:error]) {
- NSString *string = [NSString stringWithFormat:@"Object value expected for key: %@", k];
- *error = errWithUnderlier(EPARSE, error, string);
- return NO;
- }
-
- [*o setObject:v forKey:k];
-
- skipWhitespace(c);
- if (*c == ',' && c++) {
- skipWhitespace(c);
- if (*c == '}') {
- *error = err(ETRAILCOMMA, @"Trailing comma disallowed in object");
- return NO;
- }
- }
- }
-
- *error = err(EEOF, @"End of input while parsing object");
- return NO;
-}
-
-- (BOOL)scanRestOfString:(NSMutableString **)o error:(NSError **)error
-{
- *o = [NSMutableString stringWithCapacity:16];
- do {
- // First see if there's a portion we can grab in one go.
- // Doing this caused a massive speedup on the long string.
- size_t len = strcspn(c, ctrl);
- if (len) {
- // check for
- id t = [[NSString alloc] initWithBytesNoCopy:(char*)c
- length:len
- encoding:NSUTF8StringEncoding
- freeWhenDone:NO];
- if (t) {
- [*o appendString:t];
- [t release];
- c += len;
- }
- }
-
- if (*c == '"') {
- c++;
- return YES;
-
- } else if (*c == '\\') {
- unichar uc = *++c;
- switch (uc) {
- case '\\':
- case '/':
- case '"':
- break;
-
- case 'b': uc = '\b'; break;
- case 'n': uc = '\n'; break;
- case 'r': uc = '\r'; break;
- case 't': uc = '\t'; break;
- case 'f': uc = '\f'; break;
-
- case 'u':
- c++;
- if (![self scanUnicodeChar:&uc error:error]) {
- *error = errWithUnderlier(EUNICODE, error, @"Broken unicode character");
- return NO;
- }
- c--; // hack.
- break;
- default:
- *error = err(EESCAPE, [NSString stringWithFormat:@"Illegal escape sequence '0x%x'", uc]);
- return NO;
- break;
- }
- [*o appendFormat:@"%C", uc];
- c++;
-
- } else if (*c < 0x20) {
- *error = err(ECTRL, [NSString stringWithFormat:@"Unescaped control character '0x%x'", *c]);
- return NO;
-
- } else {
- NSLog(@"should not be able to get here");
- }
- } while (*c);
-
- *error = err(EEOF, @"Unexpected EOF while parsing string");
- return NO;
-}
-
-- (BOOL)scanUnicodeChar:(unichar *)x error:(NSError **)error
-{
- unichar hi, lo;
-
- if (![self scanHexQuad:&hi error:error]) {
- *error = err(EUNICODE, @"Missing hex quad");
- return NO;
- }
-
- if (hi >= 0xd800) { // high surrogate char?
- if (hi < 0xdc00) { // yes - expect a low char
-
- if (!(*c == '\\' && ++c && *c == 'u' && ++c && [self scanHexQuad:&lo error:error])) {
- *error = errWithUnderlier(EUNICODE, error, @"Missing low character in surrogate pair");
- return NO;
- }
-
- if (lo < 0xdc00 || lo >= 0xdfff) {
- *error = err(EUNICODE, @"Invalid low surrogate char");
- return NO;
- }
-
- hi = (hi - 0xd800) * 0x400 + (lo - 0xdc00) + 0x10000;
-
- } else if (hi < 0xe000) {
- *error = err(EUNICODE, @"Invalid high character in surrogate pair");
- return NO;
- }
- }
-
- *x = hi;
- return YES;
-}
-
-- (BOOL)scanHexQuad:(unichar *)x error:(NSError **)error
-{
- *x = 0;
- for (int i = 0; i < 4; i++) {
- unichar uc = *c;
- c++;
- int d = (uc >= '0' && uc <= '9')
- ? uc - '0' : (uc >= 'a' && uc <= 'f')
- ? (uc - 'a' + 10) : (uc >= 'A' && uc <= 'F')
- ? (uc - 'A' + 10) : -1;
- if (d == -1) {
- *error = err(EUNICODE, @"Missing hex digit in quad");
- return NO;
- }
- *x *= 16;
- *x += d;
- }
- return YES;
-}
-
-- (BOOL)scanNumber:(NSNumber **)o error:(NSError **)error
-{
- const char *ns = c;
-
- // The logic to test for validity of the number formatting is relicensed
- // from JSON::XS with permission from its author Marc Lehmann.
- // (Available at the CPAN: http://search.cpan.org/dist/JSON-XS/ .)
-
- if ('-' == *c)
- c++;
-
- if ('0' == *c && c++) {
- if (isdigit(*c)) {
- *error = err(EPARSENUM, @"Leading 0 disallowed in number");
- return NO;
- }
-
- } else if (!isdigit(*c) && c != ns) {
- *error = err(EPARSENUM, @"No digits after initial minus");
- return NO;
-
- } else {
- skipDigits(c);
- }
-
- // Fractional part
- if ('.' == *c && c++) {
-
- if (!isdigit(*c)) {
- *error = err(EPARSENUM, @"No digits after decimal point");
- return NO;
- }
- skipDigits(c);
- }
-
- // Exponential part
- if ('e' == *c || 'E' == *c) {
- c++;
-
- if ('-' == *c || '+' == *c)
- c++;
-
- if (!isdigit(*c)) {
- *error = err(EPARSENUM, @"No digits after exponent");
- return NO;
- }
- skipDigits(c);
- }
-
- id str = [[NSString alloc] initWithBytesNoCopy:(char*)ns
- length:c - ns
- encoding:NSUTF8StringEncoding
- freeWhenDone:NO];
- [str autorelease];
- if (str && (*o = [NSDecimalNumber decimalNumberWithString:str]))
- return YES;
-
- *error = err(EPARSENUM, @"Failed creating decimal instance");
- return NO;
-}
-
-- (BOOL)scanIsAtEnd
-{
- skipWhitespace(c);
- return !*c;
-}
-
-
-
-#pragma mark Properties
-
-@synthesize humanReadable;
-@synthesize sortKeys;
-@synthesize maxDepth;
-
-@end
View
16 Classes/unit_tests/XMLDeserializeTest.h
@@ -1,16 +0,0 @@
-//
-// XMLDeserializeTest.h
-// objective_support
-//
-// Created by James Burka on 2/13/09.
-// Copyright 2009 Burkaprojects. All rights reserved.
-//
-
-#import "GTMSenTestCase.h"
-
-
-@interface XMLDeserializeTest : SenTestCase {
-