ObjFW  Check-in [cebd6fbbfc]

Overview
Comment:Implement reverse for OF(Wide)CString & rename wcString -> wCString.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: cebd6fbbfcb352fd0162464b1a27377c5203d1c6003ad1203465dc2a6220da4d
User & Date: js on 2008-11-19 18:27:59
Other Links: manifest | tags
Context
2008-11-23
06:11
New string API, string class completely rewritten.
One class for all string types now.
check-in: bf02f0ef25 user: js tags: trunk
2008-11-19
18:27
Implement reverse for OF(Wide)CString & rename wcString -> wCString. check-in: cebd6fbbfc user: js tags: trunk
18:11
Fix missing rm. check-in: 4c5e4752da user: js tags: trunk
Changes

Modified src/OFCString.h from [af15a5856e] to [4014e47d9b].

64
65
66
67
68
69
70





71
64
65
66
67
68
69
70
71
72
73
74
75
76







+
+
+
+
+


/**
 * Append a C string to the OFCString.
 *
 * \param str A C string to append
 */
- appendCString: (const char*)str;

/**
 * Reverse the OFCString.
 */
- reverse;
@end

Modified src/OFCString.m from [92741a24d4] to [745d2596c4].

72
73
74
75
76
77
78













79
80
81
82
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95







+
+
+
+
+
+
+
+
+
+
+
+
+




	newstr = [self resizeMem: string
			  toSize: newlen + 1];

	memcpy(newstr + length, str, strlength + 1);

	length = newlen;
	string = newstr;

	return self;
}

- reverse
{
	size_t i, j, len = length / 2;

	for (i = 0, j = length - 1; i < len; i++, j--) {
		string[i] ^= string[j];
		string[j] ^= string[i];
		string[i] ^= string[j];
	}

	return self;
}
@end

Modified src/OFConstWideCString.h from [85176fdaf9] to [441911b239].

30
31
32
33
34
35
36
37

38
39
40
41
42
43
44
30
31
32
33
34
35
36

37
38
39
40
41
42
43
44







-
+







 * \return An initialized OFConstWideCString
 */
- initAsConstWideCString: (const wchar_t*)str;

/**
 * \return The OFConstWideCString as a constant wide C string
 */
- (const wchar_t*)wcString;
- (const wchar_t*)wCString;

/**
 * \return The length of the OFConstWideCString
 */
- (size_t)length;

/**

Modified src/OFConstWideCString.m from [ef59396699] to [1a558eeed6].

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







-
+
















-
+


			length = wcslen(str);
			string = str;
		}
	}
	return self;
}

- (const wchar_t*)wcString
- (const wchar_t*)wCString
{
	return string;
}

- (size_t)length
{
	return length;
}

- (OFString*)clone
{
	return [OFString newAsConstWideCString: string];
}

- (int)compareTo: (OFString*)str
{
	return wcscmp(string, [str wcString]);
	return wcscmp(string, [str wCString]);
}
@end

Modified src/OFString.h from [74c6375e2f] to [d4d814f095].

48
49
50
51
52
53
54
55

56
57
58
59
60
61
62
48
49
50
51
52
53
54

55
56
57
58
59
60
61
62







-
+







 * \return The OFString as a C-type string of the type it was created as
 */
- (char*)cString;

/**
 * \return The OFString as a C-type wide string of the type it was created as
 */
- (wchar_t*)wcString;
- (wchar_t*)wCString;

/**
 * \return The length of the OFString
 */
- (size_t)length;

/**
97
98
99
100
101
102
103





104
97
98
99
100
101
102
103
104
105
106
107
108
109







+
+
+
+
+


/**
 * Append a wide C string to the OFString.
 *
 * \param str A wide C string to append
 */
- appendWideCString: (const wchar_t*)str;

/**
 * Reverse the OFString.
 */
- reverse;
@end

Modified src/OFString.m from [d41ed2e6b4] to [fbb622def6].

44
45
46
47
48
49
50
51

52
53
54
55
56
57
58
44
45
46
47
48
49
50

51
52
53
54
55
56
57
58







-
+







}

- (char*)cString
{
	OF_NOT_IMPLEMENTED(NULL)
}

- (wchar_t*)wcString
- (wchar_t*)wCString
{
	OF_NOT_IMPLEMENTED(NULL)
}

