Skip to content

Commit

Permalink
Updating iOS project; Adding capacity argument
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel committed Mar 3, 2011
1 parent de2ee78 commit 684811e
Show file tree
Hide file tree
Showing 69 changed files with 218 additions and 99 deletions.
3 changes: 3 additions & 0 deletions Classes/YAJL.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@
To use the framework (for Mac OS X or iOS):
@code
// For Mac OS X
#import <YAJL/YAJL.h>
// For iOS
#import <YAJLiOS/YAJL.h>
@endcode
@section Examples Examples
Expand Down
24 changes: 24 additions & 0 deletions Classes/YAJLDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,19 @@ extern NSInteger YAJLDocumentStackCapacity;
*/
- (id)initWithData:(NSData *)data parserOptions:(YAJLParserOptions)parserOptions error:(NSError **)error;

/*!
Create document from data.
@param data Data to parse
@param parserOptions Parse options
- YAJLParserOptionsNone: No options
- YAJLParserOptionsAllowComments: Javascript style comments will be allowed in the input (both /&asterisk; &asterisk;/ and //)
- YAJLParserOptionsCheckUTF8: Invalid UTF8 strings will cause a parse error
- YAJLParserOptionsStrictPrecision: If YES will force strict precision and return integer overflow error
@param capacity Initial capacity for NSArray and NSDictionary objects (Defaults to 20)
@param error Error to set on failure
*/
- (id)initWithData:(NSData *)data parserOptions:(YAJLParserOptions)parserOptions capacity:(NSInteger)capacity error:(NSError **)error;

/*!
Create empty document with parser options.
@param parserOptions Parse options
Expand All @@ -157,6 +170,17 @@ extern NSInteger YAJLDocumentStackCapacity;
*/
- (id)initWithParserOptions:(YAJLParserOptions)parserOptions;

/*!
Create empty document with parser options.
@param parserOptions Parse options
- YAJLParserOptionsNone: No options
- YAJLParserOptionsAllowComments: Javascript style comments will be allowed in the input (both /&asterisk; &asterisk;/ and //)
- YAJLParserOptionsCheckUTF8: Invalid UTF8 strings will cause a parse error
- YAJLParserOptionsStrictPrecision: If YES will force strict precision and return integer overflow error
@param capacity Initial capacity for NSArray and NSDictionary objects (Defaults to 20)
*/
- (id)initWithParserOptions:(YAJLParserOptions)parserOptions capacity:(NSInteger)capacity;

