Permalink
Browse files

Importing

  • Loading branch information...
gabriel committed Oct 30, 2009
0 parents commit cb4de69a8f7016040b823030868d99eed42e2fea
Showing with 7,556 additions and 0 deletions.
  1. +18 −0 Classes/JSONPerfTestAppDelegate.h
  2. +34 −0 Classes/JSONPerfTestAppDelegate.m
  3. +43 −0 Classes/JSONTest.h
  4. +49 −0 Classes/JSONTest.m
  5. +1 −0 Data/delicious_popular.json
  6. +1 −0 Data/lastfm.json
  7. +1 −0 Data/twitter_public.json
  8. +1 −0 Data/yelp.json
  9. +50 −0 Frameworks/SBJSON-2.2.2/JSON.h
  10. +68 −0 Frameworks/SBJSON-2.2.2/NSObject+SBJSON.h
  11. +53 −0 Frameworks/SBJSON-2.2.2/NSObject+SBJSON.m
  12. +58 −0 Frameworks/SBJSON-2.2.2/NSString+SBJSON.h
  13. +55 −0 Frameworks/SBJSON-2.2.2/NSString+SBJSON.m
  14. +75 −0 Frameworks/SBJSON-2.2.2/SBJSON.h
  15. +212 −0 Frameworks/SBJSON-2.2.2/SBJSON.m
  16. +86 −0 Frameworks/SBJSON-2.2.2/SBJsonBase.h
  17. +78 −0 Frameworks/SBJSON-2.2.2/SBJsonBase.m
  18. +87 −0 Frameworks/SBJSON-2.2.2/SBJsonParser.h
  19. +475 −0 Frameworks/SBJSON-2.2.2/SBJsonParser.m
  20. +129 −0 Frameworks/SBJSON-2.2.2/SBJsonWriter.h
  21. +228 −0 Frameworks/SBJSON-2.2.2/SBJsonWriter.m
  22. +68 −0 Frameworks/TouchJSON/CDataScanner.h
  23. +270 −0 Frameworks/TouchJSON/CDataScanner.m
  24. +37 −0 Frameworks/TouchJSON/Extensions/CDataScanner_Extensions.h
  25. +80 −0 Frameworks/TouchJSON/Extensions/CDataScanner_Extensions.m
  26. +36 −0 Frameworks/TouchJSON/Extensions/NSCharacterSet_Extensions.h
  27. +48 −0 Frameworks/TouchJSON/Extensions/NSCharacterSet_Extensions.m
  28. +36 −0 Frameworks/TouchJSON/Extensions/NSDictionary_JSONExtensions.h
  29. +41 −0 Frameworks/TouchJSON/Extensions/NSDictionary_JSONExtensions.m
  30. +44 −0 Frameworks/TouchJSON/Extensions/NSScanner_Extensions.h
  31. +118 −0 Frameworks/TouchJSON/Extensions/NSScanner_Extensions.m
  32. +46 −0 Frameworks/TouchJSON/JSON/CJSONDataSerializer.h
  33. +229 −0 Frameworks/TouchJSON/JSON/CJSONDataSerializer.m
  34. +45 −0 Frameworks/TouchJSON/JSON/CJSONDeserializer.h
  35. +95 −0 Frameworks/TouchJSON/JSON/CJSONDeserializer.m
  36. +44 −0 Frameworks/TouchJSON/JSON/CJSONScanner.h
  37. +539 −0 Frameworks/TouchJSON/JSON/CJSONScanner.m
  38. +47 −0 Frameworks/TouchJSON/JSON/CJSONSerializer.h
  39. +75 −0 Frameworks/TouchJSON/JSON/CJSONSerializer.m
  40. +40 −0 Frameworks/TouchJSON/JSON/CSerializedJSONData.h
  41. +54 −0 Frameworks/TouchJSON/JSON/CSerializedJSONData.m
  42. +107 −0 Frameworks/libYAJLIPhone-0.2.6/NSObject+YAJL.h
  43. +34 −0 Frameworks/libYAJLIPhone-0.2.6/YAJL.h
  44. +84 −0 Frameworks/libYAJLIPhone-0.2.6/YAJLDocument.h
  45. +86 −0 Frameworks/libYAJLIPhone-0.2.6/YAJLGen.h
  46. +120 −0 Frameworks/libYAJLIPhone-0.2.6/YAJLParser.h
  47. BIN Frameworks/libYAJLIPhone-0.2.6/libYAJLIPhone.a
  48. +85 −0 Frameworks/libYAJLIPhone-0.2.6/yajl_common.h
  49. +123 −0 Frameworks/libYAJLIPhone-0.2.6/yajl_gen.h
  50. +179 −0 Frameworks/libYAJLIPhone-0.2.6/yajl_parse.h
  51. +30 −0 JSONPerfTest-Info.plist
  52. +1,438 −0 JSONPerfTest.xcodeproj/gabe.mode1v3
  53. +814 −0 JSONPerfTest.xcodeproj/gabe.pbxuser
  54. +446 −0 JSONPerfTest.xcodeproj/project.pbxproj
  55. +8 −0 JSONPerfTest_Prefix.pch
  56. +191 −0 MainWindow.xib
  57. +17 −0 main.m
