-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBCDataRowsValidator.h
More file actions
60 lines (42 loc) · 1.69 KB
/
BCDataRowsValidator.h
File metadata and controls
60 lines (42 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//
// BCDataRowsValidator.h
// Xynk
//
// Created by Tom Houpt on 21/9/23.
//
#import <Foundation/Foundation.h>
#define kDataRowsMinimum 2 // header and 1 subject
#define kDataColumnsMinimum 3 // subject, group, and one measure column
typedef NSUInteger DataValidationError;
typedef NS_OPTIONS(NSUInteger,DataValidationErrorFlags) {
kDataValidationErrorNoError = 0,
kDataValidationErrorNonEqualRowLengths = 1 << 0,
kDataValidationErrorInsufficientColumns = 1 << 1,
kDataValidationErrorInsufficientRows = 1 << 2,
kDataValidationErrorRowsLongerThanHeader = 1 << 3,
kDataValidationErrorRowsShorterThanHeader = 1 << 4,
kDataValidationErrorEmptyHeaderCell = 1 << 5,
kDataValidationErrorNoDataOnPasteboard = 1 << 6,
kDataValidationErrorProblemSubject = 1 << 7
};
NS_ASSUME_NONNULL_BEGIN
/**
usage: pass in a mutable array of rows, each row containing an array of strings as cells in the row. Rows are validated and trimmed *in place* for subsequent use.
Empty rows and columns, and comment rows starting with "#", are removed
Empty cells are replaced with @"--"
BCDataRowsValidator * validator = [[BCDataRowsValidator alloc] initWithRows:rows];
DataValidationError error = [validator validateRows];
NSString *errorMessage = [validator errorString:error];
if (kDataValidationErrorNoError == error) {
// okay to use rows
}
TODO: add some tests to make sure validator works properly
*/
@interface BCDataRowsValidator : NSObject
@property NSMutableArray *rows;
@property NSArray *errorStrings;
-(id)initWithRows:(NSMutableArray *)theRows;
-(DataValidationError)validateRows;
-(NSString *)errorString:(DataValidationError)error;
@end
NS_ASSUME_NONNULL_END