Modified src/OFArray.h
from [e7a8933e40]
to [0b607ebca5].
︙ | | |
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
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
|
-
+
-
+
+
+
+
+
+
+
+
+
+
|
size_t items;
}
/**
* Creates a new OFArray whose items all have the same size.
*
* \param is The size of each element in the OFArray
* \return A new allocated and initialized OFArray
* \return A new autoreleased OFArray
*/
+ newWithItemSize: (size_t)is;
+ arrayWithItemSize: (size_t)is;
/*
* Creates a new OFArray optimized for big arrays whose items all have the same
* size, which means memory is allocated in pages rather than in bytes.
*
* \param is The size of each element in the OFArray
* \return A new autoreleased OFArray
*/
+ bigArrayWithItemSize: (size_t)is;
/**
* Initializes an already allocated OFArray whose items all have the same size.
*
* \param is The size of each element in the OFArray
* \return An initialized OFArray
*/
|
︙ | | |
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
* Removes a specified amount of the last items from the OFArray.
*
* \param nitems The number of items to remove
*/
- removeNItems: (size_t)nitems;
@end
/**
* The OFBigArray class is nearly the same as the OFArray class, but it
* allocates the memory rather in pages than in bytes.
* This is faster, but needs more memory. It is especially useful if you want
* to store large hunks of data.
*/
@interface OFBigArray: OFArray
{
size_t size;
}
/**
* Initializes an already allocated OFBigArray whose items all have the same
* size.
*
* \param is The size of each element in the OFBigArray
* \return An initialized OFBigArray
*/
- initWithItemSize: (size_t)is;
/**
* Adds an item to the OFBigArray.
*
* \param item An arbitrary item
*/
- add: (void*)item;
/**
* Adds items from a C array to the OFBigArray.
*
* \param nitems The number of items to add
* \param carray A C array containing the items to add
*/
- addNItems: (size_t)nitems
fromCArray: (void*)carray;
/**
* Removes a specified amount of the last items from the OFBigArray.
*
* \param nitems The number of items to remove
*/
- removeNItems: (size_t)nitems;
@end
|
Modified src/OFArray.m
from [5b2194bc15]
to [ea5c3825ad].
︙ | | |
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
-
+
-
+
+
+
+
+
+
|
#import "OFExceptions.h"
#import "OFMacros.h"
static size_t lastpagebyte = 0;
extern int getpagesize(void);
@implementation OFArray
+ newWithItemSize: (size_t)is
+ arrayWithItemSize: (size_t)is
{
return [[self alloc] initWithItemSize: is];
return [[[self alloc] initWithItemSize: is] autorelease];
}
+ bigArrayWithItemSize: (size_t)is
{
return [[[OFBigArray alloc] initWithItemSize: is] autorelease];
}
- initWithItemSize: (size_t)is
{
if ((self = [super init])) {
data = NULL;
itemsize = is;
|
︙ | | |
Modified src/OFAutoreleasePool.m
from [53c2a094cf]
to [6b8df1f839].
︙ | | |
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
-
+
|
return [super free];
}
- addToPool: (OFObject*)obj
{
if (objects == nil)
objects = [OFArray newWithItemSize: sizeof(char*)];
objects = [[OFArray alloc] initWithItemSize: sizeof(char*)];
[objects add: &obj];
return self;
}
- release
|
︙ | | |
Modified src/OFExceptions.h
from [5b59b73e4f]
to [fb7bdc037c].
︙ | | |
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
+
+
|
* the packaging of this file.
*/
#import "OFObject.h"
/**
* The OFException class is the base class for all exceptions in ObjFW.
*
* IMPORTANT: Exceptions do NOT use OFAutoreleasePools!!
*/
@interface OFException: OFObject
{
Class class;
char *string;
}
|
︙ | | |
Modified src/OFFile.h
from [c444256949]
to [75dce3944f].
︙ | | |
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
-
+
-
-
+
+
|
{
FILE *fp;
}
/**
* \param path The path to the file to open as a C string
* \param mode The mode in which the file should be opened as a C string
* \return A new OFFile
* \return A new autoreleased OFFile
*/
+ newWithPath: (const char*)path
andMode: (const char*)mode;
+ fileWithPath: (const char*)path
andMode: (const char*)mode;
/**
* Changes the mode of a file.
*
* Not available on Windows.
*
* \param path The path to the file of which the mode should be changed as a
* C string
|
︙ | | |
Modified src/OFFile.m
from [3489cc9954]
to [f8ec01874b].
︙ | | |
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
-
-
+
+
-
-
+
+
|
#import <sys/stat.h>
#endif
#import "OFFile.h"
#import "OFExceptions.h"
@implementation OFFile
+ newWithPath: (const char*)path
andMode: (const char*)mode
+ fileWithPath: (const char*)path
andMode: (const char*)mode
{
return [[self alloc] initWithPath: path
andMode: mode];
return [[[self alloc] initWithPath: path
andMode: mode] autorelease];
}
+ (void)changeModeOfFile: (const char*)path
toMode: (mode_t)mode
{
/*
* FIXME: On error, throw exception
|
︙ | | |
179
180
181
182
183
184
185
186
|
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
+
+
+
+
+
+
+
+
|
- (size_t)writeCString: (const char*)str
{
return [self writeNItems: strlen(str)
ofSize: 1
fromBuffer: (const uint8_t*)str];
}
- close
{
fclose(fp);
fp = NULL;
return self;
}
@end
|
Modified src/OFHashes.h
from [69af6f5e0e]
to [d9a99aea79].
︙ | | |
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
+
+
+
+
+
|
uint32_t buf[4];
uint32_t bits[2];
uint8_t in[64];
BOOL calculated;
}
/**
* \return A new autoreleased MD5 Hash
*/
+ md5Hash;
- init;
/**
* Adds a buffer to the hash to be calculated.
*
* \param buf The buffer which should be included into calculation.
* \param size The size of the buffer
|
︙ | | |
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
+
+
+
+
+
|
uint64_t count;
uint8_t buffer[64];
uint8_t digest[SHA1_DIGEST_SIZE];
BOOL calculated;
}
/**
* \return A new autoreleased SHA1 Hash
*/
+ sha1Hash;
- init;
/**
* Adds a buffer to the hash to be calculated.
*
* \param buf The buffer which should be included into calculation.
* \param size The size of the buffer
|
︙ | | |
Modified src/OFHashes.m
from [7cf61e44ad]
to [8790812f47].
︙ | | |
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
+
+
+
+
+
|
buf[0] += a;
buf[1] += b;
buf[2] += c;
buf[3] += d;
}
@implementation OFMD5Hash
+ md5Hash
{
return [[[self alloc] init] autorelease];
}
- init
{
if ((self = [super init])) {
buf[0] = 0x67452301;
buf[1] = 0xEFCDAB89;
buf[2] = 0x98BADCFE;
buf[3] = 0x10325476;
|
︙ | | |
349
350
351
352
353
354
355
356
357
358
359
360
361
362
|
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
|
+
+
+
+
+
|
} else
i = 0;
memcpy(&buffer[j], &buf[i], size - i);
}
@implementation OFSHA1Hash
+ sha1Hash
{
return [[[self alloc] init] autorelease];
}
- init
{
if ((self = [super init])) {
count = 0;
state[0] = 0x67452301;
state[1] = 0xEFCDAB89;
state[2] = 0x98BADCFE;
|
︙ | | |
Modified src/OFList.h
from [439fd52763]
to [d92e163846].
︙ | | |
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
+
+
+
+
|
*/
@interface OFList: OFObject
{
of_list_object_t *first;
of_list_object_t *last;
BOOL retain_and_release;
}
/**
* \return A new autoreleased OFList
*/
+ list;
/**
* Initializes an already allocated OFList.
*
* \param enabled Whether release / retain should be called when an object is
* added / removed. Default: YES
* \return An initialized OFList
|
︙ | | |
Modified src/OFList.m
from [f248439ac0]
to [d340619ba8].
︙ | | |
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
+
+
+
+
+
|
*/
#import "config.h"
#import "OFList.h"
@implementation OFList
+ list
{
return [[[self alloc] init] autorelease];
}
- init
{
if ((self = [super init])) {
first = NULL;
last = NULL;
retain_and_release = YES;
}
|
︙ | | |
Modified src/OFNumber.h
from [9ee2537120]
to [3bc9a9c5bd].
︙ | | |
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
|
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
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
float float_;
double double_;
long double longdouble;
} value;
enum of_number_type type;
}
+ newWithChar: (char)char_;
+ newWithShort: (short)short_;
+ newWithInt: (int)int_;
+ newWithLong: (long)long_;
+ newWithUChar: (unsigned char)uchar;
+ newWithUShort: (unsigned short)ushort;
+ newWithUInt: (unsigned int)uint;
+ newWithULong: (unsigned long)ulong;
+ newWithInt8: (int8_t)int8;
+ newWithInt16: (int16_t)int16;
+ newWithInt32: (int32_t)int32;
+ newWithInt64: (int64_t)int64;
+ newWithUInt8: (uint8_t)uint8;
+ newWithUInt16: (uint16_t)uint16;
+ newWithUInt32: (uint32_t)uint32;
+ newWithUInt64: (uint64_t)uint64;
+ newWithSize: (size_t)size;
+ newWithSSize: (ssize_t)ssize;
+ newWithPtrDiff: (ptrdiff_t)ptrdiff;
+ newWithIntPtr: (intptr_t)intptr;
+ newWithFloat: (float)float_;
+ newWithDouble: (double)double_;
+ newWithLongDouble: (long double)longdouble;
+ numberWithChar: (char)char_;
+ numberWithShort: (short)short_;
+ numberWithInt: (int)int_;
+ numberWithLong: (long)long_;
+ numberWithUChar: (unsigned char)uchar;
+ numberWithUShort: (unsigned short)ushort;
+ numberWithUInt: (unsigned int)uint;
+ numberWithULong: (unsigned long)ulong;
+ numberWithInt8: (int8_t)int8;
+ numberWithInt16: (int16_t)int16;
+ numberWithInt32: (int32_t)int32;
+ numberWithInt64: (int64_t)int64;
+ numberWithUInt8: (uint8_t)uint8;
+ numberWithUInt16: (uint16_t)uint16;
+ numberWithUInt32: (uint32_t)uint32;
+ numberWithUInt64: (uint64_t)uint64;
+ numberWithSize: (size_t)size;
+ numberWithSSize: (ssize_t)ssize;
+ numberWithPtrDiff: (ptrdiff_t)ptrdiff;
+ numberWithIntPtr: (intptr_t)intptr;
+ numberWithFloat: (float)float_;
+ numberWithDouble: (double)double_;
+ numberWithLongDouble: (long double)longdouble;
- initWithChar: (char)char_;
- initWithShort: (short)short_;
- initWithInt: (int)int_;
- initWithLong: (long)long_;
- initWithUChar: (unsigned char)uchar;
- initWithUShort: (unsigned short)ushort;
|
︙ | | |
Modified src/OFNumber.m
from [76fb7ad662]
to [714973113c].
︙ | | |
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
|
@throw [OFInvalidFormatException newWithClass: [self class]]; \
\
/* Make gcc happy */ \
return 0; \
}
@implementation OFNumber
+ newWithChar: (char)char_
+ numberWithChar: (char)char_
{
return [[self alloc] initWithChar: char_];
return [[[self alloc] initWithChar: char_] autorelease];
}
+ newWithShort: (short)short_
+ numberWithShort: (short)short_
{
return [[self alloc] initWithShort: short_];
return [[[self alloc] initWithShort: short_] autorelease];
}
+ newWithInt: (int)int_
+ numberWithInt: (int)int_
{
return [[self alloc] initWithInt: int_];
return [[[self alloc] initWithInt: int_] autorelease];
}
+ newWithLong: (long)long_
+ numberWithLong: (long)long_
{
return [[self alloc] initWithLong: long_];
return [[[self alloc] initWithLong: long_] autorelease];
}
+ newWithUChar: (unsigned char)uchar
+ numberWithUChar: (unsigned char)uchar
{
return [[self alloc] initWithUChar: uchar];
return [[[self alloc] initWithUChar: uchar] autorelease];
}
+ newWithUShort: (unsigned short)ushort
+ numberWithUShort: (unsigned short)ushort
{
return [[self alloc] initWithUShort: ushort];
return [[[self alloc] initWithUShort: ushort] autorelease];
}
+ newWithUInt: (unsigned int)uint
+ numberWithUInt: (unsigned int)uint
{
return [[self alloc] initWithUInt: uint];
return [[[self alloc] initWithUInt: uint] autorelease];
}
+ newWithULong: (unsigned long)ulong
+ numberWithULong: (unsigned long)ulong
{
return [[self alloc] initWithULong: ulong];
return [[[self alloc] initWithULong: ulong] autorelease];
}
+ newWithInt8: (int8_t)int8
+ numberWithInt8: (int8_t)int8
{
return [[self alloc] initWithInt8: int8];
return [[[self alloc] initWithInt8: int8] autorelease];
}
+ newWithInt16: (int16_t)int16
+ numberWithInt16: (int16_t)int16
{
return [[self alloc] initWithInt16: int16];
return [[[self alloc] initWithInt16: int16] autorelease];
}
+ newWithInt32: (int32_t)int32
+ numberWithInt32: (int32_t)int32
{
return [[self alloc] initWithInt32: int32];
return [[[self alloc] initWithInt32: int32] autorelease];
}
+ newWithInt64: (int64_t)int64
+ numberWithInt64: (int64_t)int64
{
return [[self alloc] initWithInt64: int64];
return [[[self alloc] initWithInt64: int64] autorelease];
}
+ newWithUInt8: (uint8_t)uint8
+ numberWithUInt8: (uint8_t)uint8
{
return [[self alloc] initWithUInt8: uint8];
return [[[self alloc] initWithUInt8: uint8] autorelease];
}
+ newWithUInt16: (uint16_t)uint16
+ numberWithUInt16: (uint16_t)uint16
{
return [[self alloc] initWithUInt16: uint16];
return [[[self alloc] initWithUInt16: uint16] autorelease];
}
+ newWithUInt32: (uint32_t)uint32
+ numberWithUInt32: (uint32_t)uint32
{
return [[self alloc] initWithUInt32: uint32];
return [[[self alloc] initWithUInt32: uint32] autorelease];
}
+ newWithUInt64: (uint64_t)uint64
+ numberWithUInt64: (uint64_t)uint64
{
return [[self alloc] initWithUInt64: uint64];
return [[[self alloc] initWithUInt64: uint64] autorelease];
}
+ newWithSize: (size_t)size
+ numberWithSize: (size_t)size
{
return [[self alloc] initWithSize: size];
return [[[self alloc] initWithSize: size] autorelease];
}
+ newWithSSize: (ssize_t)ssize
+ numberWithSSize: (ssize_t)ssize
{
return [[self alloc] initWithSSize: ssize];
return [[[self alloc] initWithSSize: ssize] autorelease];
}
+ newWithPtrDiff: (ptrdiff_t)ptrdiff
+ numberWithPtrDiff: (ptrdiff_t)ptrdiff
{
return [[self alloc] initWithPtrDiff: ptrdiff];
return [[[self alloc] initWithPtrDiff: ptrdiff] autorelease];
}
+ newWithIntPtr: (intptr_t)intptr
+ numberWithIntPtr: (intptr_t)intptr
{
return [[self alloc] initWithIntPtr: intptr];
return [[[self alloc] initWithIntPtr: intptr] autorelease];
}
+ newWithFloat: (float)float_
+ numberWithFloat: (float)float_
{
return [[self alloc] initWithFloat: float_];
return [[[self alloc] initWithFloat: float_] autorelease];
}
+ newWithDouble: (double)double_
+ numberWithDouble: (double)double_
{
return [[self alloc] initWithDouble: double_];
return [[[self alloc] initWithDouble: double_] autorelease];
}
+ newWithLongDouble: (long double)longdouble
+ numberWithLongDouble: (long double)longdouble
{
return [[self alloc] initWithLongDouble: longdouble];
return [[[self alloc] initWithLongDouble: longdouble] autorelease];
}
- initWithChar: (char)char_
{
if ((self = [super init])) {
value.char_ = char_;
type = OF_NUMBER_CHAR;
|
︙ | | |
Modified src/OFStream.h
from [63e211130f]
to [ae18f564f1].
︙ | | |
46
47
48
49
50
51
52
53
|
46
47
48
49
50
51
52
53
54
55
56
57
58
|
+
+
+
+
+
|
/**
* Writes a C string into the stream, without the trailing zero.
*
* \param str The C string from which the data is written to the stream
* \return The number of bytes written
*/
- (size_t)writeCString: (const char*)str;
/**
* Closes the stream.
*/
- close;
@end
|
Modified src/OFString.h
from [24a3ce2979]
to [3f383f6fa1].
︙ | | |
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
|
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
122
|
+
+
+
+
+
-
+
-
+
-
+
-
+
-
+
-
-
+
+
-
+
-
+
-
-
+
+
-
+
-
+
-
|
@interface OFString: OFObject
{
char *string;
size_t length;
BOOL is_utf8;
}
/**
* \return A new autoreleased OFString
*/
+ string;
/**
* Creates a new OFString from a C string.
*
* \param str A C string to initialize the OFString with
* \return A new OFString
* \return A new autoreleased OFString
*/
+ newFromCString: (const char*)str;
+ stringWithCString: (const char*)str;
/**
* Creates a new OFString from a format C string.
* See printf for the format syntax.
*
* \param fmt A C string used as format to initialize the OFString
* \return A new OFString
* \return A new autoreleased OFString
*/
+ newFromFormatCString: (const char*)fmt, ...;
+ stringWithFormat: (const char*)fmt, ...;
/**
* Creates a new OFString from a format C string.
* See printf for the format syntax.
*
* \param fmt A C string used as format to initialize the OFString
* \param args The arguments used in the format string
* \return A new OFString
* \return A new autoreleased OFString
*/
+ newFromFormatCString: (const char*)fmt
withArguments: (va_list)args;
+ stringWithFormat: (const char*)fmt
andArguments: (va_list)args;
/**
* Initializes an already allocated OFString.
*
* \return An initialized OFString
*/
- init;
/**
* Initializes an already allocated OFString from a C string.
*
* \param str A C string to initialize the OFString with
* \return An initialized OFString
*/
- initFromCString: (const char*)str;
- initWithCString: (const char*)str;
/**
* Initializes an already allocated OFString from a format C string.
* See printf for the format syntax.
*
* \param fmt A C string used as format to initialize the OFString
* \return An initialized OFString
*/
- initFromFormatCString: (const char*)fmt, ...;
- initWithFormat: (const char*)fmt, ...;
/**
* Initializes an already allocated OFString from a format C string.
* See printf for the format syntax.
*
* \param fmt A C string used as format to initialize the OFString
* \param args The arguments used in the format string
* \return An initialized OFString
*/
- initFromFormatCString: (const char*)fmt
withArguments: (va_list)args;
- initWithFormat: (const char*)fmt
andArguments: (va_list)args;
/**
* \return The OFString as a wide C string
*/
- (const char*)cString;
/**
* \return The length of the OFString
*/
- (size_t)length;
/**
* Clones the OFString, creating a new one.
*
* \return A copy of the OFString
* \return A new autoreleased copy of the OFString
*/
- (OFString*)clone;
/**
* Frees the OFString and sets it to the specified OFString.
* Sets the OFString to the specified OFString.
*
* \param str An OFString to set the OFString to.
* \return The new OFString
*/
- setTo: (OFString*)str;
/**
* Compares the OFString to another OFString.
*
* \param str An OFString to compare with
|
︙ | | |
Modified src/OFString.m
from [7c7b5b7fed]
to [f753114c1f].
︙ | | |
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
+
+
+
+
+
-
+
-
+
-
+
-
-
+
+
-
-
+
+
-
-
+
+
-
+
|
madvise((void*)str, len, MADV_NORMAL);
return (utf8 ? 1 : 0);
}
@implementation OFString
+ string
{
return [[[self alloc] init] autorelease];
}
+ newFromCString: (const char*)str
+ stringWithCString: (const char*)str
{
return [[self alloc] initFromCString: str];
return [[[self alloc] initWithCString: str] autorelease];
}
+ newFromFormatCString: (const char*)fmt, ...
+ stringWithFormat: (const char*)fmt, ...
{
id ret;
va_list args;
va_start(args, fmt);
ret = [[self alloc] initFromFormatCString: fmt
withArguments: args];
ret = [[[self alloc] initWithFormat: fmt
andArguments: args] autorelease];
va_end(args);
return ret;
}
+ newFromFormatCString: (const char*)fmt
withArguments: (va_list)args
+ stringWithFormat: (const char*)fmt
andArguments: (va_list)args
{
return [[self alloc] initFromFormatCString: fmt
withArguments: args];
return [[[self alloc] initWithFormat: fmt
andArguments: args] autorelease];
}
- init
{
if ((self = [super init])) {
length = 0;
string = NULL;
is_utf8 = NO;
}
return self;
}
- initFromCString: (const char*)str
- initWithCString: (const char*)str
{
Class c;
if ((self = [super init])) {
if (str != NULL) {
length = strlen(str);
|
︙ | | |
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
-
+
-
-
+
+
-
-
+
+
|
memcpy(string, str, length + 1);
}
}
return self;
}
- initFromFormatCString: (const char*)fmt, ...
- initWithFormat: (const char*)fmt, ...
{
id ret;
va_list args;
va_start(args, fmt);
ret = [self initFromFormatCString: fmt
withArguments: args];
ret = [self initWithFormat: fmt
andArguments: args];
va_end(args);
return ret;
}
- initFromFormatCString: (const char*)fmt
withArguments: (va_list)args
- initWithFormat: (const char*)fmt
andArguments: (va_list)args
{
int t;
Class c;
if ((self = [super init])) {
if (fmt == NULL) {
c = [self class];
|
︙ | | |
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
|
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
|
- (size_t)length
{
return length;
}
- (OFString*)clone
{
return [OFString newFromCString: string];
return [OFString stringWithCString: string];
}
- setTo: (OFString*)str
{
size_t len;
[self free];
return (self = [str clone]);
if (string != NULL)
free(string);
len = [str length];
switch (check_utf8([str cString], len)) {
case 1:
is_utf8 = YES;
break;
case -1:
string = NULL;
length = 0;
is_utf8 = NO;
@throw [OFInvalidEncodingException newWithClass: [self class]];
}
length = len;
string = [self getMemWithSize: length + 1];
memcpy(string, [str cString], length + 1);
return self;
}
- (int)compareTo: (OFString*)str
{
return strcmp(string, [str cString]);
}
- append: (OFString*)str
{
return [self appendCString: [str cString]];
}
- appendCString: (const char*)str
{
char *newstr;
size_t newlen, strlength;
if (string == NULL)
return [self setTo: [OFString newFromCString: str]];
strlength = strlen(str);
switch (check_utf8(str, strlength)) {
case 1:
is_utf8 = YES;
break;
case -1:
|
︙ | | |
Modified src/OFTCPSocket.h
from [f01ceb564c]
to [968f2d5f3e].
︙ | | |
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
+
+
+
+
+
|
#else
SOCKET sock;
#endif
struct sockaddr *saddr;
socklen_t saddr_len;
}
/**
* \return A new autoreleased OFTCPSocket
*/
+ tcpSocket;
/**
* Initializes an already allocated OFTCPSocket.
*
* \return An initialized OFTCPSocket
*/
- init;
|
︙ | | |
Modified src/OFTCPSocket.m
from [7d0fea78bc]
to [c9f6264550].
︙ | | |
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
+
+
+
+
+
|
#import "OFExceptions.h"
#ifndef INVALID_SOCKET
#define INVALID_SOCKET -1
#endif
@implementation OFTCPSocket
+ tcpSocket
{
return [[[self alloc] init] autorelease];
}
#ifdef _WIN32
+ (void)initialize
{
WSADATA wsa;
if (WSAStartup(MAKEWORD(2, 0), &wsa))
@throw [OFInitializationFailedException newWithClass: self];
|
︙ | | |
Modified tests/OFArray/OFArray.m
from [211a3acfce]
to [0b1404de72].
︙ | | |
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
-
+
|
puts("Resuming..."); \
}
const char *str = "Hallo!";
#define TEST(type) \
puts("Trying to add too much to an array..."); \
a = [type newWithItemSize: 4096]; \
a = [[type alloc] initWithItemSize: 4096]; \
CATCH_EXCEPTION([a addNItems: SIZE_MAX \
fromCArray: NULL], \
OFOutOfRangeException) \
\
puts("Trying to add something after that error..."); \
p = [a getMemWithSize: 4096]; \
memset(p, 255, 4096); \
|
︙ | | |
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
|
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
|
-
+
-
+
-
+
|
puts("Trying to remove more data than we added..."); \
CATCH_EXCEPTION([a removeNItems: [a items] + 1], \
OFOutOfRangeException); \
\
puts("Trying to access an index that does not exist..."); \
CATCH_EXCEPTION([a item: [a items]], OFOutOfRangeException); \
\
[a free]; \
[a release]; \
\
puts("Creating new array and using it to build a string..."); \
a = [type newWithItemSize: 1]; \
a = [[type alloc] initWithItemSize: 1]; \
\
for (i = 0; i < strlen(str); i++) \
[a add: (void*)&str[i]]; \
[a add: ""]; \
\
if (!strcmp([a data], str)) \
puts("Built string matches!"); \
else { \
puts("Built string does not match!"); \
abort(); \
} \
\
[a free];
[a release];
int
main()
{
id a;
void *p, *q;
size_t i;
|
︙ | | |
Modified tests/OFHashes/OFHashes.m
from [4cc440481a]
to [c778845c1b].
︙ | | |
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
|
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
|
-
-
-
-
+
+
+
+
-
+
-
-
|
int
main()
{
uint8_t buf[64];
size_t len;
OFMD5Hash *md5 = [OFMD5Hash new];
OFSHA1Hash *sha1 = [OFSHA1Hash new];
OFFile *f = [OFFile newWithPath: "testfile"
andMode: "rb"];
OFMD5Hash *md5 = [OFMD5Hash md5Hash];
OFSHA1Hash *sha1 = [OFSHA1Hash sha1Hash];
OFFile *f = [OFFile fileWithPath: "testfile"
andMode: "rb"];
while (![f atEndOfFile]) {
len = [f readNBytes: 64
intoBuffer: buf];
[md5 updateWithBuffer: buf
ofSize: len];
[sha1 updateWithBuffer: buf
ofSize: len];
}
[f free];
[f close];
if (!memcmp([md5 digest], testfile_md5, MD5_DIGEST_SIZE)) {
fputs("\r\033[1;33mTests successful: 1/2\033[0m", stdout);
fflush(stdout);
} else {
puts("\r\033[K\033[1;31mTest 1/2 failed!\033[0m");
return 1;
}
[md5 free];
if (!memcmp([sha1 digest], testfile_sha1, SHA1_DIGEST_SIZE))
puts("\r\033[1;32mTests successful: 2/2\033[0m");
else {
puts("\r\033[K\033[1;31mTest 2/2 failed!\033[0m");
return 1;
}
[sha1 free];
return 0;
}
|
Modified tests/OFList/OFList.m
from [147b8c86d0]
to [61b6eedfea].
︙ | | |
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
|
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
|
-
+
-
-
-
+
+
+
-
+
-
+
|
int
main()
{
size_t i, j;
OFList *list;
of_list_object_t *iter;
list = [OFList new];
list = [OFList list];
[list append: [OFString newFromCString: strings[0]]];
[list append: [OFString newFromCString: strings[1]]];
[list append: [OFString newFromCString: strings[2]]];
[list append: [OFString stringWithCString: strings[0]]];
[list append: [OFString stringWithCString: strings[1]]];
[list append: [OFString stringWithCString: strings[2]]];
for (iter = [list first], i = 0; iter != NULL; iter = iter->next, i++)
if (!strcmp([iter->object cString], strings[i]))
SUCCESS
else
FAIL
CHECK(!strcmp([[list first]->object cString], strings[0]))
CHECK(!strcmp([[list last]->object cString], strings[2]))
[list remove: [list last]];
CHECK(!strcmp([[list last]->object cString], strings[1]))
[list remove: [list first]];
CHECK(!strcmp([[list first]->object cString],
[[list last]->object cString]))
[list insert: [OFString newFromCString: strings[0]]
[list insert: [OFString stringWithCString: strings[0]]
before: [list last]];
[list insert: [OFString newFromCString: strings[2]]
[list insert: [OFString stringWithCString: strings[2]]
after: [list first]->next];
for (iter = [list first], j = 0; iter != NULL; iter = iter->next, j++)
CHECK(!strcmp([iter->object cString], strings[j]))
puts("");
return 0;
}
|
Modified tests/OFString/OFString.m
from [a85f1b3a10]
to [ffc025b2b3].
︙ | | |
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
+
|
#import "config.h"
#import <string.h>
#import "OFString.h"
#import "OFExceptions.h"
#import "OFAutoreleasePool.h"
#import <stdio.h>
#ifndef _WIN32
#define ZD "%zd"
#else
#define ZD "%u"
|
︙ | | |
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
|
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
|
+
-
-
+
+
-
+
-
+
-
-
-
-
+
-
+
-
+
-
+
|
i++;
int
main()
{
size_t i = 0;
OFAutoreleasePool *pool = [OFAutoreleasePool new];
OFString *s1 = [OFString newFromCString: "test"];
OFString *s2 = [OFString newFromCString: ""];
OFString *s1 = [OFString stringWithCString: "test"];
OFString *s2 = [OFString stringWithCString: ""];
OFString *s3;
OFString *s4 = [OFString new];
OFString *s4 = [OFString string];
s3 = [s1 clone];
CHECK(![s1 compareTo: s3])
[s2 appendCString: "123"];
[s4 setTo: s2];
CHECK(![s2 compareTo: s4])
CHECK(!strcmp([[s1 append: s2] cString], "test123"))
CHECK(strlen([s1 cString]) == [s1 length] && [s1 length] == 7)
CHECK(!strcmp([[s1 reverse] cString], "321tset"))
CHECK(!strcmp([[s1 upper] cString], "321TSET"))
CHECK(!strcmp([[s1 lower] cString], "321tset"))
/* Also clears all the memory of the returned C strings */
[s1 free];
[pool release];
[s2 free];
[s3 free];
[s4 free];
/* UTF-8 tests */
CHECK_EXCEPT(s1 = [OFString newFromCString: "\xE0\x80"],
CHECK_EXCEPT(s1 = [OFString stringWithCString: "\xE0\x80"],
OFInvalidEncodingException)
CHECK_EXCEPT(s1 = [OFString newFromCString: "\xF0\x80\x80\xC0"],
CHECK_EXCEPT(s1 = [OFString stringWithCString: "\xF0\x80\x80\xC0"],
OFInvalidEncodingException)
s1 = [OFString newFromCString: "äöü€𝄞"];
s1 = [OFString stringWithCString: "äöü€𝄞"];
CHECK(!strcmp([[s1 reverse] cString], "𝄞€üöä"))
[s1 free];
/* Format tests */
s1 = [OFString newFromFormatCString: "%s: %d", "test", 123];
s1 = [OFString stringWithFormat: "%s: %d", "test", 123];
CHECK(!strcmp([s1 cString], "test: 123"))
[s1 appendWithFormatCString: "%02X", 15];
CHECK(!strcmp([s1 cString], "test: 1230F"))
puts("");
return 0;
}
|
Modified tests/OFTCPSocket/OFTCPSocket.m
from [0858553e55]
to [f9f0278503].
︙ | | |
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
-
-
+
+
|
main()
{
uint16_t port;
srand(time(NULL));
@try {
OFTCPSocket *server = [OFTCPSocket new];
OFTCPSocket *client = [OFTCPSocket new];
OFTCPSocket *server = [OFTCPSocket tcpSocket];
OFTCPSocket *client = [OFTCPSocket tcpSocket];
OFTCPSocket *accepted;
char buf[7];
puts("== IPv4 ==");
port = get_port();
[server bindOn: "localhost"
|
︙ | | |
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
-
+
|
puts("Received INCORRECT string!");
return 1;
}
#ifdef HAVE_IPV6
memset(buf, 0, 7);
[accepted free];
[accepted release];
[client close];
[server close];
puts("== IPv6 ==");
port = get_port();
[server bindOn: "::1"
|
︙ | | |
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
-
-
-
+
+
+
|
puts("Received correct string!");
else {
puts("Received INCORRECT string!");
return 1;
}
#endif
[accepted free];
[client free];
[server free];
[accepted release];
[client release];
[server release];
} @catch(OFException *e) {
printf("EXCEPTION: %s\n", [e cString]);
return 1;
}
return 0;
}
|