Debian Codegraph @

XCode/NSArray+Additions.m

raw
1 /*
2 Copyright (C) 2018, 2019, 2020, 2021 Free Software Foundation, Inc.
3
4 Written by: Gregory John Casamento <[email protected]>
5 Date: 2022
6
7 This file is part of the GNUstep XCode Library
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free
21 Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110 USA.
23 */
24
25 #import "PBXBuildFile.h"
26 #import "NSArray+Additions.h"
27 #import "NSString+PBXAdditions.h"
28
29 @implementation NSArray (Additions)
30
31 - (NSString *) implodeArrayWithSeparator: (NSString *)separator
32 {
33 NSString *result = @"";
34 NSEnumerator *en = [self objectEnumerator];
35 id object = nil;
36 while((object = [en nextObject]) != nil)
37 {
38 NSString *obj = [separator stringByAppendingString: object];
39 result = [result stringByAppendingString: obj];
40 }
41 return result;
42 }
43
44 - (NSArray *) arrayByRemovingDuplicateEntries
45 {
46 NSArray *result = [NSArray array];
47 NSEnumerator *en = [self objectEnumerator];
48 id o = nil;
49
50 while ((o = [en nextObject]) != nil)
51 {
52 if ([result containsObject: o] == NO)
53 {
54 result = [result arrayByAddingObject: o];
55 }
56 }
57
58 return result;
59 }
60
61 - (NSString *) removeDuplicatesAndImplodeWithSeparator: (NSString *)separator
62 {
63 NSArray *result = [self arrayByRemovingDuplicateEntries];
64 return [result implodeArrayWithSeparator: separator];
65 }
66
67 - (NSArray *) arrayByAddingQuotationMarksToEntries
68 {
69 NSEnumerator *en = [self objectEnumerator];
70 NSString *obj = nil;
71 NSMutableArray *result = [NSMutableArray arrayWithCapacity: [self count]];
72
73 while ((obj = [en nextObject]) != nil)
74 {
75 NSString *s = [obj stringByAddingQuotationMarks];
76 [result addObject: s];
77 }
78
79 return [NSArray arrayWithArray: result];
80 }
81
82
83 - (NSString *) arrayToLinkList
84 {
85 NSString *result = @"";
86 NSEnumerator *en = [self objectEnumerator];
87 NSString *aname = nil;
88
89 while((aname = [en nextObject]) != nil)
90 {
91 if ([aname isEqualToString: [self firstObject]] == YES)
92 {
93 result = [result stringByAppendingString: [NSString stringWithFormat: @"%@ ", aname]];
94 }
95 else
96 {
97 result = [result stringByAppendingString: [NSString stringWithFormat: @"\t%@ ", aname]];
98 }
99
100 if ([aname isEqualToString: [self lastObject]] == NO)
101 {
102 result = [result stringByAppendingString: @"\\\n"];
103 }
104 }
105
106 return result;
107 }
108
109 - (NSString *) arrayToIncludeList
110 {
111 NSString *result = @"-I. \\\n";
112 NSEnumerator *en = [self objectEnumerator];
113 NSString *aname = nil;
114
115 while((aname = [en nextObject]) != nil)
116 {
117 result = [result stringByAppendingString: [NSString stringWithFormat: @"\t-I./%@ ", aname]];
118 if ([aname isEqualToString: [self lastObject]] == NO)
119 {
120 result = [result stringByAppendingString: @"\\\n"];
121 }
122 }
123
124 return result;
125 }
126
127 - (NSString *) arrayToList
128 {
129 NSString *result = @"";
130 NSEnumerator *en = [self objectEnumerator];
131 id o = nil;
132
133 while((o = [en nextObject]) != nil)
134 {
135 NSString *aname = nil;
136 if ([o isKindOfClass: [NSString class]])
137 {
138 aname = o;
139 }
140 else if ([o isKindOfClass: [PBXBuildFile class]])
141 {
142 PBXBuildFile *f = o;
143 PBXFileReference *r = [f fileRef];
144 aname = [r path];
145 }
146
147 if (aname != nil)
148 {
149 if ([aname isEqualToString: [self firstObject]] == YES)
150 {
151 result = [result stringByAppendingString: [NSString stringWithFormat: @"%@ ", aname]];
152 }
153 else
154 {
155 result = [result stringByAppendingString: [NSString stringWithFormat: @"\t%@ ", aname]];
156 }
157
158 if ([aname isEqualToString: [self lastObject]] == NO)
159 {
160 result = [result stringByAppendingString: @"\\\n"];
161 }
162 }
163 }
164
165 return result;
166 }
167
168 @end
169
170 @implementation NSMutableArray (Additional)
171
172 - (void) prependObjectsFromArray: (NSArray *)array
173 {
174 NSEnumerator *en = [array objectEnumerator];
175 id o = nil;
176
177 while ((o = [en nextObject]) != nil)
178 {
179 [self insertObject: o atIndex: 0];
180 }
181 }
182
183 @end