diff --git a/ChangeLog b/ChangeLog index cef5c17d8..6cada392b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,8 @@ * Tests/base/NSString/test00.m: Add David Chisnall's test from newapi branch slightly reformatted. * Source/GSString.m: Remove code that was identical to super class. + * Source/GSString.m: Move the method _unicodeString from here... + * Tests/base/NSString/test00.m: ...to here. 2018-06-28 Richard Frith-Macdonald diff --git a/Source/GSString.m b/Source/GSString.m index 02a80cb1d..02322f0cc 100644 --- a/Source/GSString.m +++ b/Source/GSString.m @@ -1100,23 +1100,6 @@ tsbytes(uintptr_t s, char *buf) return 8; } -/* This method is provided to enable regression tests to ensure they are - * using an object whose internal representation is wide (unicode) text, - * so that all the comparison operations between 8bit and 16bit strings - * can be tested. - */ -- (NSString*) _unicodeString -{ - GSUInlineString *o; - unsigned i = [self length]; - - o = [newUInline(i, [self zone]) autorelease]; - while (i-- > 0) - { - o->_contents.u[i] = [self characterAtIndex: i]; - } - return o; -} @end /** @@ -3758,23 +3741,6 @@ transmute(GSStr self, NSString *aString) return size; } -/* This method is provided to enable regression tests to ensure they are - * using an object whose internal representation is wide (unicode) text, - * so that all the comparison operations between 8bit and 16bit strings - * can be tested. - */ -- (NSString*) _unicodeString -{ - GSUInlineString *o; - unsigned i = [self length]; - - o = [newUInline(i, [self zone]) autorelease]; - while (i-- > 0) - { - o->_contents.u[i] = [self characterAtIndex: i]; - } - return o; -} @end @@ -4487,15 +4453,6 @@ agree, create a new GSUInlineString otherwise. } } -/* This method is provided to enable regression tests to ensure they are - * using an object whose internal representation is wide (unicode) text, - * so that all the comparison operations between 8bit and 16bit strings - * can be tested. - */ -- (NSString*) _unicodeString -{ - return self; -} @end @@ -6189,23 +6146,6 @@ literalIsEqual(NXConstantString *self, id anObject) return NSUTF8StringEncoding; } -/* This method is provided to enable regression tests to ensure they are - * using an object whose internal representation is wide (unicode) text, - * so that all the comparison operations between 8bit and 16bit strings - * can be tested. - */ -- (NSString*) _unicodeString -{ - GSUInlineString *o; - unsigned i = [self length]; - - o = [newUInline(i, [self zone]) autorelease]; - while (i-- > 0) - { - o->_contents.u[i] = [self characterAtIndex: i]; - } - return o; -} @end diff --git a/Tests/base/NSString/test00.m b/Tests/base/NSString/test00.m index 6fc325597..e8e9b27fd 100644 --- a/Tests/base/NSString/test00.m +++ b/Tests/base/NSString/test00.m @@ -4,11 +4,30 @@ #import #import -#ifdef GNUSTEP_BASE_LIBRARY + @interface NSString (Test) - (NSString*) _unicodeString; @end -#endif + +@implementation NSString (Test) + +/* This method is provided to enable regression tests to ensure they are + * using an object whose internal representation is wide (unicode) text, + * so that all the comparison operations between 8bit and 16bit strings + * can be tested. + */ +- (NSString*) _unicodeString +{ + int l = [self length]; + NSMutableData *d = [NSMutableData dataWithLength: (l * 2)]; + unichar *b = [d mutableBytes]; + + [self getCharacters: b]; + return [NSString stringWithCharacters: b length: l]; +} + +@end + static BOOL rangesEqual(NSRange r1, NSRange r2) { @@ -38,18 +57,9 @@ static void strCompare (char *s0, char *s1, NSComparisonResult ci, us1 = nil; PASS_RUNS(cs0 = [NSString stringWithCString: s0]; - l = [cs0 length]; - d = [NSMutableData dataWithLength: (l * 2)]; - b = [d mutableBytes]; - [cs0 getCharacters: b]; - us0 = [NSString stringWithCharacters: b length: l]; - + us0 = [cs0 _unicodeString]; cs1 = [NSString stringWithCString: s1]; - l = [cs1 length]; - d = [NSMutableData dataWithLength: (l * 2)]; - b = [d mutableBytes]; - [cs1 getCharacters: b]; - us1 = [NSString stringWithCharacters: b length: l];, + us1 = [cs1 _unicodeString];, "create strings for compare is ok"); opts = NSCaseInsensitiveSearch; type = "case insensitive comparison for"; @@ -178,33 +188,11 @@ static void strRange(char *s0, char *s1, unsigned int opts, us0 = nil; us1 = nil; -#ifdef GNUSTEP_BASE_LIBRARY - /* The _unicodeString method is a private/hidden method the strings in the - * base library provide to return an autorelease copy of themselves which - * is guaranteed to use a 16bit internal character representation and be a - * subclass of GSUnicodeString. - */ PASS_RUNS(cs0 = [NSString stringWithCString: s0]; us0 = [cs0 _unicodeString]; cs1 = [NSString stringWithCString: s1]; us1 = [cs1 _unicodeString];, "create strings for range is ok"); -#else - PASS_RUNS(cs0 = [NSString stringWithCString: s0]; - l = [cs0 length]; - d = [NSMutableData dataWithLength: (l * 2)]; - b = [d mutableBytes]; - [cs0 getCharacters: b]; - us0 = [NSString stringWithCharacters: b length: l]; - - cs1 = [NSString stringWithCString: s1]; - l = [cs1 length]; - d = [NSMutableData dataWithLength: (l * 2)]; - b = [d mutableBytes]; - [cs1 getCharacters: b]; - us1 = [NSString stringWithCharacters: b length: l];, - "create strings for range is ok"); -#endif res = [cs0 rangeOfString: cs1 options: opts range: range]; PASS(rangesEqual(res,want), "CCString range for '%s' and '%s' is ok",s0,s1); @@ -232,18 +220,9 @@ static void strRangeFromSet(char *s, NSCharacterSet *c, unsigned int o, NSRange us0 = nil; us1 = nil; PASS_RUNS(cs0 = [NSString stringWithCString: s]; - l = [cs0 length]; - d = [NSMutableData dataWithLength: (l * 2)]; - b = [d mutableBytes]; - [cs0 getCharacters: b]; - us0 = [NSString stringWithCharacters: b length: l]; - + us0 = [cs0 _unicodeString]; cs1 = [NSMutableString stringWithCString: s]; - l = [cs1 length]; - d = [NSMutableData dataWithLength: (l * 2)]; - b = [d mutableBytes]; - [cs1 getCharacters: b]; - us1 = [NSMutableString stringWithCharacters: b length: l];, + us1 = [cs1 _unicodeString];, "create strings for range"); res = [cs0 rangeOfCharacterFromSet: c options: o range: range];