Overview
Comment: | Add -[OFMutableString appendCharacters:length:]. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
beb9051a10b54d9ec446ab2080adc40b |
User & Date: | js on 2013-01-11 12:13:38 |
Other Links: | manifest | tags |
Context
2013-01-11
| ||
12:41 | OFString: Improve API for characters / UTF-32. check-in: 50916b8dbe user: js tags: trunk | |
12:13 | Add -[OFMutableString appendCharacters:length:]. check-in: beb9051a10 user: js tags: trunk | |
2013-01-10
| ||
22:52 | Fix all Doxygen warnings. check-in: 365d74aa27 user: js tags: trunk | |
Changes
Modified src/OFMutableString.h from [0aaaa474f7] to [339f0e1d69].
︙ | ︙ | |||
25 26 27 28 29 30 31 32 33 34 35 36 37 38 | * * @param character The character to set * @param index The index where to set the character */ - (void)setCharacter: (of_unichar_t)character atIndex: (size_t)index; /*! * @brief Appends a UTF-8 encoded C string to the OFMutableString. * * @param UTF8String A UTF-8 encoded C string to append */ - (void)appendUTF8String: (const char*)UTF8String; | > > > > > > > > > > > > > > > > | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | * * @param character The character to set * @param index The index where to set the character */ - (void)setCharacter: (of_unichar_t)character atIndex: (size_t)index; /*! * @brief Appends another OFString to the OFMutableString. * * @param string An OFString to append */ - (void)appendString: (OFString*)string; /*! * @brief Appends the specified characters to the OFMutableString. * * @param characters An array of characters to append * @param length The length of the array of characters */ - (void)appendCharacters: (of_unichar_t*)characters length: (size_t)length; /*! * @brief Appends a UTF-8 encoded C string to the OFMutableString. * * @param UTF8String A UTF-8 encoded C string to append */ - (void)appendUTF8String: (const char*)UTF8String; |
︙ | ︙ | |||
63 64 65 66 67 68 69 | * @param encoding The encoding of the C string * @param cStringLength The length of the UTF-8 encoded C string */ - (void)appendCString: (const char*)cString encoding: (of_string_encoding_t)encoding length: (size_t)cStringLength; | < < < < < < < | 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | * @param encoding The encoding of the C string * @param cStringLength The length of the UTF-8 encoded C string */ - (void)appendCString: (const char*)cString encoding: (of_string_encoding_t)encoding length: (size_t)cStringLength; /*! * @brief Appends a formatted string to the OFMutableString. * * See printf for the format syntax. As an addition, %@ is available as format * specifier for objects. * * @param format A format string which generates the string to append |
︙ | ︙ |
Modified src/OFMutableString.m from [76c373f5c0] to [a7724d0cb6].
︙ | ︙ | |||
282 283 284 285 286 287 288 289 290 291 292 293 294 295 | length: 1]; [self replaceCharactersInRange: of_range(index, 1) withString: string]; objc_autoreleasePoolPop(pool); } - (void)appendUTF8String: (const char*)UTF8String { void *pool = objc_autoreleasePoolPush(); [self appendString: [OFString stringWithUTF8String: UTF8String]]; | > > > > > > > > > > > > > > > > > | 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 | length: 1]; [self replaceCharactersInRange: of_range(index, 1) withString: string]; objc_autoreleasePoolPop(pool); } - (void)appendString: (OFString*)string { return [self insertString: string atIndex: [self length]]; } - (void)appendCharacters: (of_unichar_t*)characters length: (size_t)length { void *pool = objc_autoreleasePoolPush(); return [self appendString: [OFString stringWithCharacters: characters length: length]]; objc_autoreleasePoolPop(pool); } - (void)appendUTF8String: (const char*)UTF8String { void *pool = objc_autoreleasePoolPush(); [self appendString: [OFString stringWithUTF8String: UTF8String]]; |
︙ | ︙ | |||
327 328 329 330 331 332 333 | [self appendString: [OFString stringWithCString: cString encoding: encoding length: cStringLength]]; objc_autoreleasePoolPop(pool); } | < < < < < < | 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | [self appendString: [OFString stringWithCString: cString encoding: encoding length: cStringLength]]; objc_autoreleasePoolPop(pool); } - (void)appendFormat: (OFConstantString*)format, ... { va_list arguments; va_start(arguments, format); [self appendFormat: format arguments: arguments]; |
︙ | ︙ |
Modified src/OFMutableString_UTF8.m from [95309d22f2] to [3edda5e667].
︙ | ︙ | |||
386 387 388 389 390 391 392 393 394 395 396 397 398 399 | if ([string isKindOfClass: [OFString_UTF8 class]] || [string isKindOfClass: [OFMutableString_UTF8 class]]) { if (((OFString_UTF8*)string)->s->isUTF8) s->isUTF8 = YES; } else s->isUTF8 = YES; } - (void)appendFormat: (OFConstantString*)format arguments: (va_list)arguments { char *UTF8String; int UTF8StringLength; | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 | if ([string isKindOfClass: [OFString_UTF8 class]] || [string isKindOfClass: [OFMutableString_UTF8 class]]) { if (((OFString_UTF8*)string)->s->isUTF8) s->isUTF8 = YES; } else s->isUTF8 = YES; } - (void)appendCharacters: (of_unichar_t*)characters length: (size_t)length { char *tmp; tmp = [self allocMemoryWithSize: (length * 4) + 1]; @try { size_t i, j = 0; BOOL isUTF8 = NO; for (i = 0; i < length; i++) { char buffer[4]; switch (of_string_utf8_encode(characters[i], buffer)) { case 1: tmp[j++] = buffer[0]; break; case 2: isUTF8 = YES; memcpy(tmp + j, buffer, 2); j += 2; break; case 3: isUTF8 = YES; memcpy(tmp + j, buffer, 3); j += 3; break; case 4: isUTF8 = YES; memcpy(tmp + j, buffer, 4); j += 4; break; default: @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; } } tmp[j] = '\0'; s->hashed = NO; s->cString = [self resizeMemory: s->cString size: s->cStringLength + j + 1]; memcpy(s->cString + s->cStringLength, tmp, j + 1); s->cStringLength += j; s->length += length; if (isUTF8) s->isUTF8 = YES; } @finally { [self freeMemory: tmp]; } } - (void)appendFormat: (OFConstantString*)format arguments: (va_list)arguments { char *UTF8String; int UTF8StringLength; |
︙ | ︙ |
Modified src/OFString_UTF8.m from [a02eabeb4e] to [ce12e0f51c].
︙ | ︙ | |||
420 421 422 423 424 425 426 | characters++; length--; } else if (byteOrder != OF_BYTE_ORDER_NATIVE) swap = YES; s = &s_store; | < < < < > | | 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 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | characters++; length--; } else if (byteOrder != OF_BYTE_ORDER_NATIVE) swap = YES; s = &s_store; s->cString = [self allocMemoryWithSize: (length * 4) + 1]; s->length = length; for (i = 0; i < length; i++) { char buffer[4]; size_t characterLen = of_string_utf8_encode( (swap ? OF_BSWAP32(characters[i]) : characters[i]), buffer); switch (characterLen) { case 1: s->cString[j++] = buffer[0]; break; case 2: s->isUTF8 = YES; memcpy(s->cString + j, buffer, 2); j += 2; break; case 3: s->isUTF8 = YES; memcpy(s->cString + j, buffer, 3); j += 3; break; case 4: s->isUTF8 = YES; memcpy(s->cString + j, buffer, 4); j += 4; break; default: @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; } } s->cString[j] = '\0'; s->cStringLength = j; @try { s->cString = [self resizeMemory: s->cString size: j + 1]; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } } @catch (id e) { [self release]; @throw e; } |
︙ | ︙ |
Modified tests/OFStringTests.m from [9c36134f55] to [61ef4cadec].
︙ | ︙ | |||
114 115 116 117 118 119 120 121 122 123 124 125 126 127 | TEST(@"-[description]", [[s[0] description] isEqual: s[0]]) TEST(@"-[appendString:] and -[appendUTF8String:]", R([s[1] appendUTF8String: "1๐"]) && R([s[1] appendString: @"3"]) && R([s[0] appendString: s[1]]) && [s[0] isEqual: @"tรคsโฌ1๐3"]) TEST(@"-[length]", [s[0] length] == 7) TEST(@"-[UTF8StringLength]", [s[0] UTF8StringLength] == 13) TEST(@"-[hash]", [s[0] hash] == 0x705583C0) TEST(@"-[characterAtIndex:]", [s[0] characterAtIndex: 0] == 't' && [s[0] characterAtIndex: 1] == 0xE4 && [s[0] characterAtIndex: 3] == 0x20AC && | > > > > | 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | TEST(@"-[description]", [[s[0] description] isEqual: s[0]]) TEST(@"-[appendString:] and -[appendUTF8String:]", R([s[1] appendUTF8String: "1๐"]) && R([s[1] appendString: @"3"]) && R([s[0] appendString: s[1]]) && [s[0] isEqual: @"tรคsโฌ1๐3"]) TEST(@"-[appendCharacters:length:]", R([s[1] appendCharacters: ucstr + 6 length: 2]) && [s[1] isEqual: @"1๐3r๐บ"]) TEST(@"-[length]", [s[0] length] == 7) TEST(@"-[UTF8StringLength]", [s[0] UTF8StringLength] == 13) TEST(@"-[hash]", [s[0] hash] == 0x705583C0) TEST(@"-[characterAtIndex:]", [s[0] characterAtIndex: 0] == 't' && [s[0] characterAtIndex: 1] == 0xE4 && [s[0] characterAtIndex: 3] == 0x20AC && |
︙ | ︙ |