New headers

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3367 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 1998-12-02 20:14:34 +00:00
parent 7b825e0cde
commit 540821fe94
4 changed files with 331 additions and 0 deletions

View file

@ -0,0 +1,51 @@
/* Interface for NSDateFormatter for GNUStep
Copyright (C) 1998 Free Software Foundation, Inc.
Header Written by: Camille Troillard <tuscland@wanadoo.fr>
Created: November 1998
Modified by: Richard Frith-Macdonald <richard@brainstorm.co.uk>
This file is part of the GNUstep Base Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __NSDateFormatter_h_GNUSTEP_BASE_INCLUDE
#define __NSDateFormatter_h_GNUSTEP_BASE_INCLUDE
#include <Foundation/NSObject.h>
#ifndef STRICT_OPENSTEP
@class NSString;
@interface NSDateFormatter : NSFormatter <NSCoding, NSCopying>
{
NSString *dateFormat;
BOOL allowsNaturalLanguage;
}
/* Initializing an NSDateFormatter */
- (id) initWithDateFormat: (NSString *)format
allowNaturalLanguage: (BOOL)flag;
/* Determining Attributes */
- (BOOL) allowsNaturalLanguage;
- (NSString *) dateFormat;
@end
#endif
#endif /* _NSDateFormatter_h_GNUSTEP_BASE_INCLUDE */

View file

@ -0,0 +1,104 @@
/* NSDecimal types and functions
Copyright (C) 1998 Free Software Foundation, Inc.
Written by: Richard Frith-Macdonald <richard@brainstorm.co.uk>
Created: November 1998
This file is part of the GNUstep Base Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __NSDecimal_h_GNUSTEP_BASE_INCLUDE
#define __NSDecimal_h_GNUSTEP_BASE_INCLUDE
#ifndef STRICT_OPENSTEP
typedef enum {
NSRoundDown,
NSRoundUp,
NSRoundPlain, /* Round .5 up */
NSRoundBankers /* Make last digit even */
} NSRoundingMode;
typedef enum {
NSCalculationNoError = 0,
NSCalculationUnderflow, /* result became zero */
NSCalculationOverflow,
NSCalculationLossOfPrecision,
NSCalculationDivideByZero
} NSCalculationError;
/*
* Give a precision of at least 38 decimal digits
* requires 128 bits.
*/
#define NSDecimalMaxSize (16/sizeof(int))
#define NSDecimalNoScale -1
typedef struct {
char exponent; /* Signed exponent - -128 to 127 */
char length; /* digits in mantissa. */
BOOL isNegative; /* Is this negative? */
BOOL validNumber; /* Is this a valid number? */
unsigned int mantissa[NSDecimalMaxSize];
} NSDecimal;
static inline BOOL
NSDecimalIsNotANumber(const NSDecimal *decimal)
{
return (decimal->validNumber == NO);
}
extern void
NSDecimalCopy(NSDecimal *destination, const NSDecimal *source);
extern void
NSDecimalCompact(NSDecimal *number);
extern NSComparisonResult
NSDecimalCompare(const NSDecimal *leftOperand, const NSDecimal *rightOperand);
extern void
NSDecimalRound(NSDecimal *result, const NSDecimal *number, int scale, NSRoundingMode mode);
extern NSCalculationError
NSDecimalNormalize(NSDecimal *n1, NSDecimal *n2, NSRoundingMode mode);
extern NSCalculationError
NSDecimalAdd(NSDecimal *result, const NSDecimal *left, const NSDecimal *right, NSRoundingMode mode);
extern NSCalculationError
NSDecimalSubtract(NSDecimal *result, const NSDecimal *left, const NSDecimal *right, NSRoundingMode mode);
extern NSCalculationError
NSDecimalMultiply(NSDecimal *result, const NSDecimal *l, const NSDecimal *r, NSRoundingMode mode);
extern NSCalculationError
NSDecimalDivide(NSDecimal *result, const NSDecimal *l, const NSDecimal *rr, NSRoundingMode mode);
extern NSCalculationError
NSDecimalPower(NSDecimal *result, const NSDecimal *n, unsigned power, NSRoundingMode mode);
extern NSCalculationError
NSDecimalMultiplyByPowerOf10(NSDecimal *result, const NSDecimal *n, short power, NSRoundingMode mode);
extern NSString*
NSDecimalString(const NSDecimal *decimal, NSDictionary *locale);
#endif
#endif

