From e9286f769724c3c1b1246e378500fe7f7070f584 Mon Sep 17 00:00:00 2001 From: CaS Date: Mon, 12 Nov 2001 13:01:09 +0000 Subject: [PATCH] Some formatting changes git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@11371 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 4 + Documentation/gsdoc/NSNumber.gsdoc | 35 ++++++ Documentation/gsdoc/NSNumber.html | 38 +++++++ Documentation/gsdoc/NSString.gsdoc | 22 +++- Documentation/gsdoc/NSString.html | 175 ++++++++++++++++------------- Headers/gnustep/base/NSString.h | 4 +- Source/NSConcreteNumber.m | 31 ++--- Source/NSNumber.m | 59 +++++++--- Source/NSString.m | 11 +- 9 files changed, 260 insertions(+), 119 deletions(-) diff --git a/ChangeLog b/ChangeLog index ca225d3df..ad09b28bc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,10 @@ * Source/NSConcreteNumber.m: ditto * Source/GSFormat.m: Fix bug in formatting short integers - was trying to treat them as full sized. + * headers/Foundation/NSString.h: Fix error in initWithFormat:locale:,... + * Source/NSString.m: ditto ... was missing varargs + * Documentation/gsdoc/NSNumber.gsdoc: document changes. + * Documentation/gsdoc/NSString.gsdoc: document changes. 2001-11-09 Richard Frith-Macdonald diff --git a/Documentation/gsdoc/NSNumber.gsdoc b/Documentation/gsdoc/NSNumber.gsdoc index 3065f2b66..84833a09d 100644 --- a/Documentation/gsdoc/NSNumber.gsdoc +++ b/Documentation/gsdoc/NSNumber.gsdoc @@ -120,12 +120,46 @@ description + Invokes descriptionWithLocale: using nil locale. descriptionWithLocale: aLocale +

+ Produces a string representation of the number. For a boolean + this will be either 'true' or 'false'. For other numbers the + format is produced using the initWithFormat:locale:... method + of NSString, and the format depends on the type of number as + follows - +

+ + char + %i + short + %hi + int + %i + long + %li + long long + %li + unsigned char + %u + unsigned short + %hu + unsigned int + %u + unsigned long + %lu + unsigned long long + %lu + float + %0.7g + double + %0.16g +
@@ -245,6 +279,7 @@ stringValue + Expivalent to descriptionWithLocale: using a nil locale. diff --git a/Documentation/gsdoc/NSNumber.html b/Documentation/gsdoc/NSNumber.html index fe41cb1e5..5f0e0e840 100644 --- a/Documentation/gsdoc/NSNumber.html +++ b/Documentation/gsdoc/NSNumber.html @@ -163,11 +163,48 @@

description

- (NSString*) description;
+ Invokes descriptionWithLocale: using nil locale.

descriptionWithLocale:

- (NSString*) descriptionWithLocale: (NSDictionary*)aLocale;
+

+ + Produces a string representation of the number. For a boolean + this will be either 'true' or 'false'. For other numbers the + format is produced using the initWithFormat:locale:... method + of NSString, and the format depends on the type of number as + follows - +

+ +
+
char +
%i +
short +
%hi +
int +
%i +
long +
%li +
long long +
%li +
unsigned char +
%u +
unsigned short +
%hu +
unsigned int +
%u +
unsigned long +
%lu +
unsigned long long +
%lu +
float +
%0.7g +
double +
%0.16g +
+

doubleValue

@@ -273,6 +310,7 @@

stringValue

- (NSString*) stringValue;
+ Expivalent to descriptionWithLocale: using a nil locale.

unsignedCharValue

