ObjFW  Diff

Differences From Artifact [f7c6b63b6d]:

To Artifact [deb6471012]:


24
25
26
27
28
29
30


31
32
33
34
35
36
37
#import "OFURL.h"
#import "OFHTTPRequest.h"
#import "OFHTTPResponse.h"
#import "OFHTTPClient.h"
#import "OFFile.h"
#import "OFStdIOStream.h"



#import "TableGenerator.h"
#import "copyright.h"

#define UNICODE_DATA_URL \
	@"http://www.unicode.org/Public/UNIDATA/UnicodeData.txt"
#define CASE_FOLDING_URL \
	@"http://www.unicode.org/Public/UNIDATA/CaseFolding.txt"







>
>







24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#import "OFURL.h"
#import "OFHTTPRequest.h"
#import "OFHTTPResponse.h"
#import "OFHTTPClient.h"
#import "OFFile.h"
#import "OFStdIOStream.h"

#import "OFOutOfRangeException.h"

#import "TableGenerator.h"
#import "copyright.h"

#define UNICODE_DATA_URL \
	@"http://www.unicode.org/Public/UNIDATA/UnicodeData.txt"
#define CASE_FOLDING_URL \
	@"http://www.unicode.org/Public/UNIDATA/CaseFolding.txt"
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

