Permalink
Browse files

Many changes to allow multiple header rows. Not finished at all. Plus…

… newer version of CSVDocument.
  • Loading branch information...
1 parent b1bd943 commit b4b2e203ef82215c63ddd1949c044bec043539f8 svnuser committed Oct 9, 2009
View
@@ -6,12 +6,17 @@
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
+#ifdef IPHONE
+#import <Foundation/Foundation.h>
+#import <UIKit/UIKit.h>
+#else
#import <Cocoa/Cocoa.h>
+#endif
@interface CSVColumn : NSObject {
- NSString *name;
- NSString *key;
+ NSString *name; // the name to display
+ NSString *key; // a unique key
BOOL active;
}
View
@@ -41,7 +41,7 @@ - (NSString *) name
}
- (void) setName:(NSString *)newName
{
- if(newName != name) {
+ if (newName != name) {
[self willChangeValueForKey:@"name"];
[name release];
name = [newName retain];
@@ -51,7 +51,7 @@ - (void) setName:(NSString *)newName
- (BOOL) hasName
{
- return (nil != name);
+ return (nil != name && ![@"" isEqualToString:name]);
}
#pragma mark -
@@ -60,7 +60,7 @@ - (BOOL) hasName
#pragma mark Utilities
- (NSString *) description
{
- return [NSString stringWithFormat:@"%@ <0x%X>; %@ -> %@, active: %i", [self className], self, key, name, active];
+ return [NSString stringWithFormat:@"%@ <0x%X>; %@ -> %@, active: %i", NSStringFromClass([self class]), self, key, name, active];
}
View
@@ -7,51 +7,64 @@
// http://www.apache.org/licenses/LICENSE-2.0.html
//
+#ifdef IPHONE
+#import <Foundation/Foundation.h>
+#import <UIKit/UIKit.h>
+#else
#import <Cocoa/Cocoa.h>
+@class CSVRowController;
+#endif
+
#import "CSVDocumentDelegate.h"
@class CSVRow;
@class CSVColumn;
-@class CSVRowController;
@class PPStringFormat;
@interface CSVDocument : NSObject {
id <CSVDocumentDelegate> delegate;
NSString *separator;
- CSVRow *headerRow; // must never be nil
+ NSMutableArray *headerRows; // array full of CSVRow header rows
NSMutableArray *rows;
NSNumber *numRows;
+
+#ifndef IPHONE
CSVRowController *rowController;
+#endif
NSArray *columns; // needs to be an array to preserve column order
NSDictionary *columnDict; // readonly to allow fast access to columns by key
BOOL parseSuccessful;
BOOL autoDetectSeparator; // if YES will check for other separators (";" and TAB) than the comma
- BOOL firstRowIsHeaderRow; // tells us whether the first row contains data or only header info. bound to a checkbox
+ NSUInteger numHeaderRows; // first x rows contain header data
BOOL mustAbortImport;
BOOL didAbortImport;
+ BOOL reportEveryRowParsed; // if YES informs the delegate after each row that was parsed
}
@property (nonatomic, assign) id delegate;
@property (nonatomic, retain) NSString *separator;
-@property (nonatomic, copy) CSVRow *headerRow;
+@property (nonatomic, retain) NSMutableArray *headerRows;
@property (nonatomic, retain) NSMutableArray *rows;
@property (nonatomic, copy) NSNumber *numRows;
+#ifndef IPHONE
@property (nonatomic, retain) CSVRowController *rowController;
+#endif
@property (nonatomic, retain) NSArray *columns;
@property (nonatomic, readonly) NSDictionary *columnDict;
@property (nonatomic, assign) BOOL parseSuccessful;
@property (nonatomic, assign) BOOL autoDetectSeparator;
-@property (nonatomic, assign) BOOL firstRowIsHeaderRow;
+@property (nonatomic, assign) NSUInteger numHeaderRows;
@property (assign) BOOL mustAbortImport;
@property (nonatomic, assign) BOOL didAbortImport;
+@property (nonatomic, assign) BOOL reportEveryRowParsed;
// Main methods
@@ -60,17 +73,20 @@
- (NSUInteger) numRowsToExpect:(NSString *)string;
- (BOOL) parseCSVString:(NSString *)string error:(NSError **)error;
- (BOOL) parseCSVString:(NSString *)string maxRows:(NSUInteger)maxRows error:(NSError **)error;
+#ifdef CSV_STRING_EXPORTING
- (NSString *) stringInFormat:(PPStringFormat *)format withColumns:(NSArray *)columnArray forRowIndexes:(NSIndexSet *)rowIndexes writeHeader:(BOOL)headerFlag;
+#endif
// column handling
-- (void) changeHeaderRow:(CSVRow *)newHeaderRow;
-- (void) setNewColumns:(NSArray *)newColumns;
+- (void) addColumn:(CSVColumn *) newColumn;
- (BOOL) isFirstColumnKey:(NSString *)columnKey;
+- (void) setHeaderRow:(CSVRow *)newHeaderRow;
- (BOOL) hasColumnKey:(NSString *)columnKey;
- (void) setColumnOrderByKeys:(NSArray *)newOrderKeys;
-- (NSString *) nameForColumn:(NSString *)columnKey;
-- (NSString *) nameForColumn:(NSString *)columnKey quoted:(BOOL)quoted;
+- (CSVColumn *) columnWithKey:(NSString *)columnKey;
+- (NSString *) nameForColumnKey:(NSString *)columnKey;
+- (NSString *) nameForColumnKey:(NSString *)columnKey quoted:(BOOL)quoted;
- (void) setHeaderName:(NSString *)newName forColumnKey:(NSString *)columnKey;
- (void) setHeaderActive:(BOOL)active forColumnKey:(NSString *)columnKey;
Oops, something went wrong.

0 comments on commit b4b2e20

Please sign in to comment.