- (size_t)length
{
	OF_NOT_IMPLEMENTED(0)
82
83
84
85
86
87
88





89
90
91
92
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97







+
+
+
+
+





- appendCString: (const char*)str
{
	OF_NOT_IMPLEMENTED(nil)
}

- appendWideCString: (const wchar_t*)str
{
	OF_NOT_IMPLEMENTED(nil)
}

- reverse
{
	OF_NOT_IMPLEMENTED(nil)
}
@end

Modified src/OFWideCString.h from [81a5610d59] to [3ceaa14475].

30
31
32
33
34
35
36
37

38
39
40
41
42
43
44
30
31
32
33
34
35
36

37
38
39
40
41
42
43
44







-
+







 * \return An initialized OFWideCString
 */
- initAsWideCString: (wchar_t*)str;

/**
 * \return The OFWideCString as a wide C string
 */
- (wchar_t*)wcString;
- (wchar_t*)wCString;

/**
 * \return The length of the OFWideCString
 */
- (size_t)length;

/**
65
66
67
68
69
70
71





72
65
66
67
68
69
70
71
72
73
74
75
76
77







+
+
+
+
+


/**
 * Append a wide C string to the OFWideCString.
 *
 * \param str A wide C string to append
 */
- appendWideCString: (const wchar_t*)str;

/**
 * Reverse the OFWideCString.
 */
- reverse;
@end

Modified src/OFWideCString.m from [882172ee7f] to [979098a330].

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







-
+
















-
+




-
+







							   sizeof(wchar_t)];
			wmemcpy(string, str, length + 1);
		}
	}
	return self;
}

- (wchar_t*)wcString
- (wchar_t*)wCString
{
	return string;
}

- (size_t)length
{
	return length;
}

- (OFString*)clone
{
	return [OFString newAsWideCString: string];
}

- (int)compareTo: (OFString*)str
{
	return wcscmp(string, [str wcString]);
	return wcscmp(string, [str wCString]);
}

- append: (OFString*)str
{
	return [self appendWideCString: [str wcString]];
	return [self appendWideCString: [str wCString]];
}

- appendWideCString: (const wchar_t*)str
{
	wchar_t	*newstr;
	size_t	newlen, strlength;

75
76
77
78
79
80
81













82
83
84
85
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98







+
+
+
+
+
+
+
+
+
+
+
+
+




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

	wmemcpy(newstr + length, str, strlength + 1);

	length = newlen;
	string = newstr;

	return self;
}

- reverse
{
	size_t i, j, len = length / 2;

	for (i = 0, j = length - 1; i < len; i++, j--) {
		string[i] ^= string[j];
		string[j] ^= string[i];
		string[i] ^= string[j];
	}

	return self;
}
@end

Modified tests/OFString/OFString.m from [1ba1ce211e] to [97aa03dbaf].

52
53
54
55
56
57
58







59
60
61
62
63
64
65
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72







+
+
+
+
+
+
+








	if (strlen([s1 cString]) == [s1 length] && [s1 length] == 7)
		puts("s1 has the expected length. GOOD!");
	else {
		puts("s1 does not have the expected length!");
		return 1;
	}

	if (!strcmp([[s1 reverse] cString], "321tset"))
		puts("Reversed s1 is expected string! GOOD!");
	else {
		puts("Reversed s1 is NOT the expected string!");
		return 1;
	}

	[s1 free];
	[s2 free];
	[s3 free];
	[s4 free];

	return 0;

Modified tests/OFWideString/OFWideString.m from [437fd29f56] to [1851e3e09d].

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







-
+






-
+





+
+
+
+
+
+
+







	if (![s2 compareTo: s4])
		puts("s2 and s4 match! GOOD!");
	else {
		puts("s1 and s3 don't match!");
		return 1;
	}

	if (!wcscmp([[s1 append: s2] wcString], L"test123"))
	if (!wcscmp([[s1 append: s2] wCString], L"test123"))
		puts("s1 appended with s2 is the expected string! GOOD!");
	else {
		puts("s1 appended with s2 is not the expected string!");
		return 1;
	}

	if (wcslen([s1 wcString]) == [s1 length] && [s1 length] == 7)
	if (wcslen([s1 wCString]) == [s1 length] && [s1 length] == 7)
		puts("s1 has the expected length. GOOD!");
	else {
		puts("s1 does not have the expected length!");
		return 1;
	}

	if (!wcscmp([[s1 reverse] wCString], L"321tset"))
		puts("Reversed s1 is expected string! GOOD!");
	else {
		puts("Reversed s1 is NOT the expected string!");
		return 1;
	}

	[s1 free];
	[s2 free];
	[s3 free];
	[s4 free];

	return 0;