-
Notifications
You must be signed in to change notification settings - Fork 0
/
PNPortInfo.m
118 lines (96 loc) · 2.36 KB
/
PNPortInfo.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
/**
* @file PNPortInfo.h
*
* @brief implement file for class PNPortInfo
*
* @author eddyxu@gmail.com
*
* $Id$
*/
#import "PNPortInfo.h"
@implementation PNPortInfo
-(id)initWithTitle:(NSString*)aTitle oldVersion:(NSString*)aOldVersion
newVersion:(NSString *)aNewVersion
{
[super init];
title = aTitle;
oldVersion = aOldVersion;
newVersion = aNewVersion;
return self;
}
-(id)initWithString:(NSString*)aLine
{
[super init];
//NSArray *arr = [aLine componentsSeparatedByString:@"\n"];
NSRange portNameRange = [aLine rangeOfCharacterFromSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSRange titleRange = {0, portNameRange.location};
@try {
title = [aLine substringWithRange:titleRange];
[title retain];
}
@catch (NSException * e) {
title = nil;
return self;
}
@finally {
}
NSLog(@"Title: [%@]", title);
NSString *versionString = [aLine substringFromIndex:portNameRange.location];
NSRange oldVersionStart = [versionString rangeOfCharacterFromSet:[NSCharacterSet alphanumericCharacterSet]];
NSRange oldVersionEnd = [versionString rangeOfString:@" < "];
NSRange oldVersionRange = {oldVersionStart.location, oldVersionEnd.location - oldVersionStart.location};
@try{
oldVersion = [versionString substringWithRange:oldVersionRange];
NSLog(@"[%@]", oldVersion);
[oldVersion retain];
}@catch(NSException *e){
oldVersion = nil;
return self;
}
NSString * newVersionString = [versionString substringFromIndex: oldVersionEnd.location + oldVersionEnd.length];
newVersion = [newVersionString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSLog(@"[%@]", newVersion);
[newVersion retain];
return self;
}
- (void) dealloc {
[title release];
[oldVersion release];
[newVersion release];
[super dealloc];
}
-(NSString*) title
{
return title;
}
- (void) setTitle:(NSString*) aTitle
{
if(title != aTitle)
[title release];
title = aTitle;
}
-(NSString*) oldVersion
{
return oldVersion;
}
- (void) setOldVersion:(NSString*) aOldVersion
{
if(oldVersion != aOldVersion)
[oldVersion release];
oldVersion = aOldVersion;
}
-(NSString*) newVersion
{
return newVersion;
}
- (void) setNewVersion:(NSString*) aNewVersion
{
if(newVersion != aNewVersion)
[newVersion release];
newVersion = aNewVersion;
}
- (BOOL) isAvailable
{
return title != nil && newVersion != nil && oldVersion != nil;
}
@end