libs-base/Tests/base/NSString/unichar_format.m
Niels Grewe 17d379a59a Optimise appending UTF-16 strings for formatting
If the string being appended to already uses unichar as the underlying 
character type, append the new characters using memcpy() instead of
looping over them individually. Also includes test cases to verify that
nothing breaks.



git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@38969 72102866-910b-0410-8b05-ffd578937521
2015-09-04 09:48:07 +00:00

24 lines
1.2 KiB
Objective-C

#import "ObjectTesting.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSString.h>
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSString *narrow = @"aaaa"; // fits in a single byte
NSString *wide = @"a\u20AC\u20ACa"; // Euro signs, requires UTF-16 storage
NSString *narrowNarrowFormat = [NSString stringWithFormat: @"a%@a", narrow];
NSString *narrowWideFormat = [NSString stringWithFormat: @"a%@a", wide];
NSString *wideNarrowFormat = [NSString stringWithFormat: @"\u20AC%@\u20ac", narrow];
NSString *wideWideFormat = [NSString stringWithFormat: @"\u20AC%@\u20ac", wide];
PASS_EQUAL(narrowNarrowFormat, @"aaaaaa",
"Formatting byte-width string into a byte-width string works.");
PASS_EQUAL(narrowWideFormat, @"aa\u20AC\u20ACaa",
"Formatting a 16 bit wide string into a byte-width string works.");
PASS_EQUAL(wideNarrowFormat, @"\u20ACaaaa\u20AC",
"Formatting a byte-width string into a 16 bit wide string works.");
PASS_EQUAL(wideWideFormat, @"\u20ACa\u20AC\u20ACa\u20AC",
"Formatting a 16 bit wide string into a 16 bit wide string works.");
[arp release]; arp = nil;
return 0;
}