forked from gavinkwoe/todparsekit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPKDelimitedString.m
58 lines (45 loc) · 1.3 KB
/
PKDelimitedString.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
//
// PKDelimitedString.m
// ParseKit
//
// Created by Todd Ditchendorf on 5/21/09.
// Copyright 2009 Todd Ditchendorf. All rights reserved.
//
#import <ParseKit/PKDelimitedString.h>
#import <ParseKit/PKToken.h>
@interface PKDelimitedString ()
@property (nonatomic, retain) NSString *startMarker;
@property (nonatomic, retain) NSString *endMarker;
@end
@implementation PKDelimitedString
+ (id)delimitedString {
return [self delimitedStringWithStartMarker:nil];
}
+ (id)delimitedStringWithStartMarker:(NSString *)start {
return [self delimitedStringWithStartMarker:start endMarker:nil];
}
+ (id)delimitedStringWithStartMarker:(NSString *)start endMarker:(NSString *)end {
PKDelimitedString *ds = [[[self alloc] initWithString:nil] autorelease];
ds.startMarker = start;
ds.endMarker = end;
return ds;
}
- (void)dealloc {
self.startMarker = nil;
self.endMarker = nil;
[super dealloc];
}
- (BOOL)qualifies:(id)obj {
PKToken *tok = (PKToken *)obj;
BOOL result = tok.isDelimitedString;
if (result && [startMarker length]) {
result = [tok.stringValue hasPrefix:startMarker];
if (result && [endMarker length]) {
result = [tok.stringValue hasSuffix:endMarker];
}
}
return result;
}
@synthesize startMarker;
@synthesize endMarker;
@end