Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code blocks support #82

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CHCSVParser.podspec
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
Pod::Spec.new do |spec|
spec.name = "CHCSVParser"
spec.version = "2.1.0"
spec.version = "2.1.1"
spec.summary = "A proper CSV parser for Objective-C"
spec.description = <<-DESC
A robust class for reading and writing delimited files in Cocoa.
DESC
spec.homepage = "https://github.com/davedelong/CHCSVParser"
spec.homepage = "https://github.com/grigaci/CHCSVParser"
spec.license = { :type => 'MIT', :file => 'LICENSE.txt' }
spec.author = "Dave DeLong"
spec.social_media_url = "http://twitter.com/davedelong"
spec.ios.deployment_target = "6.0"
spec.osx.deployment_target = "10.7"
spec.source = { :git => "https://github.com/davedelong/CHCSVParser.git", :tag => "2.1.0" }
spec.source_files = "CHCSVParser/CHCSVParser/CHCSVParser.{h,m}"
spec.source = { :git => "https://github.com/grigaci/CHCSVParser.git", :tag => "2.1.1" }
spec.source_files = "CHCSVParser/CHCSVParser/CHCSVParser.{h,m}","CHCSVParser/CHCSVParser/CHCSVParserBlocks.{h,m}"
spec.requires_arc = true
end
12 changes: 12 additions & 0 deletions CHCSVParser.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
432CA0F61AE6998500EF86FC /* CHCSVParserBlocks.m in Sources */ = {isa = PBXBuildFile; fileRef = 432CA0F51AE6998500EF86FC /* CHCSVParserBlocks.m */; };
432CA0F81AE69E6100EF86FC /* CHCSVParserBlocksTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 432CA0F71AE69E6100EF86FC /* CHCSVParserBlocksTestCase.m */; };
432CA0F91AE6B2C300EF86FC /* CHCSVParserBlocks.m in Sources */ = {isa = PBXBuildFile; fileRef = 432CA0F51AE6998500EF86FC /* CHCSVParserBlocks.m */; };
550ED4281973491500E7D173 /* Issue64.csv in Resources */ = {isa = PBXBuildFile; fileRef = 550ED4271973491500E7D173 /* Issue64.csv */; };
5515D4461AAB72FF00DC1D5B /* Issue79.csv in Resources */ = {isa = PBXBuildFile; fileRef = 5515D4451AAB72FF00DC1D5B /* Issue79.csv */; };
557FCEB61203F938009FCDBA /* CoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 557FCEB51203F938009FCDBA /* CoreServices.framework */; };
Expand All @@ -22,6 +25,9 @@
/* Begin PBXFileReference section */
08FB7796FE84155DC02AAC07 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
08FB779EFE84155DC02AAC07 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
432CA0F41AE6998500EF86FC /* CHCSVParserBlocks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CHCSVParserBlocks.h; sourceTree = "<group>"; };
432CA0F51AE6998500EF86FC /* CHCSVParserBlocks.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CHCSVParserBlocks.m; sourceTree = "<group>"; };
432CA0F71AE69E6100EF86FC /* CHCSVParserBlocksTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CHCSVParserBlocksTestCase.m; sourceTree = "<group>"; };
550ED4271973491500E7D173 /* Issue64.csv */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Issue64.csv; sourceTree = "<group>"; };
5515D4451AAB72FF00DC1D5B /* Issue79.csv */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Issue79.csv; sourceTree = "<group>"; };
5560A19E173743A300DDD1D3 /* UnitTestContent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UnitTestContent.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -103,6 +109,8 @@
children = (
55B9931F160E376100D6548A /* CHCSVParser.h */,
55B99320160E376100D6548A /* CHCSVParser.m */,
432CA0F41AE6998500EF86FC /* CHCSVParserBlocks.h */,
432CA0F51AE6998500EF86FC /* CHCSVParserBlocks.m */,
);
path = CHCSVParser;
sourceTree = "<group>";
Expand All @@ -114,6 +122,7 @@
5560A19E173743A300DDD1D3 /* UnitTestContent.h */,
557FD05A1204A72B009FCDBA /* UnitTests.h */,
557FD05B1204A72B009FCDBA /* UnitTests.m */,
432CA0F71AE69E6100EF86FC /* CHCSVParserBlocksTestCase.m */,
550ED4271973491500E7D173 /* Issue64.csv */,
55C61C60199C0B4600770AA2 /* Issue65.csv */,
5515D4451AAB72FF00DC1D5B /* Issue79.csv */,
Expand Down Expand Up @@ -221,7 +230,9 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
432CA0F91AE6B2C300EF86FC /* CHCSVParserBlocks.m in Sources */,
557FD05D1204A731009FCDBA /* UnitTests.m in Sources */,
432CA0F81AE69E6100EF86FC /* CHCSVParserBlocksTestCase.m in Sources */,
55F79EE01682D6B60095E9D5 /* CHCSVParser.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -230,6 +241,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
432CA0F61AE6998500EF86FC /* CHCSVParserBlocks.m in Sources */,
8DD76F9A0486AA7600D96B5E /* main.m in Sources */,
55B99321160E376100D6548A /* CHCSVParser.m in Sources */,
);
Expand Down
84 changes: 84 additions & 0 deletions CHCSVParser/CHCSVParser/CHCSVParserBlocks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//
// CHCSVParserBlocks.h
// CHCSVParser
/**
Copyright (c) 2014 Dave DeLong

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
**/

#import "CHCSVParser.h"

/**
* CSV parser with code blocks.
* Do not set the delegate for this class. Instead use the provied callbacks.
*/
@interface CHCSVParserBlocks : CHCSVParser<CHCSVParserDelegate>

/**
* Indicates that the parser has started parsing the stream
*/
@property (nonatomic, copy) void(^didBeginDocumentCallback)();

/**
* Indicates that the parser has successfully finished parsing the stream
*
* This callback is not invoked if any error is encountered
*/
@property (nonatomic, copy) void(^didEndDocumentCallback)();

/**
* Indicates the parser has started parsing a line
*
* @param recordNumber The 1-based number of the record
*/
@property (nonatomic, copy) void(^didBeginLineCallback)(NSUInteger recordNumber);

/**
* Indicates the parser has finished parsing a line
*
* @param recordNumber The 1-based number of the record
*/
@property (nonatomic, copy) void(^didEndLineCallback)(NSUInteger recordNumber);

/**
* Indicates the parser has parsed a field on the current line
*
* @param field The parsed string. If configured to do so, this string may be sanitized and trimmed
* @param fieldIndex The 0-based index of the field within the current record
*/
@property (nonatomic, copy) void(^didReadFieldCallback)(NSString *field, NSInteger fieldIndex);

/**
* Indicates the parser has encountered a comment
*
* This method is only invoked if @c CHCSVParser.recognizesComments is @c YES
*
* @param comment The parsed comment
*/
@property (nonatomic, copy) void(^didReadCommentCallback)(NSString *comment);

/**
* Indicates the parser encounter an error while parsing
*
* @param error The @c NSError instance
*/
@property (nonatomic, copy) void(^didFailWithErrorCallback)(NSError *error);

@end
84 changes: 84 additions & 0 deletions CHCSVParser/CHCSVParser/CHCSVParserBlocks.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//
// CHCSVParserBlocks.m
// CHCSVParser
/**
Copyright (c) 2014 Dave DeLong

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
**/

#import "CHCSVParserBlocks.h"

@implementation CHCSVParserBlocks

#pragma mark - CHCSVParser methods

- (instancetype)initWithInputStream:(NSInputStream *)stream usedEncoding:(NSStringEncoding *)encoding delimiter:(unichar)delimiter {
self = [super initWithInputStream:stream usedEncoding:encoding delimiter:delimiter];
if (self) {
self.delegate = self;
}
return self;
}

#pragma mark - CHCSVParserDelegate methods

- (void)parserDidBeginDocument:(CHCSVParser *)parser {
if (self.didBeginDocumentCallback) {
self.didBeginDocumentCallback();
}
}

- (void)parserDidEndDocument:(CHCSVParser *)parser {
if (self.didEndDocumentCallback) {
self.didEndDocumentCallback();
}
}

- (void)parser:(CHCSVParser *)parser didBeginLine:(NSUInteger)recordNumber {
if (self.didBeginLineCallback) {
self.didBeginLineCallback(recordNumber);
}
}

- (void)parser:(CHCSVParser *)parser didEndLine:(NSUInteger)recordNumber {
if (self.didEndLineCallback) {
self.didEndLineCallback(recordNumber);
}
}

- (void)parser:(CHCSVParser *)parser didReadField:(NSString *)field atIndex:(NSInteger)fieldIndex {
if (self.didReadFieldCallback) {
self.didReadFieldCallback(field, fieldIndex);
}
}

- (void)parser:(CHCSVParser *)parser didReadComment:(NSString *)comment {
if (self.didReadCommentCallback) {
self.didReadCommentCallback(comment);
}
}

- (void)parser:(CHCSVParser *)parser didFailWithError:(NSError *)error {
if (self.didFailWithErrorCallback) {
self.didFailWithErrorCallback(error);
}
}

@end
1 change: 1 addition & 0 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#CHCSVParser

`CHCSVParser` is an Objective-C parser for CSV files.
Instead of using the delegate methods, now you can use code blocks.

##Supported Platforms

Expand Down
Loading