diff --git a/Documentation/gsdoc/NSString.gsdoc b/Documentation/gsdoc/NSString.gsdoc index 2fbfea50d..e109640b4 100644 --- a/Documentation/gsdoc/NSString.gsdoc +++ b/Documentation/gsdoc/NSString.gsdoc @@ -449,8 +449,10 @@ initWithFormat: - format, + format + + Invokes initWithFormat:locale:arguments with a nil locale. @@ -460,13 +462,29 @@ arguments: argList + Invokes initWithFormat:locale:arguments with a nil locale.
initWithFormat: format + locale: + dictionary + + Initialises the string using the specified format and local + to format the following arguments. + + + + + initWithFormat: + format + arguments: + argList + + Invokes initWithFormat:locale:,... with a nil locale. @@ -478,6 +496,8 @@ arguments: argList + Initialises the string using the specified format and local + to format the following arguments.
diff --git a/Documentation/gsdoc/NSString.html b/Documentation/gsdoc/NSString.html index 3a256a54b..f2cf3977b 100644 --- a/Documentation/gsdoc/NSString.html +++ b/Documentation/gsdoc/NSString.html @@ -62,13 +62,13 @@
  • +availableStringEncodings
  • +defaultCStringEncoding
  • +getLineStart:end:contentsEnd: -
  • +lineRangeForRange: +
  • +lineRangeForRange:
  • +localizedNameOfStringEncoding:
  • +localizedStringWithFormat:
  • +pathWithComponents:
  • +string -
  • +stringWithCString:
  • +stringWithCString: +
  • +stringWithCString:
  • +stringWithCharacters:length:
  • +stringWithContentsOfFile:
  • +stringWithFormat: @@ -95,59 +95,60 @@
  • -getCString:
  • -getCString:maxLength:
  • -getCString:maxLength:range:remainingRange: -
  • -getCharacters:
  • -getCharacters: +
  • -getCharacters:
  • -getFileSystemRepresentation:maxLength:
  • -hasPrefix:
  • -hasSuffix:
  • -hash
  • -init -
  • -initWithCString:
  • -initWithCString: +
  • -initWithCString:
  • -initWithCStringNoCopy:length:freeWhenDone:
  • -initWithCharacters:
  • -initWithCharactersNoCopy:length:freeWhenDone:
  • -initWithContentsOfFile:
  • -initWithData:encoding:
  • -initWithFormat: -
  • -initWithFormat: +
  • -initWithFormat:arguments:
  • -initWithFormat:arguments: -
  • -initWithFormat:locale:arguments: -
  • -initWithString: -
  • -intValue -
  • -isAbsolutePath -
  • -isEqualToString: -
  • -lastPathComponent -
  • -length -
  • -lossyCString -
  • -lowercaseString -
  • -pathComponents -
  • -pathExtension -
  • -propertyList -
  • -propertyListFromStringsFileFormat -
  • -rangeOfCharacterFromSet: -
  • -rangeOfCharacterFromSet:options: -
  • -rangeOfCharacterFromSet:options:range: -
  • -rangeOfComposedCharacterSequenceAtIndex: -
  • -rangeOfString: -
  • -rangeOfString:options: -
  • -rangeOfString:options:range: -
  • -smallestEncoding -
  • -stringByAbbreviatingWithTildeInPath -
  • -stringByAppendingFormat: -
  • -stringByAppendingPathComponent: -
  • -stringByAppendingPathExtension: -
  • -stringByAppendingString: -
  • -stringByDeletingLastPathComponent -
  • -stringByDeletingPathExtension -
  • -stringByExpandingTildeInPath -
  • -stringByReplacingString:withString: -
  • -stringsByAppendingPaths: -
  • -substringFromIndex: -
  • -substringToIndex: -
  • -substringWithRange: -
  • -uppercaseString -
  • -writeToFile:atomically: +
  • -initWithFormat:locale: +
  • -initWithFormat:locale:arguments: +
  • -initWithString: +
  • -intValue +
  • -isAbsolutePath +
  • -isEqualToString: +
  • -lastPathComponent +
  • -length +
  • -lossyCString +
  • -lowercaseString +
  • -pathComponents +
  • -pathExtension +
  • -propertyList +
  • -propertyListFromStringsFileFormat +
  • -rangeOfCharacterFromSet: +
  • -rangeOfCharacterFromSet:options: +
  • -rangeOfCharacterFromSet:options:range: +
  • -rangeOfComposedCharacterSequenceAtIndex: +
  • -rangeOfString: +
  • -rangeOfString:options: +
  • -rangeOfString:options:range: +
  • -smallestEncoding +
  • -stringByAbbreviatingWithTildeInPath +
  • -stringByAppendingFormat: +
  • -stringByAppendingPathComponent: +
  • -stringByAppendingPathExtension: +
  • -stringByAppendingString: +
  • -stringByDeletingLastPathComponent +
  • -stringByDeletingPathExtension +
  • -stringByExpandingTildeInPath +
  • -stringByReplacingString:withString: +
  • -stringsByAppendingPaths: +
  • -substringFromIndex: +
  • -substringToIndex: +
  • -substringWithRange: +
  • -uppercaseString +
  • -writeToFile:atomically:

    Class Methods

    availableStringEncodings

    @@ -257,7 +258,7 @@
    -

    lineRangeForRange:

    +

    lineRangeForRange:

    + (NSRange) lineRangeForRange: (NSRange)aRange;
    @@ -452,122 +453,134 @@

    initWithFormat:

    -- (id) initWithFormat: (NSString*)format,;
    +- (id) initWithFormat: (NSString*)format, ...;
    + Invokes initWithFormat:locale:arguments with a nil locale.

    initWithFormat:arguments:

    - (id) initWithFormat: (NSString*)format arguments: (va_list)argList;
    + Invokes initWithFormat:locale:arguments with a nil locale.
    -

    initWithFormat:

    -- (id) initWithFormat: (NSString*)format;
    +

    initWithFormat:locale:

    +- (id) initWithFormat: (NSString*)format locale: (NSDictionary*)dictionary, ...;
    + Initialises the string using the specified format and local + to format the following arguments.
    -

    initWithFormat:locale:arguments:

    +

    initWithFormat:arguments:

    +- (id) initWithFormat: (NSString*)format arguments: (va_list)argList;
    + + Invokes initWithFormat:locale:,... with a nil locale. + +
    +

    initWithFormat:locale:arguments:

    - (id) initWithFormat: (NSString*)format locale: (NSDictionary*)dictionary arguments: (va_list)argList;
    + Initialises the string using the specified format and local + to format the following arguments.
    -

    initWithString:

    +

    initWithString:

    - (id) initWithString: (NSString*)aString;

    -

    intValue

    +

    intValue

    - (int) intValue;

    -

    isAbsolutePath

    +

    isAbsolutePath

    - (BOOL) isAbsolutePath;

    -

    isEqualToString:

    +

    isEqualToString:

    - (BOOL) isEqualToString: (NSString*)aString;

    -

    lastPathComponent

    +

    lastPathComponent

    - (NSString*) lastPathComponent;

    -

    length

    +

    length

    - (unsigned int) length;

    -

    lossyCString

    +

    lossyCString

    - (const char*) lossyCString;

    -

    lowercaseString

    +

    lowercaseString

    - (NSString*) lowercaseString;
    Returns a copy of the receiver with all characters converted to lowercase.
    -

    pathComponents

    +

    pathComponents

    - (NSArray*) pathComponents;

    -

    pathExtension

    +

    pathExtension

    - (NSString*) pathExtension;

    -

    propertyList

    +

    propertyList

    - (id) propertyList;

    -

    propertyListFromStringsFileFormat

    +

    propertyListFromStringsFileFormat

    - (NSDictionary*) propertyListFromStringsFileFormat;

    -

    rangeOfCharacterFromSet:

    +

    rangeOfCharacterFromSet:

    - (NSRange) rangeOfCharacterFromSet: (NSCharacterSet*)aSet;

    -

    rangeOfCharacterFromSet:options:

    +

    rangeOfCharacterFromSet:options:

    - (NSRange) rangeOfCharacterFromSet: (NSCharacterSet*)aSet options: (unsigned int)mask;

    -

    rangeOfCharacterFromSet:options:range:

    +

    rangeOfCharacterFromSet:options:range:

    - (NSRange) rangeOfCharacterFromSet: (NSCharacterSet*)aSet options: (unsigned int)mask range: (NSRange)aRange;

    -

    rangeOfComposedCharacterSequenceAtIndex:

    +

    rangeOfComposedCharacterSequenceAtIndex:

    - (NSRange) rangeOfComposedCharacterSequenceAtIndex: (unsigned int)anIndex;

    -

    rangeOfString:

    +

    rangeOfString:

    - (NSRange) rangeOfString: (NSString*)aString;
    Invokes rangeOfString:options: with the options mask set to zero.
    -

    rangeOfString:options:

    +

    rangeOfString:options:

    - (NSRange) rangeOfString: (NSString*)aString options: (unsigned int)mask;
    Invokes rangeOfString:options:range with the range set set to the range of the whole of the reciever.
    -

    rangeOfString:options:range:

    +

    rangeOfString:options:range:

    - (NSRange) rangeOfString: (NSString*)subString options: (unsigned int)mask range: (NSRange)aRange;
    Returns the range giving the location and length of the first @@ -592,52 +605,52 @@
    -

    smallestEncoding

    +

    smallestEncoding

    - (NSStringEncoding) smallestEncoding;

    -

    stringByAbbreviatingWithTildeInPath

    +

    stringByAbbreviatingWithTildeInPath

    - (NSString*) stringByAbbreviatingWithTildeInPath;

    -

    stringByAppendingFormat:

    +

    stringByAppendingFormat:

    - (NSString*) stringByAppendingFormat: (NSString*)format,;

    -

    stringByAppendingPathComponent:

    +

    stringByAppendingPathComponent:

    - (NSString*) stringByAppendingPathComponent: (NSString*)aString;

    -

    stringByAppendingPathExtension:

    +

    stringByAppendingPathExtension:

    - (NSString*) stringByAppendingPathExtension: (NSString*)string;

    -

    stringByAppendingString:

    +

    stringByAppendingString:

    - (NSString*) stringByAppendingString: (NSString*)aString;

    -

    stringByDeletingLastPathComponent

    +

    stringByDeletingLastPathComponent

    - (NSString*) stringByDeletingLastPathComponent;

    -

    stringByDeletingPathExtension

    +

    stringByDeletingPathExtension

    - (NSString*) stringByDeletingPathExtension;

    -

    stringByExpandingTildeInPath

    +

    stringByExpandingTildeInPath

    - (NSString*) stringByExpandingTildeInPath;

    -

    stringByReplacingString:withString:

    +

    stringByReplacingString:withString:

    - (NSString*) stringByReplacingString: (NSString*)aString withString: (NSString*)replacement;
    Standards: GNUstep NotMacOS-X NotOpenStep
    @@ -648,34 +661,34 @@ Standards: GNUstep NotMacOS-X NotOpenStep
    not considered to exist within the receiver.
    -

    stringsByAppendingPaths:

    +

    stringsByAppendingPaths:

    - (NSArray*) stringsByAppendingPaths: (NSArray*)paths;

    -

    substringFromIndex:

    +

    substringFromIndex:

    - (NSString*) substringFromIndex: (unsigned int)anIndex;

    -

    substringToIndex:

    +

    substringToIndex:

    - (NSString*) substringToIndex: (unsigned int)anIndex;

    -

    substringWithRange:

    +

    substringWithRange:

    - (NSString*) substringWithRange: (NSRange)aRange;

    -

    uppercaseString

    +

    uppercaseString

    - (NSString*) uppercaseString;
    Returns a copy of the receiver with all characters converted to uppercase.
    -

    writeToFile:atomically:

    +

    writeToFile:atomically:

    - (BOOL) writeToFile: (NSString*)path atomically: (BOOL)flag;
    diff --git a/Headers/gnustep/base/NSString.h b/Headers/gnustep/base/NSString.h index 4ae8d72fc..bb273cbc3 100644 --- a/Headers/gnustep/base/NSString.h +++ b/Headers/gnustep/base/NSString.h @@ -123,7 +123,7 @@ enum { length: (unsigned int)length; - (id) initWithCString: (const char*)byteString; - (id) initWithString: (NSString*)string; -- (id) initWithFormat: (NSString*)format,...; +- (id) initWithFormat: (NSString*)format, ...; - (id) initWithFormat: (NSString*)format arguments: (va_list)argList; - (id) initWithData: (NSData*)data @@ -252,7 +252,7 @@ enum { + (id) stringWithContentsOfURL: (NSURL*)anURL; + (id) stringWithUTF8String: (const char*)bytes; - (id) initWithFormat: (NSString*)format - locale: (NSDictionary*)dictionary; + locale: (NSDictionary*)dictionary, ...; - (id) initWithFormat: (NSString*)format locale: (NSDictionary*)dictionary arguments: (va_list)argList; diff --git a/Source/NSConcreteNumber.m b/Source/NSConcreteNumber.m index 9bf2f1783..096ce5e70 100644 --- a/Source/NSConcreteNumber.m +++ b/Source/NSConcreteNumber.m @@ -377,30 +377,35 @@ { #if TYPE_ORDER == 0 return (data) ? @"true" : @"false"; -#elif TYPE_ORDER == 1 - return [NSString stringWithFormat: @"%i", (int)data]; +#else + NSString *result = [NSString alloc]; + +#if TYPE_ORDER == 1 + result = [result initWithFormat: @"%i" locale: locale, (int)data]; #elif TYPE_ORDER == 2 - return [NSString stringWithFormat: @"%u", (unsigned int)data]; + result = [result initWithFormat: @"%u" locale: locale, (unsigned int)data]; #elif TYPE_ORDER == 3 - return [NSString stringWithFormat: @"%hi", (short int)data]; + result = [result initWithFormat: @"%hi" locale: locale, data]; #elif TYPE_ORDER == 4 - return [NSString stringWithFormat: @"%hu", (unsigned short int)data]; + result = [result initWithFormat: @"%hu" locale: locale, data]; #elif TYPE_ORDER == 5 - return [NSString stringWithFormat: @"%i", data]; + result = [result initWithFormat: @"%i" locale: locale, data]; #elif TYPE_ORDER == 6 - return [NSString stringWithFormat: @"%u", data]; + result = [result initWithFormat: @"%u" locale: locale, data]; #elif TYPE_ORDER == 7 - return [NSString stringWithFormat: @"%li", data]; + result = [result initWithFormat: @"%li" locale: locale, data]; #elif TYPE_ORDER == 8 - return [NSString stringWithFormat: @"%lu", data]; + result = [result initWithFormat: @"%lu" locale: locale, data]; #elif TYPE_ORDER == 9 - return [NSString stringWithFormat: @"%lli", data]; + result = [result initWithFormat: @"%lli" locale: locale, data]; #elif TYPE_ORDER == 10 - return [NSString stringWithFormat: @"%llu", data]; + result = [result initWithFormat: @"%llu" locale: locale, data]; #elif TYPE_ORDER == 11 - return [NSString stringWithFormat: @"%0.7g", (double)data]; + result = [result initWithFormat: @"%0.7g" locale: locale, (double)data]; #elif TYPE_ORDER == 12 - return [NSString stringWithFormat: @"%0.16g", data]; + result = [result initWithFormat: @"%0.16g" locale: locale, data]; +#endif + return AUTORELEASE(result); #endif } diff --git a/Source/NSNumber.m b/Source/NSNumber.m index 0a58da4d0..b4bf4dccc 100644 --- a/Source/NSNumber.m +++ b/Source/NSNumber.m @@ -666,11 +666,12 @@ static Class doubleNumberClass; - (NSString*) descriptionWithLocale: (NSDictionary*)locale { + NSString *result = nil; + if (GSObjCClass(self) == abstractClass) { [NSException raise: NSInternalInconsistencyException format: @"descriptionWithLocale: for abstract NSNumber"]; - return nil; } else { @@ -680,48 +681,74 @@ static Class doubleNumberClass; { case 0: return [self boolValue] ? @"true" : @"false"; + break; + case 1: - return [NSString stringWithFormat: @"%i", + result = [[NSString alloc] initWithFormat: @"%i" locale: locale, (int)[self charValue]]; + break; + case 2: - return [NSString stringWithFormat: @"%u", + result = [[NSString alloc] initWithFormat: @"%u" locale: locale, (unsigned int)[self unsignedCharValue]]; + break; + case 3: - return [NSString stringWithFormat: @"%hi", - (short int)[self shortValue]]; + result = [[NSString alloc] initWithFormat: @"%hi" locale: locale, + [self shortValue]]; + break; + case 4: - return [NSString stringWithFormat: @"%hu", - (unsigned short int)[self unsignedShortValue]]; + result = [[NSString alloc] initWithFormat: @"%hu" locale: locale, + [self unsignedShortValue]]; + break; + case 5: - return [NSString stringWithFormat: @"%i", + result = [[NSString alloc] initWithFormat: @"%i" locale: locale, [self intValue]]; + break; + case 6: - return [NSString stringWithFormat: @"%u", + result = [[NSString alloc] initWithFormat: @"%u" locale: locale, [self unsignedIntValue]]; + break; + case 7: - return [NSString stringWithFormat: @"%li", + result = [[NSString alloc] initWithFormat: @"%li" locale: locale, [self longValue]]; + break; + case 8: - return [NSString stringWithFormat: @"%lu", + result = [[NSString alloc] initWithFormat: @"%lu" locale: locale, [self unsignedLongValue]]; + break; + case 9: - return [NSString stringWithFormat: @"%lli", + result = [[NSString alloc] initWithFormat: @"%lli" locale: locale, [self longLongValue]]; + break; + case 10: - return [NSString stringWithFormat: @"%llu", + result = [[NSString alloc] initWithFormat: @"%llu" locale: locale, [self unsignedLongLongValue]]; + break; + case 11: - return [NSString stringWithFormat: @"%0.7g", + result = [[NSString alloc] initWithFormat: @"%0.7g" locale: locale, (double)[self floatValue]]; + break; + case 12: - return [NSString stringWithFormat: @"%0.16g", + result = [[NSString alloc] initWithFormat: @"%0.16g" locale: locale, [self doubleValue]]; + break; + default: [NSException raise: NSInvalidArgumentException format: @"unknown number type value for description"]; - return nil; } } + return AUTORELEASE(result); } /* All the rest of these methods must be implemented by a subclass */ diff --git a/Source/NSString.m b/Source/NSString.m index c9741b05e..167c60cc3 100644 --- a/Source/NSString.m +++ b/Source/NSString.m @@ -723,14 +723,13 @@ handle_printf_atsign (FILE *stream, } - (id) initWithFormat: (NSString*)format - locale: (NSDictionary*)locale + locale: (NSDictionary*)locale, ... { - va_list ap; - /* - * Dummy variable 'ap' is unused, but needs to be present because on - * some machines we can't just pass a null as a va_list - */ + va_list ap; + va_start(ap, locale); return [self initWithFormat: format locale: locale arguments: ap]; + va_end(ap); + return self; } - (id) initWithFormat: (NSString*)format