/*!
Parse data.
@param data Data to parse
Expand Down
10 changes: 9 additions & 1 deletion Classes/YAJLDocument.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ - (id)init {
}

- (id)initWithParserOptions:(YAJLParserOptions)parserOptions {
return [self initWithParserOptions:parserOptions capacity:YAJLDocumentStackCapacity];
}

- (id)initWithParserOptions:(YAJLParserOptions)parserOptions capacity:(NSInteger)capacity {
if ((self = [super init])) {
stack_ = [[NSMutableArray alloc] initWithCapacity:YAJLDocumentStackCapacity];
keyStack_ = [[NSMutableArray alloc] initWithCapacity:YAJLDocumentStackCapacity];
Expand All @@ -57,7 +61,11 @@ - (id)initWithParserOptions:(YAJLParserOptions)parserOptions {
}

- (id)initWithData:(NSData *)data parserOptions:(YAJLParserOptions)parserOptions error:(NSError **)error {
if ((self = [self initWithParserOptions:parserOptions])) {
return [self initWithData:data parserOptions:parserOptions capacity:YAJLDocumentStackCapacity error:error];
}

- (id)initWithData:(NSData *)data parserOptions:(YAJLParserOptions)parserOptions capacity:(NSInteger)capacity error:(NSError **)error {
if ((self = [self initWithParserOptions:parserOptions capacity:capacity])) {
[self parse:data error:error];
}
return self;
Expand Down
75 changes: 55 additions & 20 deletions Example/TestApp/Frameworks/YAJL.framework/Versions/A/Headers/YAJL.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,56 +37,89 @@
@mainpage YAJL
The YAJL framework is an Objective-C wrapper around the http://lloyd.github.com/yajl/ SAX-style JSON parser.
@section Links
Source: http://github.com/gabriel/yajl-objc
View docs online: http://gabriel.github.com/yajl-objc/
YAJL C docs: http://lloyd.github.com/yajl/
@section Usage Usage
To parse JSON from an NSData (or NSString):
To use the framework (for Mac OS X or iOS):
@code
// For Mac OS X
#import <YAJL/YAJL.h>
// For iOS
#import <YAJLiOS/YAJL.h>
@endcode
@section Examples Examples
@subsection Example1 To parse JSON from NSData
@code
NSData *JSONData = [NSData dataWithContentsOfFile:@"example.json"];
NSArray *arrayFromData = [JSONData yajl_JSON];
@endcode
@subsection Example2 To parse JSON from NSString
NSString *JSONString = @"[\"Test\"]";
@code
NSString *JSONString = @"[1, 2, 3]";
NSArray *arrayFromString = [JSONString yajl_JSON];
@endcode
@subsection Example2 To parse JSON from NSString with error and comments
@code
// With options and out error
NSString *JSONString = @"[1, 2, 3] // Allow comments";
NSError *error = nil;
NSArray *arrayFromString = [JSONString yajl_JSONWithOptions:YAJLParserOptionsAllowComments error:&error];
@endcode
To generate JSON from an object:
@subsection Example3 To generate JSON from an object, NSArray, NSDictionary, etc.
@code
NSDictionary *dict = [NSDictionary dictionaryWithObject:@"value" forKey:@"key"];
NSString *JSONString = [dict yajl_JSONString];
@endcode
@subsection Example4 To generate JSON from an object, beautified with custom indent
@code
// Beautified with custon indent string
NSArray *array = [NSArray arrayWithObjects:@"value1", @"value2", nil];
NSString *JSONString = [dict yajl_JSONStringWithOptions:YAJLGenOptionsBeautify indentString:@" "];
@endcode
To use the streaming (or SAX style) parser, use YAJLParser. For higher level (document) streaming, see below.
@subsection Example5 To use the streaming (or SAX style) parser, use YAJLParser
@code
NSData *data = [NSData dataWithContentsOfFile:@"example.json"];
YAJLParser *parser = [[YAJLParser alloc] initWithParserOptions:YAJLParserOptionsAllowComments];
parser.delegate = self;
[parser parse:data];
if (parser.parserError) {
NSLog(@"Error:\n%@", parser.parserError);
}
if (parser.parserError)
NSLog(@"Error:\n%@", parser.parserError);
parser.delegate = nil;
[parser release];
// Include delegate methods from YAJLParserDelegate
- (void)parserDidStartDictionary:(YAJLParser *)parser;
- (void)parserDidEndDictionary:(YAJLParser *)parser;
- (void)parserDidStartDictionary:(YAJLParser *)parser { }
- (void)parserDidEndDictionary:(YAJLParser *)parser { }
- (void)parserDidStartArray:(YAJLParser *)parser;
- (void)parserDidEndArray:(YAJLParser *)parser;
- (void)parserDidStartArray:(YAJLParser *)parser { }
- (void)parserDidEndArray:(YAJLParser *)parser { }
- (void)parser:(YAJLParser *)parser didMapKey:(NSString *)key;
- (void)parser:(YAJLParser *)parser didAdd:(id)value;
- (void)parser:(YAJLParser *)parser didMapKey:(NSString *)key { }
- (void)parser:(YAJLParser *)parser didAdd:(id)value { }
@endcode
@subsection ParserOptions Parser Options
Expand All @@ -97,7 +130,7 @@
- YAJLParserOptionsCheckUTF8: Will verify UTF-8
- YAJLParserOptionsStrictPrecision: Will force strict precision and return integer overflow error, if number is greater than long long.
@subsection StreamingExample Streaming Example (Parser)
@subsection Example6 Parsing as data becomes available
@code
YAJLParser *parser = [[[YAJLParser alloc] init] autorelease];
Expand All @@ -106,15 +139,17 @@
// A chunk of data comes...
YAJLParserStatus status = [parser parse:chunk1];
// 'status' should be YAJLParserStatusInsufficientData, if its not finished
if (parser.parserError) ...;
if (parser.parserError)
NSLog(@"Error:\n%@", parser.parserError);
// Another chunk of data comes...
YAJLParserStatus status = [parser parse:chunk2];
// 'status' should be YAJLParserStatusOK if its finished
if (parser.parserError) ...;
@encode
if (parser.parserError)
NSLog(@"Error:\n%@", parser.parserError);
@endcode
@subsection UsageDocument Usage (Document-style)
@subsection Example7 Document style parsing
To use the document style, use YAJLDocument. Usage should be very similar to NSXMLDocument.
Expand All @@ -127,7 +162,7 @@
[document release];
@endcode
@subsection StreamingExampleDocument Streaming Example (Document)
@subsection Example8 Document style parsing as data becomes available
@code
YAJLDocument *document = [[YAJLDocument alloc] init];
Expand All @@ -149,7 +184,7 @@
- (void)document:(YAJLDocument *)document didSetObject:(id)object forKey:(id)key inDictionary:(NSDictionary *)dict { }
@endcode
@section LoadJSONBundle Load JSON from Bundle
@subsection Example9 Load JSON from Bundle
@code
id JSONValue = [[NSBundle mainBundle] yajl_JSONFromResource:@"kegs.json"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,19 @@ extern NSInteger YAJLDocumentStackCapacity;
*/
- (id)initWithData:(NSData *)data parserOptions:(YAJLParserOptions)parserOptions error:(NSError **)error;

