-
Notifications
You must be signed in to change notification settings - Fork 0
/
NSArrayALPMListExtensions.m
121 lines (109 loc) · 3.39 KB
/
NSArrayALPMListExtensions.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
/*
* Copyright (c) 2008 Sebastian Nowicki <sebnow@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#import "NSArrayALPMListExtensions.h"
#import "PMPackagePrivate.h"
#import "PMDatabasePrivate.h"
@implementation NSArray (alpm_list_t)
+ (id) arrayWithPackageList:(alpm_list_t *)aList database:(PMDatabase *)theDatabase
{
NSMutableArray *tmp;
NSArray *array;
tmp = [[NSMutableArray alloc] initWithPackageList:aList database:theDatabase];
array = [NSArray arrayWithArray:tmp];
[tmp release];
return array;
}
+ (id) arrayWithDatabaseList:(alpm_list_t *)aList
{
NSMutableArray *tmp;
NSArray *array;
tmp = [[NSMutableArray alloc] initWithDatabaseList:aList];
array = [NSArray arrayWithArray:tmp];
[tmp release];
return array;
}
+ (id) arrayWithStringList:(alpm_list_t *)aList
{
NSMutableArray *tmp;
NSArray *array;
tmp = [[NSMutableArray alloc] initWithStringList:aList];
array = [NSArray arrayWithArray:tmp];
[tmp release];
return array;
}
- (id) initWithStringList:(alpm_list_t *)aList
{
NSMutableArray *anArray;
anArray = [[NSMutableArray alloc] initWithStringList:aList];
return [self initWithArray:anArray];
}
@end
@implementation NSMutableArray (alpm_list_t)
- (id) initWithPackageList:(alpm_list_t *)aList database:(PMDatabase *)theDatabase
{
self = [self initWithCapacity:alpm_list_count(aList)];
if(self != nil) {
alpm_list_t *node;
PMPackage *package;
node = aList;
while(node != NULL) {
package = [[PMPackage alloc] _initUsingALPMPackage:alpm_list_getdata(node) database:theDatabase];
[self addObject:package];
[package release];
node = alpm_list_next(node);
}
}
return self;
}
- (id) initWithDatabaseList:(alpm_list_t *)aList
{
self = [self initWithCapacity:alpm_list_count(aList)];
if(self != nil) {
alpm_list_t *node;
PMDatabase *database;
node = aList;
while(node != NULL) {
database = [[PMDatabase alloc] _initUsingALPMDatabase:alpm_list_getdata(node)];
[self addObject:database];
[database release];
node = alpm_list_next(node);
}
}
return self;
}
- (id) initWithStringList:(alpm_list_t *)aList
{
self = [self initWithCapacity:alpm_list_count(aList)];
if(self != nil) {
alpm_list_t *node;
NSString *string;
node = aList;
while(node != NULL) {
string = [[NSString alloc] initWithUTF8String:alpm_list_getdata(node)];
[self addObject:string];
[string release];
node = alpm_list_next(node);
}
}
return self;
}
@end