Overview
Comment: | Optimize some code by using the new stringWithCString:andLength: method. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
7bb3494ef9f039631ef9e85c6de21050 |
User & Date: | js on 2009-07-14 17:51:02 |
Other Links: | manifest | tags |
Context
2009-07-14
| ||
18:57 | Add OFString (OFXMLUnescaping) category and API for OFXMLParser. check-in: d8684fc232 user: js tags: trunk | |
17:51 | Optimize some code by using the new stringWithCString:andLength: method. check-in: 7bb3494ef9 user: js tags: trunk | |
17:32 | Add methods to handle C strings with length to OF(Mutable)String. check-in: dc7bb2d594 user: js tags: trunk | |
Changes
Modified src/OFString.m from [36e450e8e9] to [b0bbce5a9e].
︙ | ︙ | |||
399 400 401 402 403 404 405 | return SIZE_MAX; } } - (OFString*)substringFromIndex: (size_t)start toIndex: (size_t)end { | < < < < < < < < < < < < < < < | < < < | < | < < | < < < < < < < < < < < < < < < < < < | < | | 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 | return SIZE_MAX; } } - (OFString*)substringFromIndex: (size_t)start toIndex: (size_t)end { if (start > end) @throw [OFInvalidArgumentException newWithClass: isa andSelector: _cmd]; if (end > length) @throw [OFOutOfRangeException newWithClass: isa]; return [OFString stringWithCString: string + start andLength: end - start]; } - (OFArray*)splitWithDelimiter: (OFString*)delimiter { OFAutoreleasePool *pool; OFArray *array; const char *delim = [delimiter cString]; size_t delim_len = [delimiter length]; size_t i, last; array = [OFMutableArray array]; pool = [[OFAutoreleasePool alloc] init]; if (delim_len > length) { [array addObject: [[self copy] autorelease]]; [pool release]; return array; } for (i = 0, last = 0; i <= length - delim_len; i++) { if (memcmp(string + i, delim, delim_len)) continue; [array addObject: [OFString stringWithCString: string + last andLength: i - last]]; i += delim_len - 1; last = i + 1; } [array addObject: [OFString stringWithCString: string + last]]; [pool release]; |
︙ | ︙ |
Modified tests/OFString/OFString.m from [2fcb062a9a] to [b1315ec8f9].
︙ | ︙ | |||
20 21 22 23 24 25 26 | #ifndef _WIN32 #define ZD "%zd" #else #define ZD "%u" #endif | | | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #ifndef _WIN32 #define ZD "%zd" #else #define ZD "%u" #endif #define NUM_TESTS 49 #define SUCCESS \ printf("\r\033[1;%dmTests successful: " ZD "/%d\033[0m", \ (i == NUM_TESTS - 1 ? 32 : 33), i + 1, NUM_TESTS); \ fflush(stdout); #define FAIL \ printf("\r\033[K\033[1;31mTest " ZD "/%d failed!\033[m\n", \ i + 1, NUM_TESTS); \ |
︙ | ︙ |