Differences From Artifact [b0b4b6766d]:
- File src/OFMutableString.m — part of check-in [e0b9167693] at 2016-02-21 15:37:42 on branch trunk — Make use of C99-style for loops (user: js, size: 12577) [annotate] [blame] [check-ins using]
To Artifact [7c949926c1]:
- File
src/OFMutableString.m
— part of check-in
[b7b33247d6]
at
2016-08-29 00:05:29
on branch trunk
— configure: Add --disable-unicode-tables option
This is only useful for size-constrained systems and changes the
behavior as follows:* Case-insensitive comparisons only work as expected for ASCII
characters. This means that while a and A compare equal, ä and Ä do
not.* -[OFMutableString {upper,lower}] and
-[OFString {upper,lower}caseString] only work on ASCII characters;
all other characters are left as they are. This means that the upper
version of a is A, but the upper version of ä is still ä (and vice
versa for lower). (user: js, size: 13923) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #include <stdarg.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #import "OFString.h" #import "OFMutableString_UTF8.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" #import "of_asprintf.h" #import "unicode.h" static struct { Class isa; } placeholder; @interface OFMutableString_placeholder: OFMutableString @end @implementation OFMutableString_placeholder - init { | > > > > > > > > > > > > > > > > | 12 13 14 15 16 17 18 19 20 21 22 23 24 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 55 56 57 58 59 60 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #include <ctype.h> #include <stdarg.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #import "OFString.h" #import "OFMutableString_UTF8.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" #import "of_asprintf.h" #import "unicode.h" static struct { Class isa; } placeholder; #ifndef OF_HAVE_UNICODE_TABLES /* Wrap these, as they can be macros. */ static int toupperWrapper(int c) { return toupper(c); } static int tolowerWrapper(int c) { return tolower(c); } #endif @interface OFMutableString_placeholder: OFMutableString @end @implementation OFMutableString_placeholder - init { |
︙ | ︙ | |||
236 237 238 239 240 241 242 243 244 245 246 247 248 249 | { if (self == [OFMutableString class]) return (id)&placeholder; return [super alloc]; } - (void)OF_convertWithWordStartTable: (const of_unichar_t *const[])startTable wordMiddleTable: (const of_unichar_t *const[])middleTable wordStartTableSize: (size_t)startTableSize wordMiddleTableSize: (size_t)middleTableSize { void *pool = objc_autoreleasePoolPush(); const of_unichar_t *characters = [self characters]; | > | 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | { if (self == [OFMutableString class]) return (id)&placeholder; return [super alloc]; } #ifdef OF_HAVE_UNICODE_TABLES - (void)OF_convertWithWordStartTable: (const of_unichar_t *const[])startTable wordMiddleTable: (const of_unichar_t *const[])middleTable wordStartTableSize: (size_t)startTableSize wordMiddleTableSize: (size_t)middleTableSize { void *pool = objc_autoreleasePoolPush(); const of_unichar_t *characters = [self characters]; |
︙ | ︙ | |||
278 279 280 281 282 283 284 285 286 287 288 289 290 291 | isStart = false; break; } } objc_autoreleasePoolPop(pool); } - (void)setCharacter: (of_unichar_t)character atIndex: (size_t)index { void *pool = objc_autoreleasePoolPush(); OFString *string; | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | isStart = false; break; } } objc_autoreleasePoolPop(pool); } #else - (void)OF_convertWithWordStartFunction: (int (*)(int))startFunction wordMiddleFunction: (int (*)(int))middleFunction { void *pool = objc_autoreleasePoolPush(); const of_unichar_t *characters = [self characters]; size_t length = [self length]; bool isStart = true; for (size_t i = 0; i < length; i++) { int (*function)(int) = (isStart ? startFunction : middleFunction);; of_unichar_t c = characters[i]; if (c <= 0x7F) [self setCharacter: (int)function(c) atIndex: i]; switch (c) { case ' ': case '\t': case '\n': case '\r': isStart = true; break; default: isStart = false; break; } } objc_autoreleasePoolPop(pool); } #endif - (void)setCharacter: (of_unichar_t)character atIndex: (size_t)index { void *pool = objc_autoreleasePoolPush(); OFString *string; |
︙ | ︙ | |||
405 406 407 408 409 410 411 412 413 414 415 416 417 418 | [self setCharacter: [self characterAtIndex: i] atIndex: j]; [self setCharacter: tmp atIndex: i]; } } - (void)uppercase { [self OF_convertWithWordStartTable: of_unicode_uppercase_table wordMiddleTable: of_unicode_uppercase_table wordStartTableSize: OF_UNICODE_UPPERCASE_TABLE_SIZE wordMiddleTableSize: OF_UNICODE_UPPERCASE_TABLE_SIZE]; } | > | 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 | [self setCharacter: [self characterAtIndex: i] atIndex: j]; [self setCharacter: tmp atIndex: i]; } } #ifdef OF_HAVE_UNICODE_TABLES - (void)uppercase { [self OF_convertWithWordStartTable: of_unicode_uppercase_table wordMiddleTable: of_unicode_uppercase_table wordStartTableSize: OF_UNICODE_UPPERCASE_TABLE_SIZE wordMiddleTableSize: OF_UNICODE_UPPERCASE_TABLE_SIZE]; } |
︙ | ︙ | |||
428 429 430 431 432 433 434 435 436 437 438 439 440 441 | - (void)capitalize { [self OF_convertWithWordStartTable: of_unicode_titlecase_table wordMiddleTable: of_unicode_lowercase_table wordStartTableSize: OF_UNICODE_TITLECASE_TABLE_SIZE wordMiddleTableSize: OF_UNICODE_LOWERCASE_TABLE_SIZE]; } - (void)insertString: (OFString*)string atIndex: (size_t)index { [self replaceCharactersInRange: of_range(index, 0) withString: string]; } | > > > > > > > > > > > > > > > > > > > | 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 | - (void)capitalize { [self OF_convertWithWordStartTable: of_unicode_titlecase_table wordMiddleTable: of_unicode_lowercase_table wordStartTableSize: OF_UNICODE_TITLECASE_TABLE_SIZE wordMiddleTableSize: OF_UNICODE_LOWERCASE_TABLE_SIZE]; } #else - (void)uppercase { [self OF_convertWithWordStartFunction: toupperWrapper wordMiddleFunction: toupperWrapper]; } - (void)lowercase { [self OF_convertWithWordStartFunction: tolowerWrapper wordMiddleFunction: tolowerWrapper]; } - (void)capitalize { [self OF_convertWithWordStartFunction: toupperWrapper wordMiddleFunction: tolowerWrapper]; } #endif - (void)insertString: (OFString*)string atIndex: (size_t)index { [self replaceCharactersInRange: of_range(index, 0) withString: string]; } |
︙ | ︙ |