@@ -0,0 +1,18 @@
+//
+// JSONPerfTestAppDelegate.h
+// JSONPerfTest
+//
+// Created by Gabriel Handford on 10/8/09.
+// Copyright 2009. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface JSONPerfTestAppDelegate : NSObject <UIApplicationDelegate> {
+ UIWindow *window;
+}
+
+@property (nonatomic, retain) IBOutlet UIWindow *window;
+
+@end
+
@@ -0,0 +1,34 @@
+//
+// JSONPerfTestAppDelegate.m
+// JSONPerfTest
+//
+// Created by Gabriel Handford on 10/8/09.
+// Copyright 2009. All rights reserved.
+//
+
+#import "JSONPerfTestAppDelegate.h"
+
+#import "JSONTest.h"
+
+@implementation JSONPerfTestAppDelegate
+
+@synthesize window;
+
+- (void)applicationDidFinishLaunching:(UIApplication *)application {
+ JSONTest *test = [[JSONTest alloc] init];
+
+ NSInteger count = 100;
+
+ [test runWithResourceName:@"twitter_public.json" count:count];
+ [test runWithResourceName:@"lastfm.json" count:count];
+ [test runWithResourceName:@"delicious_popular.json" count:count];
+ [test runWithResourceName:@"yelp.json" count:count];
+
+}
+
+- (void)dealloc {
+ [window release];
+ [super dealloc];
+}
+
+@end
@@ -0,0 +1,43 @@
+//
+// JSONTest.h
+// JSONPerfTest
+//
+// Created by Gabriel Handford on 10/8/09.
+// Copyright 2009. All rights reserved.
+//
+
+// To use microseconds timer with Carbon framework
+/*!
+#import <Carbon/Carbon.h>
+ UInt64 M0, M1;
+ Microseconds((UnsignedWide *)&M0);
+ ...
+ Microseconds((UnsignedWide *)&M1);
+ NSLog(@"Microseconds: %g\n", ((double)(M1 - M0) / (double)theCount) / 1000000.0); \
+*/
+
+
+#define RunWithCount(count, description, expr) \
+do { \
+CFAbsoluteTime start = CFAbsoluteTimeGetCurrent(); \
+for(NSInteger i = 0; i < count; i++) { \
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; \
+ id value = (expr); value; \
+ [pool release]; \
+} \
+\
+CFTimeInterval took = CFAbsoluteTimeGetCurrent() - start; \
+NSLog(@"%@ %0.3f", description, took); \
+\
+} while (0)
+
+
+@interface JSONTest : NSObject
+
+- (NSData *)loadDataFromResource:(NSString *)resource;
+
+- (NSString *)loadStringDataFromResource:(NSString *)resource;
+
+- (void)runWithResourceName:(NSString *)resourceName count:(NSInteger)count;
+
+@end
@@ -0,0 +1,49 @@
+//
+// JSONTest.m
+// JSONPerfTest
+//
+// Created by Gabriel Handford on 10/8/09.
+// Copyright 2009. All rights reserved.
+//
+
+#import "JSONTest.h"
+
+#import "NSObject+YAJL.h"
+#import "NSString+SBJSON.h"
+#import "CJSONDeserializer.h"
+
+@implementation JSONTest
+
+- (NSData *)loadDataFromResource:(NSString *)resource {
+ NSParameterAssert(resource);
+ NSString *resourcePath = [[NSBundle mainBundle] pathForResource:[resource stringByDeletingPathExtension] ofType:[resource pathExtension]];
+ if (!resourcePath) [NSException raise:NSInvalidArgumentException format:@"Resource not found: %@", resource];
+ NSError *error = nil;
+ NSData *data = [NSData dataWithContentsOfFile:resourcePath options:0 error:&error];
+ if (error) [NSException raise:NSInvalidArgumentException format:@"Error loading resource at path (%@): %@", resourcePath, error];
+ return data;
+}
+
+- (NSString *)loadStringDataFromResource:(NSString *)resource {
+ return [[[NSString alloc] initWithData:[self loadDataFromResource:resource] encoding:NSUTF8StringEncoding] autorelease];
+}
+
+- (void)runWithResourceName:(NSString *)resourceName count:(NSInteger)count {
+
+ NSString *JSONString = [[self loadStringDataFromResource:resourceName] retain];
+ RunWithCount(count, ([NSString stringWithFormat:@"SBJSON-%@", resourceName]), { [JSONString JSONValue]; });
+ [JSONString release];
+
+ NSData *JSONData = [[self loadDataFromResource:resourceName] retain];
+ RunWithCount(count, ([NSString stringWithFormat:@"YAJL-%@", resourceName]), { [JSONData yajl_JSON]; });
+ [JSONData release];
+
+ // Touch JSON
+ NSData *JSONData2 = [[self loadDataFromResource:resourceName] retain];
+ NSError *error = nil;
+ RunWithCount(count, ([NSString stringWithFormat:@"TouchJSON-%@", resourceName]), { [[CJSONDeserializer deserializer] deserialize:JSONData2 error:&error]; });
+ NSAssert1(error == nil, @"Errored: %@", error);
+ [JSONData2 release];
+}
+
+@end

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,50 @@
+/*
+ Copyright (C) 2009 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.
+ */
+
+/**
+ @mainpage A strict JSON parser and generator for Objective-C
+
+ JSON (JavaScript Object Notation) is a lightweight data-interchange
+ format. This framework provides two apis for parsing and generating
+ JSON. One standard object-based and a higher level api consisting of
+ categories added to existing Objective-C classes.
+
+ Learn more on the http://code.google.com/p/json-framework project site.
+
+ This framework does its best to be as strict as possible, both in what it
+ accepts and what it generates. 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. This is considered a feature.
+
+*/
+
+#import "SBJSON.h"
+#import "NSObject+SBJSON.h"
+#import "NSString+SBJSON.h"
+
@@ -0,0 +1,68 @@
+/*
+ Copyright (C) 2009 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>
+
+
+/**
+ @brief Adds JSON generation to Foundation classes
+
+ This is a category on NSObject that adds methods for returning JSON representations
+ of standard objects to the objects themselves. This means you can call the
+ -JSONRepresentation method on an NSArray object and it'll do what you want.
+ */
+@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
+
+ @deprecated Given we bill ourselves as a "strict" JSON library, this method should be removed.
+ */
+- (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
+
@@ -0,0 +1,53 @@
+/*
+ Copyright (C) 2009 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 "SBJsonWriter.h"
+
+@implementation NSObject (NSObject_SBJSON)
+
+- (NSString *)JSONFragment {
+ SBJsonWriter *jsonWriter = [SBJsonWriter new];
+ NSString *json = [jsonWriter stringWithFragment:self];
+ if (!json)
+ NSLog(@"-JSONFragment failed. Error trace is: %@", [jsonWriter errorTrace]);
+ [jsonWriter release];
+ return json;
+}
+
+- (NSString *)JSONRepresentation {
+ SBJsonWriter *jsonWriter = [SBJsonWriter new];
+ NSString *json = [jsonWriter stringWithObject:self];
+ if (!json)
+ NSLog(@"-JSONRepresentation failed. Error trace is: %@", [jsonWriter errorTrace]);
+ [jsonWriter release];
+ return json;
+}
+
+@end
@@ -0,0 +1,58 @@
+/*
+ Copyright (C) 2009 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>
+
+/**
+ @brief Adds JSON parsing methods to NSString
+
+This is a category on NSString that adds methods for parsing the target string.
+*/
+@interface NSString (NSString_SBJSON)
+
+
+/**
+ @brief Returns the object represented in the receiver, or nil on error.
+
+ Returns a a scalar object represented by the string's JSON fragment representation.
+
+ @deprecated Given we bill ourselves as a "strict" JSON library, this method should be removed.
+ */
+- (id)JSONFragmentValue;
+
+/**
+ @brief Returns the NSDictionary or NSArray represented by the current string's JSON representation.
+
+ Returns the dictionary or array represented in the receiver, or nil on error.
+
+ Returns the NSDictionary or NSArray represented by the current string's JSON representation.
+ */
+- (id)JSONValue;
+
+@end
Oops, something went wrong.

0 comments on commit cb4de69

Please sign in to comment.