- (void)applicationDidFinishLaunching
{
	OFString *path;
	[self parseUnicodeData];
	[self parseCaseFolding];

	[of_stdout writeString: @"Writing files..."];

	path = [OFString pathWithComponents: [OFArray arrayWithObjects:
	    OF_PATH_PARENT_DIRECTORY, @"src", @"unicode.m", nil]];
	[self writeTablesToFile: path];

	path = [OFString pathWithComponents: [OFArray arrayWithObjects:
	    OF_PATH_PARENT_DIRECTORY, @"src", @"unicode.h", nil]];







|







55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

- (void)applicationDidFinishLaunching
{
	OFString *path;
	[self parseUnicodeData];
	[self parseCaseFolding];

	[of_stdout writeString: @"Writing files"];

	path = [OFString pathWithComponents: [OFArray arrayWithObjects:
	    OF_PATH_PARENT_DIRECTORY, @"src", @"unicode.m", nil]];
	[self writeTablesToFile: path];

	path = [OFString pathWithComponents: [OFArray arrayWithObjects:
	    OF_PATH_PARENT_DIRECTORY, @"src", @"unicode.h", nil]];
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
{
	void *pool = objc_autoreleasePoolPush();
	OFHTTPRequest *request;
	OFHTTPClient *client;
	OFHTTPResponse *response;
	OFString *line;

	[of_stdout writeString: @"Downloading and parsing UnicodeData.txt..."];

	request = [OFHTTPRequest requestWithURL:
	    [OFURL URLWithString: UNICODE_DATA_URL]];
	client = [OFHTTPClient client];
	response = [client performRequest: request];

	while ((line = [response readLine]) != nil) {
		void *pool2;
		OFArray OF_GENERIC(OFString *) *split;
		OFString *const *splitObjects;
		of_unichar_t codep;

		if ([line length] == 0)
			continue;

		pool2 = objc_autoreleasePoolPush();

		split = [line componentsSeparatedByString: @";"];
		if ([split count] != 15) {
			of_log(@"Invalid line: %@\n", line);
			[OFApplication terminateWithStatus: 1];
		}
		splitObjects = [split objects];





		codep = (of_unichar_t)[splitObjects[0] hexadecimalValue];
		_uppercaseTable[codep] =
		    (of_unichar_t)[splitObjects[12] hexadecimalValue];
		_lowercaseTable[codep] =
		    (of_unichar_t)[splitObjects[13] hexadecimalValue];
		_titlecaseTable[codep] =
		    (of_unichar_t)[splitObjects[14] hexadecimalValue];

		objc_autoreleasePoolPop(pool2);
	}

	[of_stdout writeLine: @" done"];

	objc_autoreleasePoolPop(pool);
}

- (void)parseCaseFolding
{
	void *pool = objc_autoreleasePoolPush();
	OFHTTPRequest *request;
	OFHTTPClient *client;
	OFHTTPResponse *response;
	OFString *line;

	[of_stdout writeString: @"Downloading and parsing CaseFolding.txt..."];

	request = [OFHTTPRequest requestWithURL:
	    [OFURL URLWithString: CASE_FOLDING_URL]];
	client = [OFHTTPClient client];
	response = [client performRequest: request];

	while ((line = [response readLine]) != nil) {
		void *pool2;
		OFArray OF_GENERIC(OFString *) *split;
		OFString *const *splitObjects;
		of_unichar_t codep;

		if ([line length] == 0 || [line hasPrefix: @"#"])
			continue;

		pool2 = objc_autoreleasePoolPush();

		split = [line componentsSeparatedByString: @"; "];
		if ([split count] != 4) {
			of_log(@"Invalid line: %s\n", line);
			[OFApplication terminateWithStatus: 1];
		}
		splitObjects = [split objects];

		if (![splitObjects[1] isEqual: @"S"] &&
		    ![splitObjects[1] isEqual: @"C"])
			continue;

		codep = (of_unichar_t)[splitObjects[0] hexadecimalValue];





		_casefoldingTable[codep] =
		    (of_unichar_t)[splitObjects[2] hexadecimalValue];

		objc_autoreleasePoolPop(pool2);
	}

	[of_stdout writeLine: @" done"];

	objc_autoreleasePoolPop(pool);







|








|
<
|






|
|



|
>
>

>
>
|
|
|
|
|
|
|

















|








|
<
|






|
|



<

|
|


|
>
>
>
>
>
|
|







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
{
	void *pool = objc_autoreleasePoolPush();
	OFHTTPRequest *request;
	OFHTTPClient *client;
	OFHTTPResponse *response;
	OFString *line;

	[of_stdout writeString: @"Downloading and parsing UnicodeData.txt"];

	request = [OFHTTPRequest requestWithURL:
	    [OFURL URLWithString: UNICODE_DATA_URL]];
	client = [OFHTTPClient client];
	response = [client performRequest: request];

	while ((line = [response readLine]) != nil) {
		void *pool2;
		OFArray OF_GENERIC(OFString *) *components;

		of_unichar_t codePoint;

		if ([line length] == 0)
			continue;

		pool2 = objc_autoreleasePoolPush();

		components = [line componentsSeparatedByString: @";"];
		if ([components count] != 15) {
			of_log(@"Invalid line: %@\n", line);
			[OFApplication terminateWithStatus: 1];
		}

		codePoint = (of_unichar_t)
		    [[components objectAtIndex: 0] hexadecimalValue];

		if (codePoint > 0x10FFFF)
			@throw [OFOutOfRangeException exception];

		_uppercaseTable[codePoint] = (of_unichar_t)
		    [[components objectAtIndex: 12] hexadecimalValue];
		_lowercaseTable[codePoint] = (of_unichar_t)
		    [[components objectAtIndex: 13] hexadecimalValue];
		_titlecaseTable[codePoint] = (of_unichar_t)
		    [[components objectAtIndex: 14] hexadecimalValue];

		objc_autoreleasePoolPop(pool2);
	}

	[of_stdout writeLine: @" done"];

	objc_autoreleasePoolPop(pool);
}

- (void)parseCaseFolding
{
	void *pool = objc_autoreleasePoolPush();
	OFHTTPRequest *request;
	OFHTTPClient *client;
	OFHTTPResponse *response;
	OFString *line;

	[of_stdout writeString: @"Downloading and parsing CaseFolding.txt"];

	request = [OFHTTPRequest requestWithURL:
	    [OFURL URLWithString: CASE_FOLDING_URL]];
	client = [OFHTTPClient client];
	response = [client performRequest: request];

	while ((line = [response readLine]) != nil) {
		void *pool2;
		OFArray OF_GENERIC(OFString *) *components;

		of_unichar_t codePoint;

		if ([line length] == 0 || [line hasPrefix: @"#"])
			continue;

		pool2 = objc_autoreleasePoolPush();

		components = [line componentsSeparatedByString: @"; "];
		if ([components count] != 4) {
			of_log(@"Invalid line: %s\n", line);
			[OFApplication terminateWithStatus: 1];
		}


		if (![[components objectAtIndex: 1] isEqual: @"S"] &&
		    ![[components objectAtIndex: 1] isEqual: @"C"])
			continue;

		codePoint = (of_unichar_t)
		    [[components objectAtIndex: 0] hexadecimalValue];

		if (codePoint > 0x10FFFF)
			@throw [OFOutOfRangeException exception];

		_casefoldingTable[codePoint] = (of_unichar_t)
		    [[components objectAtIndex: 2] hexadecimalValue];

		objc_autoreleasePoolPop(pool2);
	}

	[of_stdout writeLine: @" done"];

	objc_autoreleasePoolPop(pool);