Overview
Comment: | Rename -[length] to -[cStringLength] in OFString. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
3ed599fe9834f58c14a785d8db3773a9 |
User & Date: | js on 2009-09-01 11:32:30 |
Other Links: | manifest | tags |
Context
2009-09-01
| ||
11:39 | Use OFMutableString in OFPlugin instead of doing it manually. check-in: cdfdea289e user: js tags: trunk | |
11:32 | Rename -[length] to -[cStringLength] in OFString. check-in: 3ed599fe98 user: js tags: trunk | |
2009-08-31
| ||
00:19 | Optimize OF_BSWAP64. check-in: 2ff4ae177d user: js tags: trunk | |
Changes
Modified src/OFMutableString.m from [c9b26460ed] to [c3c573eb68].
︙ | ︙ | |||
318 319 320 321 322 323 324 | } - replaceOccurrencesOfString: (OFString*)str withString: (OFString*)repl { const char *str_c = [str cString]; const char *repl_c = [repl cString]; | | | | 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | } - replaceOccurrencesOfString: (OFString*)str withString: (OFString*)repl { const char *str_c = [str cString]; const char *repl_c = [repl cString]; size_t str_len = [str cStringLength]; size_t repl_len = [repl cStringLength]; size_t i, last, tmp_len; char *tmp; if (str_len > length) return self; tmp = NULL; |
︙ | ︙ |
Modified src/OFPlugin.m from [773d6d11cf] to [e2e99b5635].
︙ | ︙ | |||
23 24 25 26 27 28 29 | { char *file; size_t pathlen, suffixlen; void *handle; OFPlugin *(*init_plugin)(); OFPlugin *plugin; | | | 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | { char *file; size_t pathlen, suffixlen; void *handle; OFPlugin *(*init_plugin)(); OFPlugin *plugin; pathlen = [path cStringLength]; suffixlen = strlen(PLUGIN_SUFFIX); if ((file = malloc(pathlen + suffixlen + 1)) == NULL) { @throw [OFOutOfMemoryException newWithClass: self size: pathlen + suffixlen + 1]; } |
︙ | ︙ |
Modified src/OFStream.m from [4d39d4c3d2] to [ca6dc099de].
︙ | ︙ | |||
201 202 203 204 205 206 207 | { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } - (size_t)writeString: (OFString*)str { | | | 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } - (size_t)writeString: (OFString*)str { return [self writeNBytes: [str cStringLength] fromBuffer: [str cString]]; } - (size_t)getCache: (char**)ptr { if (ptr != NULL) *ptr = cache; |
︙ | ︙ |
Modified src/OFString.h from [4c61fdeaf5] to [db05d342fe].
︙ | ︙ | |||
67 68 69 70 71 72 73 | /** * Creates a new OFString from a C string with the specified encoding and * length. * * \param str A C string to initialize the OFString with * \param encoding The encoding of the C string | | | | 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 | /** * Creates a new OFString from a C string with the specified encoding and * length. * * \param str A C string to initialize the OFString with * \param encoding The encoding of the C string * \param len The length of the C string * \return A new autoreleased OFString */ + stringWithCString: (const char*)str encoding: (enum of_string_encoding)encoding length: (size_t)len; /** * Creates a new OFString from a UTF-8 encoded C string with the specified * length. * * \param str A UTF-8 encoded C string to initialize the OFString with * \param len The length of the UTF-8 encoded C string * \return A new autoreleased OFString */ + stringWithCString: (const char*)str length: (size_t)len; /** * Creates a new OFString from a format string. |
︙ | ︙ | |||
134 135 136 137 138 139 140 | /** * Initializes an already allocated OFString from a C string with the specified * encoding and length. * * \param str A C string to initialize the OFString with * \param encoding The encoding of the C string | | | | 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 | /** * Initializes an already allocated OFString from a C string with the specified * encoding and length. * * \param str A C string to initialize the OFString with * \param encoding The encoding of the C string * \param len The length of the C string * \return An initialized OFString */ - initWithCString: (const char*)str encoding: (enum of_string_encoding)encoding length: (size_t)len; /** * Initializes an already allocated OFString from a UTF-8 encoded C string with * the specified length. * * \param str A UTF-8 encoded C string to initialize the OFString with * \param len The length of the UTF-8 encoded C string * \return An initialized OFString */ - initWithCString: (const char*)str length: (size_t)len; /** * Initializes an already allocated OFString with a format string. |
︙ | ︙ | |||
186 187 188 189 190 191 192 | /** * \return The OFString as a UTF-8 encoded C string */ - (const char*)cString; /** | | | | 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | /** * \return The OFString as a UTF-8 encoded C string */ - (const char*)cString; /** * \return The length of the string which cString would return */ - (size_t)cStringLength; /** * Compares the OFString to another object. * * \param obj An object to compare with * \return An integer which is the result of the comparison, see for example * strcmp |
︙ | ︙ |
Modified src/OFString.m from [99eed6fe4d] to [e5d0b3d2f0].
︙ | ︙ | |||
433 434 435 436 437 438 439 | } - initWithString: (OFString*)str { self = [super init]; string = strdup([str cString]); | | | 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 | } - initWithString: (OFString*)str { self = [super init]; string = strdup([str cString]); length = [str cStringLength]; @try { [self addMemoryToPool: string]; } @catch (OFException *e) { /* * We can't use [super dealloc] on OS X here. * Compiler bug? Anyway, [self dealloc] will do here as we |
︙ | ︙ | |||
456 457 458 459 460 461 462 | } - (const char*)cString { return string; } | | | 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 | } - (const char*)cString { return string; } - (size_t)cStringLength { return length; } - (BOOL)isEqual: (id)obj { if (![obj isKindOfClass: [OFString class]]) |
︙ | ︙ | |||
506 507 508 509 510 511 512 | return hash; } - (size_t)indexOfFirstOccurrenceOfString: (OFString*)str { const char *str_c = [str cString]; | | | | 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 | return hash; } - (size_t)indexOfFirstOccurrenceOfString: (OFString*)str { const char *str_c = [str cString]; size_t str_len = [str cStringLength]; size_t i; if (str_len == 0) return 0; if (str_len > length) return SIZE_MAX; for (i = 0; i <= length - str_len; i++) if (!memcmp(string + i, str_c, str_len)) return i; return SIZE_MAX; } - (size_t)indexOfLastOccurrenceOfString: (OFString*)str { const char *str_c = [str cString]; size_t str_len = [str cStringLength]; size_t i; if (str_len == 0) return length; if (str_len > length) return SIZE_MAX; |
︙ | ︙ | |||
565 566 567 568 569 570 571 | - (OFString*)stringByAppendingString: (OFString*)str { return [[OFMutableString stringWithString: self] appendString: str]; } - (BOOL)hasPrefix: (OFString*)prefix { | | | | | 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 | - (OFString*)stringByAppendingString: (OFString*)str { return [[OFMutableString stringWithString: self] appendString: str]; } - (BOOL)hasPrefix: (OFString*)prefix { size_t len = [prefix cStringLength]; if (len > length) return NO; return (memcmp(string, [prefix cString], len) ? NO : YES); } - (BOOL)hasSuffix: (OFString*)suffix { size_t len = [suffix cStringLength]; if (len > length) return NO; return (memcmp(string + (length - len), [suffix cString], len) ? NO : YES); } - (OFArray*)splitWithDelimiter: (OFString*)delimiter { OFAutoreleasePool *pool; OFArray *array; const char *delim = [delimiter cString]; size_t delim_len = [delimiter cStringLength]; size_t i, last; array = [OFMutableArray array]; pool = [[OFAutoreleasePool alloc] init]; if (delim_len > length) { [array addObject: [[self copy] autorelease]]; |
︙ | ︙ |
Modified src/OFXMLElement.m from [cf929b13b9] to [5595432660].
︙ | ︙ | |||
122 123 124 125 126 127 128 | { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; char *str_c; size_t len, i, j, attrs_count; OFXMLAttribute **attrs_data; OFString *ret, *tmp; | | | | | | | | | | 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 | { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; char *str_c; size_t len, i, j, attrs_count; OFXMLAttribute **attrs_data; OFString *ret, *tmp; len = [name cStringLength] + 4; str_c = [self allocMemoryWithSize: len]; /* Start of tag */ *str_c = '<'; memcpy(str_c + 1, [name cString], [name cStringLength]); i = [name cStringLength] + 1; /* Attributes */ attrs_data = [attrs data]; attrs_count = [attrs count]; for (j = 0; j < attrs_count; j++) { /* FIXME: Add namespace support */ OFString *attr_name = [attrs_data[j] name]; tmp = [[attrs_data[j] stringValue] stringByXMLEscaping]; len += [attr_name cStringLength] + [tmp cStringLength] + 4; @try { str_c = [self resizeMemory: str_c toSize: len]; } @catch (OFException *e) { [self freeMemory: str_c]; @throw e; } str_c[i++] = ' '; memcpy(str_c + i, [attr_name cString], [attr_name cStringLength]); i += [attr_name cStringLength]; str_c[i++] = '='; str_c[i++] = '\''; memcpy(str_c + i, [tmp cString], [tmp cStringLength]); i += [tmp cStringLength]; str_c[i++] = '\''; [pool releaseObjects]; } /* Childen */ if (stringval != nil || children != nil) { |
︙ | ︙ | |||
180 181 182 183 184 185 186 | for (j = 0; j < count; j++) append(tmp, @selector( appendCStringWithoutUTF8Checking:), [[data[j] string] cString]); } | | | | | | | 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 | for (j = 0; j < count; j++) append(tmp, @selector( appendCStringWithoutUTF8Checking:), [[data[j] string] cString]); } len += [tmp cStringLength] + [name cStringLength] + 2; @try { str_c = [self resizeMemory: str_c toSize: len]; } @catch (OFException *e) { [self freeMemory: str_c]; @throw e; } str_c[i++] = '>'; memcpy(str_c + i, [tmp cString], [tmp cStringLength]); i += [tmp cStringLength]; str_c[i++] = '<'; str_c[i++] = '/'; memcpy(str_c + i, [name cString], [name cStringLength]); i += [name cStringLength]; } else str_c[i++] = '/'; str_c[i++] = '>'; str_c[i++] = '\0'; assert(i == len); |
︙ | ︙ |
Modified src/OFXMLParser.m from [7614e5646f] to [c146e3c2d9].
︙ | ︙ | |||
143 144 145 146 147 148 149 | if (buf[i] == '<') { len = i - last; if (len > 0) [cache appendCString: buf + last withLength: len]; | | | 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | if (buf[i] == '<') { len = i - last; if (len > 0) [cache appendCString: buf + last withLength: len]; if ([cache cStringLength] > 0) { OFString *str; pool = [[OFAutoreleasePool alloc] init]; str = transform_string(cache, self); [delegate xmlParser: self foundString: str]; [pool release]; |
︙ | ︙ | |||
185 186 187 188 189 190 191 | size_t cache_len; len = i - last; if (len > 0) [cache appendCString: buf + last withLength: len]; cache_c = [cache cString]; | | | 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | size_t cache_len; len = i - last; if (len > 0) [cache appendCString: buf + last withLength: len]; cache_c = [cache cString]; cache_len = [cache cStringLength]; if ((tmp = memchr(cache_c, ':', cache_len)) != NULL) { name = [[OFString alloc] initWithCString: tmp + 1 length: cache_len - (tmp - cache_c) - 1]; |
︙ | ︙ | |||
247 248 249 250 251 252 253 | size_t cache_len; len = i - last; if (len > 0) [cache appendCString: buf + last withLength: len]; cache_c = [cache cString]; | | | 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | size_t cache_len; len = i - last; if (len > 0) [cache appendCString: buf + last withLength: len]; cache_c = [cache cString]; cache_len = [cache cStringLength]; if ((tmp = memchr(cache_c, ':', cache_len)) != NULL) { name = [[OFString alloc] initWithCString: tmp + 1 length: cache_len - (tmp - cache_c) - 1]; |
︙ | ︙ | |||
347 348 349 350 351 352 353 | len = i - last; if (len > 0) [cache appendCString: buf + last withLength: len]; cache_c = [cache cString]; | | | 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 | len = i - last; if (len > 0) [cache appendCString: buf + last withLength: len]; cache_c = [cache cString]; cache_len = [cache cStringLength]; if ((tmp = memchr(cache_c, ':', cache_len)) != NULL ) { attr_name = [[OFString alloc] initWithCString: tmp + 1 length: cache_len - (tmp - cache_c) - 1]; |
︙ | ︙ | |||
454 455 456 457 458 459 460 | break; case OF_XMLPARSER_IN_COMMENT_4: if (buf[i] == '-') { size_t cache_len; [cache appendCString: buf + last withLength: i - last]; | | | 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 | break; case OF_XMLPARSER_IN_COMMENT_4: if (buf[i] == '-') { size_t cache_len; [cache appendCString: buf + last withLength: i - last]; cache_len = [cache cStringLength]; pool = [[OFAutoreleasePool alloc] init]; [cache removeCharactersFromIndex: cache_len - 1 toIndex: cache_len]; [cache removeLeadingAndTrailingWhitespaces]; [delegate xmlParser: self foundComment: cache]; |
︙ | ︙ |
Modified tests/OFString/OFString.m from [9c8a9cddc0] to [9cf2bd2fe4].
︙ | ︙ | |||
84 85 86 87 88 89 90 | [s2 appendCString: "12"]; [s2 appendString: @"3"]; [s4 setToCString: [s2 cString]]; CHECK(![s2 compare: s4]) CHECK([[s1 appendString: s2] isEqual: @"test123"]) | | | 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | [s2 appendCString: "12"]; [s2 appendString: @"3"]; [s4 setToCString: [s2 cString]]; CHECK(![s2 compare: s4]) CHECK([[s1 appendString: s2] isEqual: @"test123"]) CHECK([s1 cStringLength] == 7) CHECK([s1 hash] == 0xC44F49A4) CHECK([[s1 reverse] isEqual: @"321tset"]) CHECK([[s1 upper] isEqual: @"321TSET"]) CHECK([[s1 lower] isEqual: @"321tset"]) /* Also clears all the memory of the returned C strings */ [pool release]; |
︙ | ︙ |