simplify case conversion options

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@35364 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2012-08-08 16:54:08 +00:00
parent cbc74f3800
commit e0c4edf62b
2 changed files with 5 additions and 144 deletions

View file

@ -1,7 +1,8 @@
2012-08-08 Richard Frith-Macdonald <rfm@gnu.org> 2012-08-08 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSString.m: Add upper and lower case methods for literal * Source/GSString.m: Simplify/remove upper and lower case conversion
strings. Change other literal string methods to check that content to use superclass implementation avoiding toupper() and tolower().
Change other literal string methods to check that the content
is really utf8 in more places. Generally simplify/cleanup a bit. is really utf8 in more places. Generally simplify/cleanup a bit.
2012-08-02 Richard Frith-Macdonald <rfm@gnu.org> 2012-08-02 Richard Frith-Macdonald <rfm@gnu.org>

View file

@ -3668,20 +3668,6 @@ agree, create a new GSCInlineString otherwise.
return lossyCString_c((GSStr)self); return lossyCString_c((GSStr)self);
} }
- (id) lowercaseString
{
GSCInlineString *o;
unsigned i;
o = [newCInline(_count, [self zone]) autorelease];
i = _count;
while (i-- > 0)
{
o->_contents.c[i] = tolower(_contents.c[i]);
}
return o;
}
- (id) mutableCopy - (id) mutableCopy
{ {
GSMutableString *obj; GSMutableString *obj;
@ -3763,20 +3749,6 @@ agree, create a new GSCInlineString otherwise.
return [super substringWithRange: aRange]; return [super substringWithRange: aRange];
} }
- (id) uppercaseString
{
GSCInlineString *o;
unsigned i;
o = [newCInline(_count, [self zone]) autorelease];
i = _count;
while (i-- > 0)
{
o->_contents.c[i] = toupper(_contents.c[i]);
}
return o;
}
- (const char *) UTF8String - (const char *) UTF8String
{ {
return UTF8String_c((GSStr)self); return UTF8String_c((GSStr)self);
@ -4795,19 +4767,7 @@ NSAssert(_flags.owned == 1 && _zone != 0, NSInternalInconsistencyException);
} }
return [o autorelease]; return [o autorelease];
} }
else return [super lowercaseString];
{
GSCInlineString *o;
unsigned i;
o = newCInline(_count, [self zone]);
i = _count;
while (i-- > 0)
{
o->_contents.c[i] = tolower(_contents.c[i]);
}
return [o autorelease];
}
} }
- (id) makeImmutableCopyOnFail: (BOOL)force - (id) makeImmutableCopyOnFail: (BOOL)force
@ -5154,19 +5114,7 @@ NSAssert(_flags.owned == 1 && _zone != 0, NSInternalInconsistencyException);
} }
return o; return o;
} }
else return [super uppercaseString];
{
GSCInlineString *o;
unsigned i;
o = [newCInline(_count, [self zone]) autorelease];
i = _count;
while (i-- > 0)
{
o->_contents.c[i] = toupper(_contents.c[i]);
}
return o;
}
} }
// private method for Unicode level 3 implementation // private method for Unicode level 3 implementation
@ -5515,50 +5463,6 @@ literalIsEqual(NXConstantString *self, id anObject)
return lengthUTF8((const uint8_t*)nxcsptr, nxcslen, 0, 0); return lengthUTF8((const uint8_t*)nxcsptr, nxcslen, 0, 0);
} }
- (NSString*) lowercaseString
{
if (nxcslen > 0)
{
BOOL ascii;
BOOL latin1;
unsigned length;
unsigned i = 0;
length = lengthUTF8((const uint8_t*)nxcsptr, nxcslen, &ascii, &latin1);
if (YES == ascii)
{
GSCInlineString *result;
result = [newCInline(length, [self zone]) autorelease];
while (i < length)
{
result->_contents.c[i] = tolower(((const char*)nxcsptr)[i]);
i++;
}
return result;
}
else
{
NSUInteger l = 0;
unichar u;
unichar n = 0;
GSUInlineString *result;
result = [newUInline(length, [self zone]) autorelease];
while (l < length)
{
u = nextUTF8((const uint8_t *)nxcsptr, nxcslen, &i, &n);
result->_contents.u[l++] = uni_tolower(u);
}
return result;
}
}
else
{
return self;
}
}
- (NSRange) rangeOfCharacterFromSet: (NSCharacterSet*)aSet - (NSRange) rangeOfCharacterFromSet: (NSCharacterSet*)aSet
options: (NSUInteger)mask options: (NSUInteger)mask
range: (NSRange)aRange range: (NSRange)aRange
@ -5674,50 +5578,6 @@ literalIsEqual(NXConstantString *self, id anObject)
return NSMakeRange(NSNotFound, 0); return NSMakeRange(NSNotFound, 0);
} }
- (NSString*) uppercaseString
{
if (nxcslen > 0)
{
BOOL ascii;
BOOL latin1;
unsigned length;
unsigned i = 0;
length = lengthUTF8((const uint8_t*)nxcsptr, nxcslen, &ascii, &latin1);
if (YES == ascii)
{
GSCInlineString *result;
result = [newCInline(length, [self zone]) autorelease];
while (i < length)
{
result->_contents.c[i] = toupper(((const char*)nxcsptr)[i]);
i++;
}
return result;
}
else
{
NSUInteger l = 0;
unichar u;
unichar n = 0;
GSUInlineString *result;
result = [newUInline(length, [self zone]) autorelease];
while (l < length)
{
u = nextUTF8((const uint8_t *)nxcsptr, nxcslen, &i, &n);
result->_contents.u[l++] = uni_toupper(u);
}
return result;
}
}
else
{
return self;
}
}
- (id) retain - (id) retain
{ {
return self; return self;