Differences From Artifact [e371dc8e8d]:
- File src/OFString_UTF8.m — part of check-in [374956b098] at 2012-12-29 14:43:05 on branch trunk — Prettify some code. (user: js, size: 28920) [annotate] [blame] [check-ins using]
To Artifact [797a478d4d]:
- File
src/OFString_UTF8.m
— part of check-in
[640b225ba7]
at
2012-12-29 17:56:05
on branch trunk
— OFString: Improve API for Unicode strings.
* Instead of Unicode "strings", it uses the term "Unicode character
array".
* No terminating 0 character anymore, as these are not C strings
anyway. (user: js, size: 28916) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
399 400 401 402 403 404 405 | [self release]; @throw e; } return self; } | | < | > | | | | | | 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 | [self release]; @throw e; } return self; } - initWithCharacters: (const of_unichar_t*)characters length: (size_t)length byteOrder: (of_byte_order_t)byteOrder { self = [super init]; @try { size_t i, j = 0; BOOL swap = NO; if (length > 0 && *characters == 0xFEFF) { characters++; length--; } else if (length > 0 && *characters == 0xFFFE0000) { swap = YES; characters++; length--; } else if (byteOrder != OF_BYTE_ORDER_NATIVE) swap = YES; s = &s_store; s->cStringLength = length; 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: |
︙ | ︙ | |||
482 483 484 485 486 487 488 | @throw e; } return self; } - initWithUTF16String: (const uint16_t*)string | < > | 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 | @throw e; } return self; } - initWithUTF16String: (const uint16_t*)string length: (size_t)length byteOrder: (of_byte_order_t)byteOrder { self = [super init]; @try { size_t i, j = 0; BOOL swap = NO; |
︙ | ︙ | |||
949 950 951 952 953 954 955 | } - (void)getCharacters: (of_unichar_t*)buffer inRange: (of_range_t)range { /* TODO: Could be slightly optimized */ void *pool = objc_autoreleasePoolPush(); | | | | 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 | } - (void)getCharacters: (of_unichar_t*)buffer inRange: (of_range_t)range { /* TODO: Could be slightly optimized */ void *pool = objc_autoreleasePoolPush(); const of_unichar_t *characters = [self characters]; if (range.length > SIZE_MAX - range.location || range.location + range.length > s->length) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; memcpy(buffer, characters + range.location, range.length * sizeof(of_unichar_t)); objc_autoreleasePoolPop(pool); } - (of_range_t)rangeOfString: (OFString*)string options: (int)options |
︙ | ︙ | |||
1244 1245 1246 1247 1248 1249 1250 | #endif return [OFString stringWithUTF8String: s->cString length: 1]; return @"."; } | | | < < | 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 | #endif return [OFString stringWithUTF8String: s->cString length: 1]; return @"."; } - (const of_unichar_t*)characters { OFObject *object = [[[OFObject alloc] init] autorelease]; of_unichar_t *ret; size_t i, j; ret = [object allocMemoryWithSize: sizeof(of_unichar_t) count: s->length]; i = j = 0; while (i < s->cStringLength) { of_unichar_t c; size_t cLen; cLen = of_string_utf8_decode(s->cString + i, s->cStringLength - i, &c); if (cLen == 0 || c > 0x10FFFF) @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; ret[j++] = c; i += cLen; } return ret; } #ifdef OF_HAVE_BLOCKS - (void)enumerateLinesUsingBlock: (of_string_line_enumeration_block_t)block { void *pool; |
︙ | ︙ |