-
Notifications
You must be signed in to change notification settings - Fork 2
/
Address.mm
68 lines (50 loc) · 1.4 KB
/
Address.mm
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
#import "Address.h"
@implementation Address
- (void) dealloc {
[name_ release];
if (address_ != nil)
[address_ release];
[super dealloc];
}
- (NSString *) name {
return name_;
}
- (NSString *) address {
return address_;
}
- (void) setAddress:(NSString *)address {
if (address_ != nil)
[address_ autorelease];
if (address == nil)
address_ = nil;
else
address_ = [address retain];
}
+ (Address *) addressWithString:(NSString *)string {
return [[[Address alloc] initWithString:string] autorelease];
}
+ (NSArray *) _attributeKeys {
return [NSArray arrayWithObjects:@"address", @"name", nil];
}
- (NSArray *) attributeKeys {
return [[self class] _attributeKeys];
}
+ (BOOL) isKeyExcludedFromWebScript:(const char *)name {
return ![[self _attributeKeys] containsObject:[NSString stringWithUTF8String:name]] && [super isKeyExcludedFromWebScript:name];
}
- (Address *) initWithString:(NSString *)string {
if ((self = [super init]) != nil) {
const char *data = [string UTF8String];
size_t size = [string length];
static Pcre address_r("^\"?(.*)\"? <([^>]*)>$");
if (address_r(data, size)) {
name_ = [address_r[1] retain];
address_ = [address_r[2] retain];
} else {
name_ = [string retain];
address_ = nil;
}
} return self;
}
@end
/* }}} */