-
Notifications
You must be signed in to change notification settings - Fork 1
/
BookStackLOCRange.m
170 lines (149 loc) · 6.75 KB
/
BookStackLOCRange.m
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
//
// BookStackLOCRange.m
// DalFind
//
// Created by admin on 2013-11-27.
// Copyright (c) 2013 Esri Canada. All rights reserved.
//
#import "BookStackLOCRange.h"
@implementation BookStackLOCRange
-initWithStartRange:(NSString*)start EndRange:(NSString*)end building:(NSString*)building planid:(NSString*)planid graphic:(AGSGraphic*)g
{
self.one = @"";
self = [super init];
self.graphic = g;
NSArray* startCallNumberArray = [self splitCallNumber:start];
NSArray* endCallNumberArray = [self splitCallNumber:end];
self.one = [startCallNumberArray objectAtIndex:0];
self.two = [startCallNumberArray objectAtIndex:1];
self.three = [startCallNumberArray objectAtIndex:2];
self.four = [startCallNumberArray objectAtIndex:3];
self.oneE = [endCallNumberArray objectAtIndex:0];
self.twoE = [endCallNumberArray objectAtIndex:1];
self.threeE = [endCallNumberArray objectAtIndex:2];
self.fourE = [endCallNumberArray objectAtIndex:3];
self.building = building;
self.planid = planid;
return self;
}
-(BOOL)inLocalRange:(NSString *)test lower:(NSString*)low upper:(NSString*)up mode:(NSString*)mode
{
if ([test isEqualToString:@""]) return YES;
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
NSNumber *numberTest = ([formatter numberFromString:test]);
BOOL lowerTest;
BOOL upperTest;
if (numberTest == nil){
lowerTest = ((NSComparisonResult)[low compare: test] == NSOrderedAscending || (NSComparisonResult)[test compare: low] == NSOrderedSame);
upperTest = ((NSComparisonResult)[up compare: test] == NSOrderedDescending || (NSComparisonResult)[test compare: up] == NSOrderedSame);
}
else{
NSNumber *lowerNumber = ([formatter numberFromString:low]);
NSNumber *upperNumber = ([formatter numberFromString:up]);
lowerTest = [numberTest doubleValue] >= [lowerNumber doubleValue];
upperTest = [numberTest doubleValue] <= [upperNumber doubleValue];;
}
if ([mode isEqualToString:@"both"] || [mode isEqualToString:@"lowerupper"]) return (lowerTest && upperTest);
else if ([mode isEqualToString:@"lower"]) return lowerTest;
else return upperTest;
}
-(NSString*)matchConfirmed:(NSString *)test lower:(NSString*)low upper:(NSString*)up mode:(NSString*)mode;
{
if ([mode isEqualToString:@"both"])
{
NSMutableString *m = [[NSMutableString alloc]init];
if ([test isEqualToString:low]){
[m appendString:@"lower"];
}
if ([test isEqualToString:up]){
[m appendString:@"upper"];
}
if (![m isEqualToString:@""])
{
return m;
}
}
else if ([mode isEqualToString:@"lower"] && ![test isEqualToString:low]){
return @"both";
}
else if ([mode isEqualToString:@"upper"] && ![test isEqualToString:up]){
return @"both";
}
else if ([mode isEqualToString:@"lowerupper"] && ![test isEqualToString:low] && ![test isEqualToString:up]) return @"both";
// if mode is initially set to upper or lower
return mode;
}
-(BOOL)inRange:(NSString*)callNumber
{
NSArray* callNumberArray = [self splitCallNumber:callNumber];
NSString* oneL = [callNumberArray objectAtIndex:0];
NSString* twoL = [callNumberArray objectAtIndex:1];
NSString* threeL = [callNumberArray objectAtIndex:2];
NSString* fourL = [callNumberArray objectAtIndex:3];
NSString *mode = @"both";
if ([self inLocalRange:oneL lower:self.one upper:self.oneE mode:mode]){
if (!(([self.one isEqualToString:@"OVERSIZE"])||([self.one isEqualToString:@"NO_SHEET"])||([self.one isEqualToString:@"nd"])))
{
mode = [self matchConfirmed:oneL lower:self.one upper:self.oneE mode:mode];
if ([self.two isEqualToString:@""] || [mode isEqualToString:@"both"]){
return YES;
}
else if ([self inLocalRange:twoL lower:self.two upper:self.twoE mode:mode]){
mode = [self matchConfirmed:twoL lower:self.two upper:self.twoE mode:mode];
if ([self.three isEqualToString:@""] || [mode isEqualToString:@"both"]){
return YES;
}
else if([self inLocalRange:threeL lower:self.three upper:self.threeE mode:mode]){
mode = [self matchConfirmed:threeL lower:self.two upper:self.threeE mode:mode];
if ([self.four isEqualToString:@""] || [mode isEqualToString:@"both"]){
return YES;
}
else if ([self inLocalRange:fourL lower:self.four upper:self.fourE mode:mode]){
return YES;
}
}
}
}
}
return NO;
}
-(NSArray*)splitCallNumber:(NSString*)callNumber
{
//remove whitespaces
callNumber = [callNumber stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSArray *output = [[NSArray alloc] init];
NSString *exp = @"^([a-z|A-Z]*)(\\d*\\.*\\d*)([a-z|A-Z]*)(\\d*)(\\w*)";
NSError *error;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:exp options:0 error:&error];
if (error) {
NSLog(@"%@", error);
} else {
NSTextCheckingResult* result = [regex firstMatchInString:callNumber options:0 range:NSMakeRange(0, [callNumber length])];
NSString* one = @"";
NSString* two = @"";
NSString* three = @"";
NSString* four = @"";
if (result) {
NSLog(@"%d", [result numberOfRanges]);
for (int i = 0; i < [result numberOfRanges]; i++)
{
if (i == 0 && !NSEqualRanges([result rangeAtIndex:1], NSMakeRange(NSNotFound, 0)))
one = [callNumber substringWithRange:[result rangeAtIndex:1]];
else if (i == 1 && !NSEqualRanges([result rangeAtIndex:2], NSMakeRange(NSNotFound, 0)))
two = [callNumber substringWithRange:[result rangeAtIndex:2]];
else if (i == 2 && !NSEqualRanges([result rangeAtIndex:3], NSMakeRange(NSNotFound, 0)))
three = [callNumber substringWithRange:[result rangeAtIndex:3]];
else if (i == 3 && !NSEqualRanges([result rangeAtIndex:4], NSMakeRange(NSNotFound, 0))){
//if the fourth section isn't an empty string append "."
if (![[callNumber substringWithRange:[result rangeAtIndex:4]] isEqualToString:@""])
{
four = [@"." stringByAppendingString:[callNumber substringWithRange:[result rangeAtIndex:4]] ];
}
}
}
}
output = [[NSArray alloc] initWithObjects:one, two, three, four, nil];
}
return output;
}
@end