Overview
Comment: | Adjust TableGenerator to (not so) recent style changes. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
30cdebfa2af158e6d3036caa82879094 |
User & Date: | js on 2011-07-08 21:26:44 |
Other Links: | manifest | tags |
Context
2011-07-09
| ||
00:00 | Check for more invalid UTF-8 byte sequences. check-in: 51dff30395 user: js tags: trunk | |
2011-07-08
| ||
21:26 | Adjust TableGenerator to (not so) recent style changes. check-in: 30cdebfa2a user: js tags: trunk | |
21:08 | Optimize +[stringWithString:] and -[appendString:]. check-in: e250800382 user: js tags: trunk | |
Changes
Modified generators/TableGenerator.h from [a726909762] to [8e63730820].
︙ | ︙ | |||
27 28 29 30 31 32 33 | size_t upperTableSize; size_t lowerTableSize; size_t casefoldingTableSize; } - (void)readUnicodeDataFileAtPath: (OFString*)path; - (void)readCaseFoldingFileAtPath: (OFString*)path; | | | | 27 28 29 30 31 32 33 34 35 36 | size_t upperTableSize; size_t lowerTableSize; size_t casefoldingTableSize; } - (void)readUnicodeDataFileAtPath: (OFString*)path; - (void)readCaseFoldingFileAtPath: (OFString*)path; - (void)writeTablesToFileAtPath: (OFString*)path; - (void)writeHeaderToFileAtPath: (OFString*)path; @end |
Modified generators/TableGenerator.m from [cd373de6ed] to [24b546a549].
︙ | ︙ | |||
39 40 41 42 43 44 45 | casefoldingTableSize = SIZE_MAX; return self; } - (void)applicationDidFinishLaunching { | | | | | | | | < | | | | | | < | | | | | | | | | < < | | | | | | < < | | | | | | < < | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 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 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 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 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 | casefoldingTableSize = SIZE_MAX; return self; } - (void)applicationDidFinishLaunching { TableGenerator *generator = [[[TableGenerator alloc] init] autorelease]; [generator readUnicodeDataFileAtPath: @"UnicodeData.txt"]; [generator readCaseFoldingFileAtPath: @"CaseFolding.txt"]; [generator writeTablesToFileAtPath: @"../src/unicode.m"]; [generator writeHeaderToFileAtPath: @"../src/unicode.h"]; } - (void)readUnicodeDataFileAtPath: (OFString*)path { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init], *pool2; OFFile *file = [OFFile fileWithPath: path mode: @"rb"]; OFString *line; pool2 = [[OFAutoreleasePool alloc] init]; while ((line = [file readLine])) { OFArray *splitted; OFString **splittedCArray; of_unichar_t codep; splitted = [line componentsSeparatedByString: @";"]; if ([splitted count] != 15) { of_log(@"Invalid line: %@\n", line); [OFApplication terminateWithStatus: 1]; } splittedCArray = [splitted cArray]; codep = (of_unichar_t)[splittedCArray[0] hexadecimalValue]; upperTable[codep] = (of_unichar_t)[splittedCArray[12] hexadecimalValue]; lowerTable[codep] = (of_unichar_t)[splittedCArray[13] hexadecimalValue]; [pool2 releaseObjects]; } [pool release]; } - (void)readCaseFoldingFileAtPath: (OFString*)path { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init], *pool2; OFFile *file = [OFFile fileWithPath: path mode: @"rb"]; OFString *line; pool2 = [[OFAutoreleasePool alloc] init]; while ((line = [file readLine])) { OFArray *splitted; OFString **splittedCArray; of_unichar_t codep; if ([line characterAtIndex: 0] == '#') continue; splitted = [line componentsSeparatedByString: @"; "]; if ([splitted count] != 4) { of_log(@"Invalid line: %s\n", line); [OFApplication terminateWithStatus: 1]; } splittedCArray = [splitted cArray]; if (![splittedCArray[1] isEqual: @"S"] && ![splittedCArray[1] isEqual: @"C"]) continue; codep = (of_unichar_t)[splittedCArray[0] hexadecimalValue]; casefoldingTable[codep] = (of_unichar_t)[splittedCArray[2] hexadecimalValue]; [pool2 releaseObjects]; } [pool release]; } - (void)writeTablesToFileAtPath: (OFString*)path { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init], *pool2; of_unichar_t i, j; OFFile *file = [OFFile fileWithPath: path mode: @"wb"]; [file writeString: COPYRIGHT @"#include \"config.h\"\n" @"\n" @"#import \"OFString.h\"\n\n" @"static const of_unichar_t nop_page[0x100] = {};\n\n"]; pool2 = [[OFAutoreleasePool alloc] init]; /* Write upper_page_%u */ for (i = 0; i < 0x110000; i += 0x100) { BOOL isEmpty = YES; for (j = i; j < i + 0x100; j++) { if (upperTable[j] != 0) { isEmpty = NO; upperTableSize = i >> 8; upperTableUsed[upperTableSize] = YES; break; } } if (!isEmpty) { [file writeString: [OFString stringWithFormat: @"static const of_unichar_t upper_page_%u[0x100] = " @"{\n", i >> 8]]; for (j = i; j < i + 0x100; j += 8) [file writeString: [OFString stringWithFormat: @"\t%u, %u, %u, %u, %u, %u, %u, %u,\n", upperTable[j], upperTable[j + 1], upperTable[j + 2], upperTable[j + 3], upperTable[j + 4], upperTable[j + 5], upperTable[j + 6], upperTable[j + 7]]]; [file writeString: @"};\n\n"]; [pool2 releaseObjects]; } } /* Write lower_page_%u */ for (i = 0; i < 0x110000; i += 0x100) { BOOL isEmpty = YES; for (j = i; j < i + 0x100; j++) { if (lowerTable[j] != 0) { isEmpty = NO; lowerTableSize = i >> 8; lowerTableUsed[lowerTableSize] = YES; break; } } if (!isEmpty) { [file writeString: [OFString stringWithFormat: @"static const of_unichar_t lower_page_%u[0x100] = " @"{\n", i >> 8]]; for (j = i; j < i + 0x100; j += 8) [file writeString: [OFString stringWithFormat: @"\t%u, %u, %u, %u, %u, %u, %u, %u,\n", lowerTable[j], lowerTable[j + 1], lowerTable[j + 2], lowerTable[j + 3], lowerTable[j + 4], lowerTable[j + 5], lowerTable[j + 6], lowerTable[j + 7]]]; [file writeString: @"};\n\n"]; [pool2 releaseObjects]; } } /* Write cf_page_%u if it does NOT match lower_page_%u */ for (i = 0; i < 0x110000; i += 0x100) { BOOL isEmpty = YES; for (j = i; j < i + 0x100; j++) { if (casefoldingTable[j] != 0) { isEmpty = (memcmp(lowerTable + i, casefoldingTable + i, 256 * sizeof(of_unichar_t)) ? NO : YES); casefoldingTableSize = i >> 8; casefoldingTableUsed[casefoldingTableSize] = (isEmpty ? 2 : 1); break; } } if (!isEmpty) { [file writeString: [OFString stringWithFormat: @"static const of_unichar_t cf_page_%u[0x100] = {" @"\n", i >> 8]]; for (j = i; j < i + 0x100; j += 8) [file writeString: [OFString stringWithFormat: @"\t%u, %u, %u, %u, %u, %u, %u, %u,\n", casefoldingTable[j], casefoldingTable[j + 1], casefoldingTable[j + 2], casefoldingTable[j + 3], casefoldingTable[j + 4], casefoldingTable[j + 5], casefoldingTable[j + 6], casefoldingTable[j + 7]]]; [file writeString: @"};\n\n"]; [pool2 releaseObjects]; } } /* * Those are currently set to the last index. * But from now on, we need the size. */ upperTableSize++; lowerTableSize++; casefoldingTableSize++; /* Write of_unicode_upper_table */ [file writeString: [OFString stringWithFormat: @"const of_unichar_t* const of_unicode_upper_table[0x%X] = {\n\t", upperTableSize]]; for (i = 0; i < upperTableSize; i++) { if (upperTableUsed[i]) { [file writeString: [OFString stringWithFormat: @"upper_page_%u", i]]; [pool2 releaseObjects]; } else [file writeString: @"nop_page"]; if (i + 1 < upperTableSize) { if ((i + 1) % 4 == 0) [file writeString: @",\n\t"]; else [file writeString: @", "]; } } [file writeString: @"\n};\n\n"]; /* Write of_unicode_lower_table */ [file writeString: [OFString stringWithFormat: @"const of_unichar_t* const of_unicode_lower_table[0x%X] = {\n\t", lowerTableSize]]; for (i = 0; i < lowerTableSize; i++) { if (lowerTableUsed[i]) { [file writeString: [OFString stringWithFormat: @"lower_page_%u", i]]; [pool2 releaseObjects]; } else [file writeString: @"nop_page"]; if (i + 1 < lowerTableSize) { if ((i + 1) % 4 == 0) [file writeString: @",\n\t"]; else [file writeString: @", "]; } } [file writeString: @"\n};\n\n"]; /* Write of_unicode_casefolding_table */ [file writeString: [OFString stringWithFormat: @"const of_unichar_t* const of_unicode_casefolding_table[0x%X] = {" @"\n\t", casefoldingTableSize]]; for (i = 0; i < casefoldingTableSize; i++) { if (casefoldingTableUsed[i] == 1) { [file writeString: [OFString stringWithFormat: @"cf_page_%u", i]]; [pool2 releaseObjects]; } else if (casefoldingTableUsed[i] == 2) { [file writeString: [OFString stringWithFormat: @"lower_page_%u", i]]; } else [file writeString: @"nop_page"]; if (i + 1 < casefoldingTableSize) { if ((i + 1) % 4 == 0) [file writeString: @",\n\t"]; else [file writeString: @", "]; } } [file writeString: @"\n};\n"]; [pool release]; } - (void)writeHeaderToFileAtPath: (OFString*)path { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFFile *file = [OFFile fileWithPath: path mode: @"wb"]; [file writeString: COPYRIGHT @"#import \"OFString.h\"\n\n"]; [file writeString: [OFString stringWithFormat: @"#define OF_UNICODE_UPPER_TABLE_SIZE 0x%X\n" @"#define OF_UNICODE_LOWER_TABLE_SIZE 0x%X\n" @"#define OF_UNICODE_CASEFOLDING_TABLE_SIZE 0x%X\n\n", upperTableSize, lowerTableSize, casefoldingTableSize]]; [file writeString: @"#ifdef __cplusplus\n" @"extern \"C\" {\n" @"#endif\n" @"extern const of_unichar_t* const\n" @" of_unicode_upper_table[OF_UNICODE_UPPER_TABLE_SIZE];\n" @"extern const of_unichar_t* const\n" @" of_unicode_lower_table[OF_UNICODE_LOWER_TABLE_SIZE];\n" |
︙ | ︙ |