View file

@ -0,0 +1,52 @@
/* Interface of NSDecimalNumber class
Copyright (C) 1998 Free Software Foundation, Inc.
Written by: Richard Frith-Macdonald <richard@brainstorm.co.uk>
Created: November 1998
This file is part of the GNUstep Base Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __NSDecimalNumber_h_GNUSTEP_BASE_INCLUDE
#define __NSDecimalNumber_h_GNUSTEP_BASE_INCLUDE
#include <Foundation/NSObject.h>
#ifndef STRICT_OPENSTEP
#include <Foundation/NSDecimal.h>
@class NSDecimalNumber;
@protocol NSDecimalNumberBehaviors
- (NSDecimalNumber*) exceptionDuringOperation: (SEL)method
error: (NSCalculationError)error
leftOperand: (NSDecimalNumber*)leftOperand
rightOperand: (NSDecimalNumber*)rightOperand;
- (NSRoundingMode) roundingMode;
- (short) scale;
@end
@interface NSDecimalNumber : NSObject <NSCopying, NSCoding>
{
}
@end
#endif
#endif

124
Source/NSDateFormatter.m Normal file
View file

@ -0,0 +1,124 @@
/* Implementation of NSDateFormatter class
Copyright (C) 1998 Free Software Foundation, Inc.
Written by: Richard Frith-Macdonald <richard@brainstorm.co.uk>
Created: December 1998
This file is part of the GNUstep Base Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <config.h>
#include <Foundation/NSDate.h>
#include <Foundation/NSFormatter.h>
#include <Foundation/NSDateFormatter.h>
#include <Foundation/NSString.h>
#include <Foundation/NSCoder.h>
@implementation NSDateFormatter
- (BOOL) allowsNaturalLanguage
{
return allowsNaturalLanguage;
}
- (NSAttributedString*) attributedStringForObjectValue: (id)anObject
withDefaultAttributes: (NSDictionary*)attr
{
return nil;
}
- (id) copyWithZone: (NSZone*)zone
{
NSDateFormatter *other = (id)NSCopyObject(self, 0, zone);
[other->dateFormat retain];
return other;
}
- (NSString*) dateFormat
{
return dateFormat;
}
- (NSString*) editingStringForObjectValue: (id)anObject
{
return [self stringForObjectValue: anObject];
}
- (void) encodeWithCoder: (NSCoder*)aCoder
{
[aCoder encodeValuesOfObjCTypes: "@C", &dateFormat, &allowsNaturalLanguage];
}
- (BOOL) getObjectValue: (id*)anObject
forString: (NSString*)string
errorDescription: (NSString**)error
{
NSCalendarDate *d;
d = [NSCalendarDate dateWithString: string calendarFormat: dateFormat];
if (d == nil)
{
if (allowsNaturalLanguage)
{
d = [NSCalendarDate dateWithNaturalLanguageString: string];
}
if (d == nil)
{
*error = @"Couldn't convert to date";
return NO;
}
}
*anObject = d;
return YES;
}
- (id) initWithCoder: (NSCoder*)aCoder
{
[aCoder decodeValuesOfObjCTypes: "@C", &dateFormat, &allowsNaturalLanguage];
return self;
}
- (id) initWithDateFormat: (NSString *)format
allowNaturalLanguage: (BOOL)flag
{
dateFormat = [format copy];
allowsNaturalLanguage = flag;
return self;
}
- (BOOL) isPartialStringValid: (NSString*)partialString
newEditingString: (NSString**)newString
errorDescription: (NSString**)error
{
*newString = nil;
*error = nil;
return YES;
}
- (NSString*) stringForObjectValue: (id)anObject
{
if ([anObject isKindOfClass: [NSDate class]] == NO)
{
return nil;
}
return [anObject descriptionWithCalendarFormat: dateFormat
timeZone: [NSTimeZone defaultTimeZone]
locale: nil];
}
@end