Overview
Comment: | Fix splitWithDelimiter:. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
cabf6ee9e7bb095caab247a66f0124c5 |
User & Date: | js on 2009-05-23 20:32:23 |
Other Links: | manifest | tags |
Context
2009-05-23
| ||
21:02 | Add replaceOccurrencesOfString:withString: to OFString. check-in: bc71bde0dd user: js tags: trunk | |
20:32 | Fix splitWithDelimiter:. check-in: cabf6ee9e7 user: js tags: trunk | |
16:50 | A few renames in OFArray, OFDataArray and OFDictionary. check-in: a29d403286 user: js tags: trunk | |
Changes
Modified src/OFString.m from [cff3100081] to [4a9dfef866].
︙ | ︙ | |||
332 333 334 335 336 337 338 339 340 341 342 343 344 | andSelector: _cmd]; } - (OFArray*)splitWithDelimiter: (OFString*)delimiter { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFArray *array = nil; const char *delim = [delimiter cString]; size_t delim_len = [delimiter length]; size_t i, last; array = [OFMutableArray array]; | > > > | > > > > > | > > | > > | > | > > > | | | | | | < | | | | | | | | | | | | | | < > | 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 | andSelector: _cmd]; } - (OFArray*)splitWithDelimiter: (OFString*)delimiter { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFArray *array = nil; OFString *str; const char *delim = [delimiter cString]; size_t delim_len = [delimiter length]; size_t i, last; array = [OFMutableArray array]; if (delim_len > length) { str = [self copy]; @try { [array add: str]; } @finally { [str release]; } [array retain]; [pool release]; return array; } for (i = 0, last = 0; i <= length - delim_len; i++) { char *tmp; if (memcmp(string + i, delim, delim_len)) continue; /* * We can't use [self allocWithSize:] here as self might be a * @""-literal. */ if ((tmp = malloc(i - last + 1)) == NULL) @throw [OFNoMemException newWithClass: isa andSize: i - last + 1]; memcpy(tmp, string + last, i - last); tmp[i - last] = '\0'; @try { str = [OFString stringWithCString: tmp]; } @finally { free(tmp); } [array add: str]; [array retain]; [pool releaseObjects]; i += delim_len - 1; last = i + 1; } [array add: [OFString stringWithCString: string + last]]; [array retain]; [pool release]; return array; } @end |