ObjFW  Diff

Differences From Artifact [f3e926533b]:

To Artifact [3d87632f9d]:


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
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







-
+

-
+




-
+


-
+








-
+

















-
+














-
+




-
+









-
+








-
+




+
-
-
+
+
-

-













#import <stdlib.h>
#import <string.h>
#import <wchar.h>
#import "OFWideString.h"

@implementation OFWideString
+ new:(const wchar_t*)wstr
+ new: (const wchar_t*)wstr
{
	return [[OFWideString alloc] init:wstr];
	return [[OFWideString alloc] init: wstr];
}

- init
{
	return [self init:NULL];
	return [self init: NULL];
}

- init:(const wchar_t*)wstr
- init: (const wchar_t*)wstr
{
	if ((self = [super init])) {
		if (wstr == NULL) {
			length = 0;
			wstring = NULL;
		} else {
			length = wcslen(wstr);
			if ((wstring =
			    [self getMem:length * sizeof(wchar_t)]) == NULL)
			    [self getMem: length * sizeof(wchar_t)]) == NULL)
				return NULL;
			memcpy(wstring, wstr, length * sizeof(wchar_t));
		}
	}
	return self;
}

- (wchar_t*)wcString
{
	return wstring;
}

- (size_t)length
{
	return length;
}

- (OFWideString*)setTo:(const wchar_t*)wstr
- (OFWideString*)setTo: (const wchar_t*)wstr
{
	wchar_t *newstr;
	size_t  newlen;
	
	if (wstr == NULL) {
		[self freeMem:wstring];

		length = 0;
		wstring = NULL;

		return self;
	}

	newlen = wcslen(wstr);
	if ((newstr = [self getMem:newlen * sizeof(wchar_t)]) == NULL)
	if ((newstr = [self getMem: newlen * sizeof(wchar_t)]) == NULL)
		return nil;
	memcpy(newstr, wstr, newlen * sizeof(wchar_t));

	if (wstring != NULL)
		[self freeMem:wstring];
		[self freeMem: wstring];

	length = newlen;
	wstring = newstr;

	return self;
}

- (OFWideString*)clone
{
	return [OFWideString new:wstring];
	return [OFWideString new: wstring];
}

- (OFWideString*)append: (const wchar_t*)wstr
{
	wchar_t	*newstr;
	size_t	newlen, strlength;

	if (wstr == NULL)
		return [self setTo:wstr];
		return [self setTo: wstr];

	strlength = wcslen(wstr);
	newlen = length + strlength;

	/* FIXME: Add error handling */
	if ((newstr = [self resizeMem:wstring toSize:(newlen + 1) * 
				      sizeof(wchar_t)]) == NULL) {
	if ((newstr = [self resizeMem: wstring
			       toSize: newlen  * sizeof(wchar_t) + 2]) == NULL)
		/* FIXME: Add error handling */
		return nil;
	}

	wstring = newstr;

	memcpy(wstring + length * sizeof(wchar_t), wstr,
	    strlength * sizeof(wchar_t));
	wstring[newlen] = '\0';

	length = newlen;

	return self;
}
@end