Overview
Comment: | Add -[OFMutableString replaceCharactersFromIndex:toIndex:withString:]. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
3f14a43fbf275ca2b6011697aea67418 |
User & Date: | js on 2010-10-24 22:12:04 |
Other Links: | manifest | tags |
Context
2010-10-24
| ||
22:32 | Add -[OFMutableString insertString:atIndex:]. check-in: e9db0f7013 user: js tags: trunk | |
22:12 | Add -[OFMutableString replaceCharactersFromIndex:toIndex:withString:]. check-in: 3f14a43fbf user: js tags: trunk | |
13:31 | Hide an internal protocol from Doxygen. check-in: eb7788d3de user: js tags: trunk | |
Changes
Modified src/OFMutableString.h from [98b6def095] to [c820e5e0d0].
︙ | ︙ | |||
118 119 120 121 122 123 124 125 126 127 128 129 130 131 | /** * Removes the characters at the specified range. * * \param range The range of the characters which should be removed */ - (void)removeCharactersInRange: (of_range_t)range; /** * Replaces all occurrences of a string with another string. * * \param str The string to replace * \param repl The string with which it should be replaced */ - (void)replaceOccurrencesOfString: (OFString*)str | > > > > > > > > > > > > > > > > > > > > > | 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 | /** * Removes the characters at the specified range. * * \param range The range of the characters which should be removed */ - (void)removeCharactersInRange: (of_range_t)range; /** * Removes the characters at the specified range. * * \param start The index where the replacement should be started * \param end The index until which the characters should be replaced. * This points BEHIND the last character! * \param repl The string to the replace the characters with */ - (void)replaceCharactersFromIndex: (size_t)start toIndex: (size_t)end withString: (OFString*)repl; /** * Removes the characters at the specified range. * * \param range The range of the characters which should be replaced * \param repl The string to the replace the characters with */ - (void)replaceCharactersInRange: (of_range_t)range withString: (OFString*)repl; /** * Replaces all occurrences of a string with another string. * * \param str The string to replace * \param repl The string with which it should be replaced */ - (void)replaceOccurrencesOfString: (OFString*)str |
︙ | ︙ |
Modified src/OFMutableString.m from [920953956a] to [4f2f2b15be].
︙ | ︙ | |||
383 384 385 386 387 388 389 390 391 392 393 394 395 396 | } - (void)removeCharactersInRange: (of_range_t)range { [self removeCharactersFromIndex: range.start toIndex: range.start + range.length]; } - (void)replaceOccurrencesOfString: (OFString*)str withString: (OFString*)repl { const char *str_c = [str cString]; const char *repl_c = [repl cString]; size_t str_len = [str cStringLength]; | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 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 | } - (void)removeCharactersInRange: (of_range_t)range { [self removeCharactersFromIndex: range.start toIndex: range.start + range.length]; } - (void)replaceCharactersFromIndex: (size_t)start toIndex: (size_t)end withString: (OFString*)repl { size_t nlen; if (isUTF8) { start = of_string_index_to_position(string, start, length); end = of_string_index_to_position(string, end, length); } if (start > end) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; if (end > length) @throw [OFOutOfRangeException newWithClass: isa]; nlen = length - (end - start) + [repl cStringLength]; string = [self resizeMemory: string toSize: nlen + 1]; memmove(string + end, string + start + [repl cStringLength], length - end); memcpy(string + start, [repl cString], [repl cStringLength]); string[nlen] = '\0'; length = nlen; } - (void)replaceCharactersInRange: (of_range_t)range withString: (OFString*)repl { [self replaceCharactersFromIndex: range.start toIndex: range.start + range.length withString: repl]; } - (void)replaceOccurrencesOfString: (OFString*)str withString: (OFString*)repl { const char *str_c = [str cString]; const char *repl_c = [repl cString]; size_t str_len = [str cStringLength]; |
︙ | ︙ |
Modified tests/OFStringTests.m from [4069c78118] to [1aeb17e075].
︙ | ︙ | |||
285 286 287 288 289 290 291 292 293 294 295 296 297 298 | (s[0] = [OFMutableString stringWithString: @"πΓΆΓΆΓΆbΓ€β¬"]) && R([s[0] removeCharactersFromIndex: 1 toIndex: 4]) && [s[0] isEqual: @"πbΓ€β¬"] && R([s[0] removeCharactersFromIndex: 0 toIndex: 4]) && [s[0] isEqual: @""]) EXPECT_EXCEPTION(@"Detect OoR in " @"-[removeCharactersFromIndex:toIndex:] #1", OFOutOfRangeException, { s[0] = [OFMutableString stringWithString: @"πΓΆΓΆ"]; [s[0] substringFromIndex: 2 toIndex: 4]; | > > > > > > > > > > > | 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 | (s[0] = [OFMutableString stringWithString: @"πΓΆΓΆΓΆbΓ€β¬"]) && R([s[0] removeCharactersFromIndex: 1 toIndex: 4]) && [s[0] isEqual: @"πbΓ€β¬"] && R([s[0] removeCharactersFromIndex: 0 toIndex: 4]) && [s[0] isEqual: @""]) TEST(@"-[replaceCharactersFromIndex:toIndex:withString:]", (s[0] = [OFMutableString stringWithString: @"πΓΆΓΆΓΆbΓ€β¬"]) && R([s[0] replaceCharactersFromIndex: 1 toIndex: 4 withString: @"Àâü"]) && [s[0] isEqual: @"πÀâübΓ€β¬"] && R([s[0] replaceCharactersFromIndex: 0 toIndex: 7 withString: @""]) && [s[0] isEqual: @""]) EXPECT_EXCEPTION(@"Detect OoR in " @"-[removeCharactersFromIndex:toIndex:] #1", OFOutOfRangeException, { s[0] = [OFMutableString stringWithString: @"πΓΆΓΆ"]; [s[0] substringFromIndex: 2 toIndex: 4]; |
︙ | ︙ |