/*!
Create document from data.
@param data Data to parse
@param parserOptions Parse options
- YAJLParserOptionsNone: No options
- YAJLParserOptionsAllowComments: Javascript style comments will be allowed in the input (both /&asterisk; &asterisk;/ and //)
- YAJLParserOptionsCheckUTF8: Invalid UTF8 strings will cause a parse error
- YAJLParserOptionsStrictPrecision: If YES will force strict precision and return integer overflow error
@param capacity Initial capacity for NSArray and NSDictionary objects (Defaults to 20)
@param error Error to set on failure
*/
- (id)initWithData:(NSData *)data parserOptions:(YAJLParserOptions)parserOptions capacity:(NSInteger)capacity error:(NSError **)error;

/*!
Create empty document with parser options.
@param parserOptions Parse options
Expand All @@ -157,6 +170,17 @@ extern NSInteger YAJLDocumentStackCapacity;
*/
- (id)initWithParserOptions:(YAJLParserOptions)parserOptions;

/*!
Create empty document with parser options.
@param parserOptions Parse options
- YAJLParserOptionsNone: No options
- YAJLParserOptionsAllowComments: Javascript style comments will be allowed in the input (both /&asterisk; &asterisk;/ and //)
- YAJLParserOptionsCheckUTF8: Invalid UTF8 strings will cause a parse error
- YAJLParserOptionsStrictPrecision: If YES will force strict precision and return integer overflow error
@param capacity Initial capacity for NSArray and NSDictionary objects (Defaults to 20)
*/
- (id)initWithParserOptions:(YAJLParserOptions)parserOptions capacity:(NSInteger)capacity;

/*!
Parse data.
@param data Data to parse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
<key>CFBundleSignature</key>
<string>GABE</string>
<key>CFBundleVersion</key>
<string>0.2.24</string>
<string>0.2.26</string>
</dict>
</plist>
Binary file modified Example/TestApp/Frameworks/YAJL.framework/Versions/A/YAJL
Binary file not shown.
2 changes: 1 addition & 1 deletion Example/TestAppIOS/Classes/TestAppIOSAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import "TestAppIOSAppDelegate.h"
#import "TestAppIOSViewController.h"

#import <YAJL/YAJL.h>
#import <YAJLiOS/YAJL.h>

@implementation TestAppIOSAppDelegate

Expand Down
Binary file not shown.
1 change: 0 additions & 1 deletion Example/TestAppIOS/Frameworks/YAJL.framework/YAJL

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@
To use the framework (for Mac OS X or iOS):
@code
// For Mac OS X
#import <YAJL/YAJL.h>
// For iOS
#import <YAJLiOS/YAJL.h>
@endcode
@section Examples Examples
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,19 @@ extern NSInteger YAJLDocumentStackCapacity;
*/
- (id)initWithData:(NSData *)data parserOptions:(YAJLParserOptions)parserOptions error:(NSError **)error;

/*!
Create document from data.
@param data Data to parse
@param parserOptions Parse options
- YAJLParserOptionsNone: No options
- YAJLParserOptionsAllowComments: Javascript style comments will be allowed in the input (both /&asterisk; &asterisk;/ and //)
- YAJLParserOptionsCheckUTF8: Invalid UTF8 strings will cause a parse error
- YAJLParserOptionsStrictPrecision: If YES will force strict precision and return integer overflow error
@param capacity Initial capacity for NSArray and NSDictionary objects (Defaults to 20)
@param error Error to set on failure
*/
- (id)initWithData:(NSData *)data parserOptions:(YAJLParserOptions)parserOptions capacity:(NSInteger)capacity error:(NSError **)error;

/*!
Create empty document with parser options.
@param parserOptions Parse options
Expand All @@ -157,6 +170,17 @@ extern NSInteger YAJLDocumentStackCapacity;
*/
- (id)initWithParserOptions:(YAJLParserOptions)parserOptions;

/*!
Create empty document with parser options.
@param parserOptions Parse options
- YAJLParserOptionsNone: No options
- YAJLParserOptionsAllowComments: Javascript style comments will be allowed in the input (both /&asterisk; &asterisk;/ and //)
- YAJLParserOptionsCheckUTF8: Invalid UTF8 strings will cause a parse error
- YAJLParserOptionsStrictPrecision: If YES will force strict precision and return integer overflow error
@param capacity Initial capacity for NSArray and NSDictionary objects (Defaults to 20)
*/
- (id)initWithParserOptions:(YAJLParserOptions)parserOptions capacity:(NSInteger)capacity;

/*!
Parse data.
@param data Data to parse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* Interface to YAJL's JSON generation facilities.
*/

#include <yajl/yajl_common.h>
#include "yajl_common.h"

#ifndef __YAJL_GEN_H__
#define __YAJL_GEN_H__
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* Interface to YAJL's JSON parsing facilities.
*/

#include <yajl/yajl_common.h>
#include "yajl_common.h"

#ifndef __YAJL_PARSE_H__
#define __YAJL_PARSE_H__
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef YAJL_VERSION_H_
#define YAJL_VERSION_H_

#include <yajl/yajl_common.h>
#include "yajl_common.h"

#define YAJL_MAJOR 1
#define YAJL_MINOR 0
Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions Example/TestAppIOS/Frameworks/YAJLiOS.framework/YAJLiOS
Loading

0 comments on commit 684811e

Please sign in to comment.