mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +00:00
minor string fixups
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@33966 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
44830d5fd2
commit
ccbd4060d9
2 changed files with 36 additions and 21 deletions
18
ChangeLog
18
ChangeLog
|
@ -1,3 +1,9 @@
|
||||||
|
2011-10-11 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* Source/NSString.m: Fix boundary error when getting cString into a
|
||||||
|
buffer. Fix floatValue and doubleValue to support arbitrary length
|
||||||
|
of leading white space.
|
||||||
|
|
||||||
2011-10-08 Niels Grewe <niels.grewe@halbordnung.de>
|
2011-10-08 Niels Grewe <niels.grewe@halbordnung.de>
|
||||||
|
|
||||||
* Source/Additions/GSMime.m (GSMimeParser -scanToken:): Return an empty
|
* Source/Additions/GSMime.m (GSMimeParser -scanToken:): Return an empty
|
||||||
|
@ -5,12 +11,12 @@
|
||||||
|
|
||||||
2011-10-08 Richard Frith-Macdonald <rfm@gnu.org>
|
2011-10-08 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* GSFileHandle.m:
|
* Source/GSFileHandle.m:
|
||||||
* GSNetwork.h:
|
* Source/GSNetwork.h:
|
||||||
* GSSocketStream.m:
|
* Source/GSSocketStream.m:
|
||||||
* NSMessagePort.m:
|
* Source/NSMessagePort.m:
|
||||||
* NSSocketPort.m:
|
* Source/NSSocketPort.m:
|
||||||
* NSURLProtocol.m:
|
* Source/NSURLProtocol.m:
|
||||||
Check for EALREADY as well as EINPROGRESS as an indicator of an
|
Check for EALREADY as well as EINPROGRESS as an indicator of an
|
||||||
incomplete system call on a non-blocking descriptor.
|
incomplete system call on a non-blocking descriptor.
|
||||||
|
|
||||||
|
|
|
@ -131,6 +131,7 @@ static SEL cMemberSel = 0;
|
||||||
|
|
||||||
#define IS_BIT_SET(a,i) ((((a) & (1<<(i)))) > 0)
|
#define IS_BIT_SET(a,i) ((((a) & (1<<(i)))) > 0)
|
||||||
|
|
||||||
|
static NSCharacterSet *nonspace = nil;
|
||||||
static NSData *whitespaceBitmap;
|
static NSData *whitespaceBitmap;
|
||||||
static unsigned const char *whitespaceBitmapRep = NULL;
|
static unsigned const char *whitespaceBitmapRep = NULL;
|
||||||
#define GS_IS_WHITESPACE(X) IS_BIT_SET(whitespaceBitmapRep[(X)/8], (X) % 8)
|
#define GS_IS_WHITESPACE(X) IS_BIT_SET(whitespaceBitmapRep[(X)/8], (X) % 8)
|
||||||
|
@ -148,7 +149,7 @@ static void setupWhitespace(void)
|
||||||
*/
|
*/
|
||||||
whitespace = [NSCharacterSet characterSetWithCharactersInString:
|
whitespace = [NSCharacterSet characterSetWithCharactersInString:
|
||||||
@" \t\r\n\f\b"];
|
@" \t\r\n\f\b"];
|
||||||
|
nonspace = [[whitespace invertedSet] retain];
|
||||||
whitespaceBitmap = RETAIN([whitespace bitmapRepresentation]);
|
whitespaceBitmap = RETAIN([whitespace bitmapRepresentation]);
|
||||||
whitespaceBitmapRep = [whitespaceBitmap bytes];
|
whitespaceBitmapRep = [whitespaceBitmap bytes];
|
||||||
}
|
}
|
||||||
|
@ -3014,16 +3015,16 @@ handle_printf_atsign (FILE *stream,
|
||||||
{
|
{
|
||||||
NSData *d = [self dataUsingEncoding: encoding];
|
NSData *d = [self dataUsingEncoding: encoding];
|
||||||
unsigned length = [d length];
|
unsigned length = [d length];
|
||||||
BOOL result = (length <= maxLength) ? YES : NO;
|
BOOL result = (length < maxLength) ? YES : NO;
|
||||||
|
|
||||||
if (d == nil)
|
if (d == nil)
|
||||||
{
|
{
|
||||||
[NSException raise: NSCharacterConversionException
|
[NSException raise: NSCharacterConversionException
|
||||||
format: @"Can't convert to C string."];
|
format: @"Can't convert to C string."];
|
||||||
}
|
}
|
||||||
if (length > maxLength)
|
if (length >= maxLength)
|
||||||
{
|
{
|
||||||
length = maxLength;
|
length = maxLength-1;
|
||||||
}
|
}
|
||||||
memcpy(buffer, [d bytes], length);
|
memcpy(buffer, [d bytes], length);
|
||||||
buffer[length] = '\0';
|
buffer[length] = '\0';
|
||||||
|
@ -3108,12 +3109,16 @@ handle_printf_atsign (FILE *stream,
|
||||||
- (double) doubleValue
|
- (double) doubleValue
|
||||||
{
|
{
|
||||||
unichar buf[32];
|
unichar buf[32];
|
||||||
unsigned len = [self length];
|
|
||||||
double d = 0.0;
|
double d = 0.0;
|
||||||
|
NSRange r;
|
||||||
|
|
||||||
if (len > 32) len = 32;
|
setupWhitespace();
|
||||||
[self getCharacters: buf range: NSMakeRange(0, len)];
|
r = [self rangeOfCharacterFromSet: nonspace];
|
||||||
GSScanDouble(buf, len, &d);
|
if (NSNotFound == r.location) return 0.0;
|
||||||
|
r.length = [self length] - r.location;
|
||||||
|
if (r.length > 32) r.length = 32;
|
||||||
|
[self getCharacters: buf range: r];
|
||||||
|
GSScanDouble(buf, r.length, &d);
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3125,12 +3130,16 @@ handle_printf_atsign (FILE *stream,
|
||||||
- (float) floatValue
|
- (float) floatValue
|
||||||
{
|
{
|
||||||
unichar buf[32];
|
unichar buf[32];
|
||||||
unsigned len = [self length];
|
|
||||||
double d = 0.0;
|
double d = 0.0;
|
||||||
|
NSRange r;
|
||||||
|
|
||||||
if (len > 32) len = 32;
|
setupWhitespace();
|
||||||
[self getCharacters: buf range: NSMakeRange(0, len)];
|
r = [self rangeOfCharacterFromSet: nonspace];
|
||||||
GSScanDouble(buf, len, &d);
|
if (NSNotFound == r.location) return 0.0;
|
||||||
|
r.length = [self length] - r.location;
|
||||||
|
if (r.length > 32) r.length = 32;
|
||||||
|
[self getCharacters: buf range: r];
|
||||||
|
GSScanDouble(buf, r.length, &d);
|
||||||
return (float)d;
|
return (float)d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3141,17 +3150,17 @@ handle_printf_atsign (FILE *stream,
|
||||||
*/
|
*/
|
||||||
- (int) intValue
|
- (int) intValue
|
||||||
{
|
{
|
||||||
return atoi([self lossyCString]);
|
return atoi([self UTF8String]);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSInteger) integerValue
|
- (NSInteger) integerValue
|
||||||
{
|
{
|
||||||
return atol([self lossyCString]);
|
return atol([self UTF8String]);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (long long) longLongValue
|
- (long long) longLongValue
|
||||||
{
|
{
|
||||||
return atoll([self lossyCString]);
|
return atoll([self UTF8String]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Working With Encodings
|
// Working With Encodings
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue