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

Setting options for parser requires creating a custom delegate #26

Closed
johnthuss opened this issue Feb 26, 2013 · 2 comments
Closed

Setting options for parser requires creating a custom delegate #26

johnthuss opened this issue Feb 26, 2013 · 2 comments

Comments

@johnthuss
Copy link

It's very cumbersome to use the parser when you want to modify the options (in this case, set sanitizesFields). Instead of just calling [@"a,b,c" CSVComponents] you have to create an entire delegate class from scratch and pass it to the parser. You should provide a default delegate, like CHCSVAccumulatorDelegate.

Another sugary option for the string category would be to allow options to be passed in:

@implementation NSString (CHCSVAdditions)

- (NSArray *)CSVComponentsWithOptions:(NSDictionary *)options {
    _CHCSVAggregator *aggregator = [[_CHCSVAggregator alloc] init];
    CHCSVParser *parser = [[CHCSVParser alloc] initWithCSVString:self];
    [parser setDelegate:aggregator];
    for (NSString *key in [options keys])
         [parse takeValue:options[key] forKey:key];
    [parser parse];
    CHCSV_RELEASE(parser);

    NSArray *final = CHCSV_AUTORELEASE(CHCSV_RETAIN([aggregator lines]));
    CHCSV_RELEASE(aggregator);

    return final;
}

@end
@davedelong
Copy link
Owner

I'll take a look at this. Thanks for the suggestion!

davedelong added a commit that referenced this issue Mar 6, 2013
@davedelong
Copy link
Owner

I went with a bitfield instead of an NSDictionary. It seemed more idiomatic that way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants