mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +00:00
Various minor fixes and optimisations ... see ChangeLog
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@22334 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
7a186a7782
commit
3c2b3f6699
5 changed files with 197 additions and 53 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
2006-01-19 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* Tools/plget.m: remove unused variable
|
||||||
|
* Source/GGSString.m: optimise ([canBeConvertedToEncoding:])
|
||||||
|
* Source/NSURL.m: correct misleading/wrong exception text.
|
||||||
|
* Source/NSString.m: mingw path handling tweaks ... build new
|
||||||
|
paths using native separator by default.
|
||||||
|
|
||||||
2006-01-19 Richard Frith-Macdonald <rfm@gnu.org>
|
2006-01-19 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Headers/Foundation/NSThread.h:
|
* Headers/Foundation/NSThread.h:
|
||||||
|
|
|
@ -797,60 +797,135 @@ boolValue_u(GSStr self)
|
||||||
static inline BOOL
|
static inline BOOL
|
||||||
canBeConvertedToEncoding_c(GSStr self, NSStringEncoding enc)
|
canBeConvertedToEncoding_c(GSStr self, NSStringEncoding enc)
|
||||||
{
|
{
|
||||||
if (enc == intEnc)
|
unsigned c = self->_count;
|
||||||
{
|
BOOL result = YES;
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
BOOL result = (*convertImp)((id)self, convertSel, enc);
|
|
||||||
|
|
||||||
return result;
|
/*
|
||||||
|
* If the length is zero, or we are already using the required encoding,
|
||||||
|
* or the required encoding is unicode (can hold any character) then we
|
||||||
|
* can assume that a conversion would succeed.
|
||||||
|
* We also know a conversion must succeed if the internal encoding is
|
||||||
|
* ascii and the required encoding has ascii as a subset.
|
||||||
|
*/
|
||||||
|
if (c > 0
|
||||||
|
&& enc != intEnc
|
||||||
|
&& enc != NSUTF8StringEncoding
|
||||||
|
&& enc != NSUnicodeStringEncoding
|
||||||
|
&& ((intEnc != NSASCIIStringEncoding)
|
||||||
|
|| ((enc != NSISOLatin1StringEncoding)
|
||||||
|
&& (enc != NSISOLatin2StringEncoding)
|
||||||
|
&& (enc != NSNEXTSTEPStringEncoding)
|
||||||
|
&& (enc != NSNonLossyASCIIStringEncoding))))
|
||||||
|
{
|
||||||
|
unsigned l = 0;
|
||||||
|
unichar *r = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* To check whether conversion is possible, we first convert to
|
||||||
|
* unicode and then check to see whether it is possible to convert
|
||||||
|
* to the desired encoding.
|
||||||
|
*/
|
||||||
|
result = GSToUnicode(&r, &l, self->_contents.c, self->_count, intEnc,
|
||||||
|
NSDefaultMallocZone(), GSUniStrict);
|
||||||
|
if (result == YES)
|
||||||
|
{
|
||||||
|
if (enc == NSISOLatin1StringEncoding)
|
||||||
|
{
|
||||||
|
unsigned i;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If all the unicode characters are in the 0 to 255 range
|
||||||
|
* they are all latin1.
|
||||||
|
*/
|
||||||
|
for (i = 0; i < l; i++)
|
||||||
|
{
|
||||||
|
if (r[i] > 255)
|
||||||
|
{
|
||||||
|
result = NO;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (enc == NSASCIIStringEncoding)
|
||||||
|
{
|
||||||
|
unsigned i;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If all the unicode characters are in the 0 to 127 range
|
||||||
|
* they are all ascii.
|
||||||
|
*/
|
||||||
|
for (i = 0; i < l; i++)
|
||||||
|
{
|
||||||
|
if (r[i] > 127)
|
||||||
|
{
|
||||||
|
result = NO;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
unsigned dummy = 0; // Hold returned length.
|
||||||
|
|
||||||
|
result = GSFromUnicode(0, &dummy, r, l, enc, 0, GSUniStrict);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Temporary unicode string no longer needed.
|
||||||
|
NSZoneFree(NSDefaultMallocZone(), r);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline BOOL
|
static inline BOOL
|
||||||
canBeConvertedToEncoding_u(GSStr self, NSStringEncoding enc)
|
canBeConvertedToEncoding_u(GSStr self, NSStringEncoding enc)
|
||||||
{
|
{
|
||||||
BOOL result = YES;
|
unsigned c = self->_count;
|
||||||
|
BOOL result = YES;
|
||||||
|
|
||||||
if (enc == NSISOLatin1StringEncoding)
|
if (c > 0 && enc != NSUTF8StringEncoding && enc != NSUnicodeStringEncoding)
|
||||||
{
|
{
|
||||||
unsigned i;
|
if (enc == NSISOLatin1StringEncoding)
|
||||||
|
|
||||||
/*
|
|
||||||
* If all the unicode characters are in the 0 to 255 range
|
|
||||||
* they are all latin1.
|
|
||||||
*/
|
|
||||||
for (i = 0; i < self->_count; i++)
|
|
||||||
{
|
{
|
||||||
if (self->_contents.u[i] > 255)
|
unsigned i;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If all the unicode characters are in the 0 to 255 range
|
||||||
|
* they are all latin1.
|
||||||
|
*/
|
||||||
|
for (i = 0; i < self->_count; i++)
|
||||||
{
|
{
|
||||||
result = NO;
|
if (self->_contents.u[i] > 255)
|
||||||
break;
|
{
|
||||||
|
result = NO;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
else if (enc == NSASCIIStringEncoding)
|
||||||
else if (enc == NSASCIIStringEncoding)
|
|
||||||
{
|
|
||||||
unsigned i;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If all the unicode characters are in the 0 to 127 range
|
|
||||||
* they are all ascii.
|
|
||||||
*/
|
|
||||||
for (i = 0; i < self->_count; i++)
|
|
||||||
{
|
{
|
||||||
if (self->_contents.u[i] > 127)
|
unsigned i;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If all the unicode characters are in the 0 to 127 range
|
||||||
|
* they are all ascii.
|
||||||
|
*/
|
||||||
|
for (i = 0; i < self->_count; i++)
|
||||||
{
|
{
|
||||||
result = NO;
|
if (self->_contents.u[i] > 127)
|
||||||
break;
|
{
|
||||||
|
result = NO;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
unsigned dummy = 0; // Hold returned length.
|
||||||
result = (*convertImp)((id)self, convertSel, enc);
|
|
||||||
|
result = GSFromUnicode(0, &dummy, self->_contents.u, c, enc,
|
||||||
|
0, GSUniStrict);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -219,6 +219,42 @@ pathSepMember(unichar c)
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline static unichar
|
||||||
|
pathSepChar()
|
||||||
|
{
|
||||||
|
#if defined(__MINGW32__)
|
||||||
|
if (GSPathHandlingUnix() == YES)
|
||||||
|
{
|
||||||
|
return '/';
|
||||||
|
}
|
||||||
|
return '\\';
|
||||||
|
#else
|
||||||
|
if (GSPathHandlingWindows() == YES)
|
||||||
|
{
|
||||||
|
return '\\';
|
||||||
|
}
|
||||||
|
return '/';
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static NSString*
|
||||||
|
pathSepString()
|
||||||
|
{
|
||||||
|
#if defined(__MINGW32__)
|
||||||
|
if (GSPathHandlingUnix() == YES)
|
||||||
|
{
|
||||||
|
return @"/";
|
||||||
|
}
|
||||||
|
return @"\\";
|
||||||
|
#else
|
||||||
|
if (GSPathHandlingWindows() == YES)
|
||||||
|
{
|
||||||
|
return @"\\";
|
||||||
|
}
|
||||||
|
return @"/";
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Find end of 'root' sequence in a string. Characters before this
|
* Find end of 'root' sequence in a string. Characters before this
|
||||||
* point in the string cannot be split into path components/extensions.
|
* point in the string cannot be split into path components/extensions.
|
||||||
|
@ -3674,7 +3710,7 @@ static NSFileManager *fm = nil;
|
||||||
{
|
{
|
||||||
length--;
|
length--;
|
||||||
}
|
}
|
||||||
buf[length++] = '/';
|
buf[length++] = pathSepChar();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((aLength - root) > 0)
|
if ((aLength - root) > 0)
|
||||||
|
@ -3704,12 +3740,12 @@ static NSFileManager *fm = nil;
|
||||||
{
|
{
|
||||||
if (pathSepMember(buf[aLength]) == YES)
|
if (pathSepMember(buf[aLength]) == YES)
|
||||||
{
|
{
|
||||||
buf[aLength] = '/'; // Standardise
|
buf[aLength] = pathSepChar();
|
||||||
if (pathSepMember(buf[aLength-1]) == YES)
|
if (pathSepMember(buf[aLength-1]) == YES)
|
||||||
{
|
{
|
||||||
unsigned pos;
|
unsigned pos;
|
||||||
|
|
||||||
buf[aLength-1] = '/'; // Standardise
|
buf[aLength-1] = pathSepChar();
|
||||||
for (pos = aLength+1; pos < length; pos++)
|
for (pos = aLength+1; pos < length; pos++)
|
||||||
{
|
{
|
||||||
buf[pos-1] = buf[pos];
|
buf[pos-1] = buf[pos];
|
||||||
|
@ -4347,7 +4383,26 @@ static NSFileManager *fm = nil;
|
||||||
{
|
{
|
||||||
s = AUTORELEASE([self mutableCopy]);
|
s = AUTORELEASE([self mutableCopy]);
|
||||||
}
|
}
|
||||||
[s replaceString: @"\\" withString: @"/"];
|
#if defined(__MINGW32__)
|
||||||
|
if (GSPathHandlingUnix() == YES)
|
||||||
|
{
|
||||||
|
[s replaceString: @"\\" withString: @"/"];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
[s replaceString: @"/" withString: @"\\"];
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (GSPathHandlingWindows() == YES)
|
||||||
|
{
|
||||||
|
[s replaceString: @"/" withString: @"\\"];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
[s replaceString: @"\\" withString: @"/"];
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
l = [s length];
|
l = [s length];
|
||||||
root = rootOf(s, l);
|
root = rootOf(s, l);
|
||||||
|
|
||||||
|
@ -4375,11 +4430,14 @@ static NSFileManager *fm = nil;
|
||||||
}
|
}
|
||||||
// Condense ('/./') sequences.
|
// Condense ('/./') sequences.
|
||||||
r = (NSRange){root, l-root};
|
r = (NSRange){root, l-root};
|
||||||
while ((r = [s rangeOfString: @"/." options: 0 range: r]).length == 2)
|
while ((r = [s rangeOfString: @"." options: 0 range: r]).length == 1)
|
||||||
{
|
{
|
||||||
if (NSMaxRange(r) == l ||
|
if (r.location > 0
|
||||||
pathSepMember((*caiImp)(s, caiSel, NSMaxRange(r))) == YES)
|
&& pathSepMember((*caiImp)(s, caiSel, r.location-1)) == YES
|
||||||
|
&& (NSMaxRange(r) == l
|
||||||
|
|| pathSepMember((*caiImp)(s, caiSel, NSMaxRange(r))) == YES))
|
||||||
{
|
{
|
||||||
|
r.length++;
|
||||||
[s deleteCharactersInRange: r];
|
[s deleteCharactersInRange: r];
|
||||||
l -= r.length;
|
l -= r.length;
|
||||||
}
|
}
|
||||||
|
@ -4391,7 +4449,7 @@ static NSFileManager *fm = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Strip trailing '/' if present.
|
// Strip trailing '/' if present.
|
||||||
if (l > root && [s hasSuffix: @"/"])
|
if (l > root && pathSepMember([s characterAtIndex: l - 1]) == YES)
|
||||||
{
|
{
|
||||||
r.length = 1;
|
r.length = 1;
|
||||||
r.location = l - r.length;
|
r.location = l - r.length;
|
||||||
|
@ -4418,11 +4476,15 @@ static NSFileManager *fm = nil;
|
||||||
#if defined(__MINGW32__)
|
#if defined(__MINGW32__)
|
||||||
/* Condense `/../' */
|
/* Condense `/../' */
|
||||||
r = (NSRange){root, l-root};
|
r = (NSRange){root, l-root};
|
||||||
while ((r = [s rangeOfString: @"/.." options: 0 range: r]).length == 3)
|
while ((r = [s rangeOfString: @".." options: 0 range: r]).length == 2)
|
||||||
{
|
{
|
||||||
if (NSMaxRange(r) == l ||
|
if (r.location > 0
|
||||||
pathSepMember((*caiImp)(s, caiSel, NSMaxRange(r))) == YES)
|
&& pathSepMember((*caiImp)(s, caiSel, r.location-1)) == YES
|
||||||
|
&& (NSMaxRange(r) == l
|
||||||
|
|| pathSepMember((*caiImp)(s, caiSel, NSMaxRange(r))) == YES))
|
||||||
{
|
{
|
||||||
|
r.location--;
|
||||||
|
r.lenght++;
|
||||||
if (r.location > root)
|
if (r.location > root)
|
||||||
{
|
{
|
||||||
NSRange r2 = {root, r.location-root};
|
NSRange r2 = {root, r.location-root};
|
||||||
|
@ -4550,7 +4612,7 @@ static NSFileManager *fm = nil;
|
||||||
s = [components objectAtIndex: 0];
|
s = [components objectAtIndex: 0];
|
||||||
if ([s length] == 0)
|
if ([s length] == 0)
|
||||||
{
|
{
|
||||||
s = @"/";
|
s = pathSepString();
|
||||||
}
|
}
|
||||||
for (i = 1; i < c; i++)
|
for (i = 1; i < c; i++)
|
||||||
{
|
{
|
||||||
|
@ -4579,7 +4641,7 @@ static NSFileManager *fm = nil;
|
||||||
* Any string beginning with '/' is absolute ... except in windows mode
|
* Any string beginning with '/' is absolute ... except in windows mode
|
||||||
* or on windows and not in unix mode.
|
* or on windows and not in unix mode.
|
||||||
*/
|
*/
|
||||||
if (c == '/')
|
if (c == pathSepChar())
|
||||||
{
|
{
|
||||||
#if defined(__MINGW32__)
|
#if defined(__MINGW32__)
|
||||||
if (GSPathHandlingUnix() == YES)
|
if (GSPathHandlingUnix() == YES)
|
||||||
|
@ -4662,7 +4724,7 @@ static NSFileManager *fm = nil;
|
||||||
*/
|
*/
|
||||||
if (l > root && pathSepMember([s characterAtIndex: l-1]))
|
if (l > root && pathSepMember([s characterAtIndex: l-1]))
|
||||||
{
|
{
|
||||||
[a addObject: @"/"];
|
[a addObject: pathSepString()];
|
||||||
}
|
}
|
||||||
|
|
||||||
r = [a copy];
|
r = [a copy];
|
||||||
|
|
|
@ -825,7 +825,7 @@ static unsigned urlAlign;
|
||||||
if (legal(buf->host, "-") == NO)
|
if (legal(buf->host, "-") == NO)
|
||||||
{
|
{
|
||||||
[NSException raise: NSGenericException format:
|
[NSException raise: NSGenericException format:
|
||||||
@"illegal character in user/password part"];
|
@"illegal character in host part"];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -75,7 +75,6 @@ main(int argc, char** argv, char **env)
|
||||||
NSFileHandle *fileHandle;
|
NSFileHandle *fileHandle;
|
||||||
NSData *inputData;
|
NSData *inputData;
|
||||||
NSString *inputString;
|
NSString *inputString;
|
||||||
NSDictionary *dictionary;
|
|
||||||
NSData *outputData;
|
NSData *outputData;
|
||||||
|
|
||||||
NS_DURING
|
NS_DURING
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue