mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 09:04:13 +00:00
Add NSByteCountFormatter.[hm] class.
This commit is contained in:
parent
c44e2b5bf8
commit
bb117a17db
4 changed files with 298 additions and 0 deletions
123
Headers/Foundation/NSByteCountFormatter.h
Normal file
123
Headers/Foundation/NSByteCountFormatter.h
Normal file
|
@ -0,0 +1,123 @@
|
|||
/* Definition of class NSByteCountFormatter
|
||||
Copyright (C) 2019 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Gregory Casamento <greg.casamento@gmail.com>
|
||||
Date: July 2019
|
||||
|
||||
This file is part of the GNUstep Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser 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 Lesser General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef _NSByteCountFormatter_h_GNUSTEP_BASE_INCLUDE
|
||||
#define _NSByteCountFormatter_h_GNUSTEP_BASE_INCLUDE
|
||||
#import <GNUstepBase/GSVersionMacros.h>
|
||||
|
||||
#import <Foundation/NSObject.h>
|
||||
#import <Foundation/NSFormatter.h>
|
||||
#import <Foundation/NSDecimalNumber.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
@class NSString, NSAttributedString, NSDictionary,
|
||||
NSError, NSLocale, NSNumber;
|
||||
|
||||
#if OS_API_VERSION(MAC_OS_X_VERSION_10_8, GS_API_LATEST)
|
||||
enum {
|
||||
NSByteCountFormatterUseDefault = 0,
|
||||
NSByteCountFormatterUseBytes = 1UL << 0,
|
||||
NSByteCountFormatterUseKB = 1UL << 1,
|
||||
NSByteCountFormatterUseMB = 1UL << 2,
|
||||
NSByteCountFormatterUseGB = 1UL << 3,
|
||||
NSByteCountFormatterUseTB = 1UL << 4,
|
||||
NSByteCountFormatterUsePB = 1UL << 5,
|
||||
NSByteCountFormatterUseEB = 1UL << 6,
|
||||
NSByteCountFormatterUseZB = 1UL << 7,
|
||||
NSByteCountFormatterUseYBOrHigher = 0x0FFUL << 8,
|
||||
NSByteCountFormatterUseAll = 0x0FFFFUL
|
||||
};
|
||||
typedef NSInteger NSByteCountFormatterUnits;
|
||||
|
||||
enum {
|
||||
NSByteCountFormatterCountStyleFile = 0,
|
||||
NSByteCountFormatterCountStyleMemory = 1,
|
||||
NSByteCountFormatterCountStyleDecimal = 2,
|
||||
NSByteCountFormatterCountStyleBinary = 3,
|
||||
};
|
||||
typedef NSInteger NSByteCountFormatterCountStyle;
|
||||
|
||||
@interface NSByteCountFormatter : NSFormatter
|
||||
{
|
||||
#if GS_EXPOSE(NSByteCountFormatter)
|
||||
#endif
|
||||
#if GS_NONFRAGILE
|
||||
# if defined(GS_NSByteCountFormatter_IVARS)
|
||||
@public
|
||||
GS_NSByteCountFormatter_IVARS;
|
||||
# endif
|
||||
#else
|
||||
/* Pointer to private additional data used to avoid breaking ABI
|
||||
* when we don't have the non-fragile ABI available.
|
||||
* Use this mechanism rather than changing the instance variable
|
||||
* layout (see Source/GSInternal.h for details).
|
||||
*/
|
||||
@private id _internal GS_UNUSED_IVAR;
|
||||
#endif
|
||||
}
|
||||
|
||||
- (NSFormattingContext) formattingContext;
|
||||
- (void) setFormattingContext: (NSFormattingContext)ctx;
|
||||
|
||||
- (NSByteCountFormatterCountStyle) countStyle;
|
||||
- (void) setCountStyle: (NSByteCountFormatterCountStyle)style;
|
||||
|
||||
- (BOOL) allowsNonnumericFormatting;
|
||||
- (void) setAllowsNonnumericFormatting: (BOOL)flag;
|
||||
|
||||
- (BOOL) includesActualByteCount;
|
||||
- (void) setIncludesActualByteCount: (BOOL)flag;
|
||||
|
||||
- (BOOL) adaptive;
|
||||
- (void) setAdaptive: (BOOL)flag;
|
||||
|
||||
- (NSByteCountFormatterUnits) allowedUnits;
|
||||
- (void) setAllowedUnits: (NSByteCountFormatterUnits)units;
|
||||
|
||||
- (BOOL) includesCount;
|
||||
- (void) setIncludesCount: (BOOL)flag;
|
||||
|
||||
- (BOOL) includesUnit;
|
||||
- (void) setIncludesUnit: (BOOL)flag;
|
||||
|
||||
- (BOOL) zeroPadsFractionDigits;
|
||||
- (void) setZeroPadsFractionDigits: (BOOL)flag;
|
||||
|
||||
/* Beta methods... not yet implemented.
|
||||
- (NSString *)stringForObjectValue: (id)obj;
|
||||
- (NSString *)stringFromMeasurement
|
||||
*/
|
||||
@end
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* GS_API_MACOSX */
|
||||
|
||||
#endif /* _NSByteCountFormatter_h_GNUSTEP_BASE_INCLUDE */
|
||||
|
|
@ -35,6 +35,23 @@
|
|||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum {
|
||||
NSFormattingContextUnknown = 0,
|
||||
NSFormattingContextDynamic,
|
||||
NSFormattingContextStandalone,
|
||||
NSFormattingContextListItem,
|
||||
NSFormattingContextBeginningOfSentence,
|
||||
NSFormattingContextMiddleOfSentence,
|
||||
};
|
||||
typedef NSInteger NSFormattingContext;
|
||||
|
||||
enum {
|
||||
NSFormattingUnitStyleShort = 1,
|
||||
NSFormattingUnitStyleMedium,
|
||||
NSFormattingUnitStyleLong,
|
||||
};
|
||||
typedef NSInteger NSFormattingUnitStyle;
|
||||
|
||||
@class NSString, NSAttributedString, NSDictionary;
|
||||
|
||||
|
|
|
@ -195,6 +195,7 @@ NSAssertionHandler.m \
|
|||
NSAttributedString.m \
|
||||
NSAutoreleasePool.m \
|
||||
NSBundle.m \
|
||||
NSByteCountFormatter.m \
|
||||
NSCache.m \
|
||||
NSCachedURLResponse.m \
|
||||
NSCalendar.m \
|
||||
|
@ -371,6 +372,7 @@ NSArray.h \
|
|||
NSAttributedString.h \
|
||||
NSAutoreleasePool.h \
|
||||
NSBundle.h \
|
||||
NSByteCountFormatter.h \
|
||||
NSByteOrder.h \
|
||||
NSCache.h\
|
||||
NSCalendar.h \
|
||||
|
|
156
Source/NSByteCountFormatter.m
Normal file
156
Source/NSByteCountFormatter.m
Normal file
|
@ -0,0 +1,156 @@
|
|||
/* Definition of class NSByteCountFormatter
|
||||
Copyright (C) 2019 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Gregory Casamento <greg.casamento@gmail.com>
|
||||
Date: July 2019
|
||||
|
||||
This file is part of the GNUstep Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser 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 Lesser General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
#define GS_NSByteCountFormatter_IVARS \
|
||||
NSFormattingContext _formattingContext; \
|
||||
NSByteCountFormatterCountStyle _countStyle; \
|
||||
BOOL _allowsNonnumericFormatting; \
|
||||
BOOL _includesActualByteCount; \
|
||||
BOOL _adaptive; \
|
||||
NSByteCountFormatterUnits _allowedUnits; \
|
||||
BOOL _includesCount; \
|
||||
BOOL _includesUnit; \
|
||||
BOOL _zeroPadsFractionDigits;
|
||||
|
||||
#define EXPOSE_NSByteCountFormatter_IVARS 1
|
||||
|
||||
#import <Foundation/NSByteCountFormatter.h>
|
||||
#import <Foundation/NSString.h>
|
||||
#import <Foundation/NSAttributedString.h>
|
||||
#import <Foundation/NSDictionary.h>
|
||||
#import <Foundation/NSError.h>
|
||||
#import <Foundation/NSLocale.h>
|
||||
#import <Foundation/NSValue.h>
|
||||
|
||||
#define GSInternal NSByteCountFormatterInternal
|
||||
#include "GSInternal.h"
|
||||
GS_PRIVATE_INTERNAL(NSByteCountFormatter)
|
||||
|
||||
|
||||
@implementation NSByteCountFormatter
|
||||
|
||||
- (id) init
|
||||
{
|
||||
self = [super init];
|
||||
if(self == nil)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
GS_CREATE_INTERNAL(NSByteCountFormatter);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSFormattingContext) formattingContext
|
||||
{
|
||||
return _formattingContext;
|
||||
}
|
||||
|
||||
- (void) setFormattingContext: (NSFormattingContext)ctx
|
||||
{
|
||||
_formattingContext = ctx;
|
||||
}
|
||||
|
||||
- (NSByteCountFormatterCountStyle) countStyle
|
||||
{
|
||||
return _countStyle;
|
||||
}
|
||||
|
||||
- (void) setCountStyle: (NSByteCountFormatterCountStyle)style
|
||||
{
|
||||
_countStyle = style;
|
||||
}
|
||||
|
||||
- (BOOL) allowsNonnumericFormatting
|
||||
{
|
||||
return _allowsNonnumericFormatting;
|
||||
}
|
||||
|
||||
- (void) setAllowsNonnumericFormatting: (BOOL)flag
|
||||
{
|
||||
_allowsNonnumericFormatting = flag;
|
||||
}
|
||||
|
||||
- (BOOL) includesActualByteCount
|
||||
{
|
||||
return _includesActualByteCount;
|
||||
}
|
||||
|
||||
- (void) setIncludesActualByteCount: (BOOL)flag
|
||||
{
|
||||
_includesActualByteCount = flag;
|
||||
}
|
||||
|
||||
- (BOOL) adaptive
|
||||
{
|
||||
return _adaptive;
|
||||
}
|
||||
|
||||
- (void) setAdaptive: (BOOL)flag
|
||||
{
|
||||
_adaptive = flag;
|
||||
}
|
||||
|
||||
- (NSByteCountFormatterUnits) allowedUnits
|
||||
{
|
||||
return _allowedUnits;
|
||||
}
|
||||
|
||||
- (void) setAllowedUnits: (NSByteCountFormatterUnits)units
|
||||
{
|
||||
_allowedUnits = units;
|
||||
}
|
||||
|
||||
- (BOOL) includesCount
|
||||
{
|
||||
return _includesCount;
|
||||
}
|
||||
|
||||
- (void) setIncludesCount: (BOOL)flag
|
||||
{
|
||||
_includesCount = flag;
|
||||
}
|
||||
|
||||
- (BOOL) includesUnit
|
||||
{
|
||||
return _includesUnit;
|
||||
}
|
||||
|
||||
- (void) setIncludesUnit: (BOOL)flag
|
||||
{
|
||||
_includesUnit = flag;
|
||||
}
|
||||
|
||||
- (BOOL) zeroPadsFractionDigits
|
||||
{
|
||||
return _zeroPadsFractionDigits;
|
||||
}
|
||||
|
||||
- (void) setZeroPadsFractionDigits: (BOOL)flag
|
||||
{
|
||||
_zeroPadsFractionDigits = flag;
|
||||
}
|
||||
|
||||
@end
|
||||
|
Loading…
Reference in a new issue