ObjFW  Diff

Differences From Artifact [1b2ac19bc0]:

To Artifact [ffeec9ddfb]:


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
	if ((self = [super init])) {
		if (wstr == NULL) {
			length = 0;
			wstring = NULL;
		} else {
			length = wcslen(wstr);
			wstring = [self getMem: (length + 1) * sizeof(wchar_t)];
			memcpy(wstring, wstr, (length + 1) * sizeof(wchar_t));
		}
	}
	return self;
}

- (wchar_t*)wcString
{
	return wstring;
}

- (size_t)length
{
	return length;
}

- (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);
	newstr = [self getMem: (newlen + 1) * sizeof(wchar_t)];
	memcpy(newstr, wstr, (newlen + 1) * sizeof(wchar_t));

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

	length = newlen;
	wstring = newstr;

	return self;
}

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

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

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

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

	newstr = [self resizeMem: wstring
			  toSize: (newlen + 1) * sizeof(wchar_t)];

	memcpy(newstr + length, wstr, (strlength + 1) * sizeof(wchar_t));

	length = newlen;
	wstring = newstr;

	return self;
}

- (int)compare: (OFWideString*)str
{
	return wcscmp(wstring, [str wcString]);
}
@end







|















|




|








|

|















|




|


|





|







|




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
	if ((self = [super init])) {
		if (wstr == NULL) {
			length = 0;
			wstring = NULL;
		} else {
			length = wcslen(wstr);
			wstring = [self getMem: (length + 1) * sizeof(wchar_t)];
			wmemcpy(wstring, wstr, length + 1);
		}
	}
	return self;
}

- (wchar_t*)wcString
{
	return wstring;
}

- (size_t)length
{
	return length;
}

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

		length = 0;
		wstring = NULL;

		return self;
	}

	newlen = [wstr length];
	newstr = [self getMem: (newlen + 1) * sizeof(wchar_t)];
	wmemcpy(newstr, [wstr wcString], newlen + 1);

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

	length = newlen;
	wstring = newstr;

	return self;
}

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

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

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

	strlength = [wstr length];
	newlen = length + strlength;

	newstr = [self resizeMem: wstring
			  toSize: (newlen + 1) * sizeof(wchar_t)];

	wmemcpy(newstr + length, [wstr wcString], strlength + 1);

	length = newlen;
	wstring = newstr;

	return self;
}

- (int)compare: (OFConstWideString*)str
{
	return wcscmp(wstring, [str wcString]);
}
@end