mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-13 01:20:57 +00:00
Added basic implementation for missing methods
[stringWithUTF8String:], [initWithUTF8String:], [UTF8String], [stringWithContentsOfURL:], [initWithContentsOfURL:], [writeToURL:atomically:], [localizedCaseInsensitiveCompare:], [localizedCompare:], [compare:options:range:locale:] git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@7488 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
6b8effbca2
commit
aa261b90b6
1 changed files with 81 additions and 0 deletions
|
@ -308,12 +308,24 @@ handle_printf_atsign (FILE *stream,
|
||||||
NSDefaultMallocZone()] initWithCString: byteString length: length]);
|
NSDefaultMallocZone()] initWithCString: byteString length: length]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (id)stringWithUTF8String:(const char *)bytes
|
||||||
|
{
|
||||||
|
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
|
||||||
|
initWithUTF8String: bytes]);
|
||||||
|
}
|
||||||
|
|
||||||
+ (id) stringWithContentsOfFile: (NSString *)path
|
+ (id) stringWithContentsOfFile: (NSString *)path
|
||||||
{
|
{
|
||||||
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
|
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
|
||||||
initWithContentsOfFile: path]);
|
initWithContentsOfFile: path]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (id) stringWithContentsOfURL: (NSURL *)url
|
||||||
|
{
|
||||||
|
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
|
||||||
|
initWithContentsOfURL: url]);
|
||||||
|
}
|
||||||
|
|
||||||
+ (id) stringWithFormat: (NSString*)format,...
|
+ (id) stringWithFormat: (NSString*)format,...
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
@ -459,6 +471,12 @@ handle_printf_atsign (FILE *stream,
|
||||||
fromZone: z];
|
fromZone: z];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (id) initWithUTF8String:(const char *)bytes
|
||||||
|
{
|
||||||
|
[self subclassResponsibility: _cmd];
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
- (id) initWithFormat: (NSString*)format,...
|
- (id) initWithFormat: (NSString*)format,...
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
@ -847,6 +865,24 @@ handle_printf_atsign (FILE *stream,
|
||||||
return [self initWithData: d encoding: enc];
|
return [self initWithData: d encoding: enc];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (id) initWithContentsOfURL: (NSURL*)url
|
||||||
|
{
|
||||||
|
NSStringEncoding enc;
|
||||||
|
NSData *d = [NSData_class dataWithContentsOfURL: url];
|
||||||
|
const unsigned char *test;
|
||||||
|
|
||||||
|
if (d == nil)
|
||||||
|
return nil;
|
||||||
|
if ([d length] < 2)
|
||||||
|
return @"";
|
||||||
|
test = [d bytes];
|
||||||
|
if (test && (((test[0]==0xFF) && (test[1]==0xFE)) || ((test[1]==0xFF) && (test[0]==0xFE))))
|
||||||
|
enc = NSUnicodeStringEncoding;
|
||||||
|
else
|
||||||
|
enc = [NSString defaultCStringEncoding];
|
||||||
|
return [self initWithData: d encoding: enc];
|
||||||
|
}
|
||||||
|
|
||||||
- (id) init
|
- (id) init
|
||||||
{
|
{
|
||||||
self = [super init];
|
self = [super init];
|
||||||
|
@ -1619,6 +1655,16 @@ handle_printf_atsign (FILE *stream,
|
||||||
return (const char*)[d bytes];
|
return (const char*)[d bytes];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (const char *)UTF8String
|
||||||
|
{
|
||||||
|
NSData *d;
|
||||||
|
|
||||||
|
// FIXME: This won't be NULL
|
||||||
|
d = [self dataUsingEncoding: NSUTF8StringEncoding
|
||||||
|
allowLossyConversion: NO];
|
||||||
|
return (const char*)[d bytes];
|
||||||
|
}
|
||||||
|
|
||||||
- (unsigned) cStringLength
|
- (unsigned) cStringLength
|
||||||
{
|
{
|
||||||
NSData *d;
|
NSData *d;
|
||||||
|
@ -2491,6 +2537,33 @@ handle_printf_atsign (FILE *stream,
|
||||||
range: ((NSRange){0, [self length]})];
|
range: ((NSRange){0, [self length]})];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSComparisonResult)compare:(NSString *)string
|
||||||
|
options:(unsigned)mask
|
||||||
|
range:(NSRange)compareRange
|
||||||
|
locale:(NSDictionary *)dict
|
||||||
|
{
|
||||||
|
// FIXME: This does only a normal compare
|
||||||
|
return [self compare: string
|
||||||
|
options: mask
|
||||||
|
range: compareRange];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSComparisonResult)localizedCompare:(NSString *)string
|
||||||
|
{
|
||||||
|
// FIXME: This does only a normal compare
|
||||||
|
return [self compare: string
|
||||||
|
options: 0
|
||||||
|
range: ((NSRange){0, [self length]})];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSComparisonResult)localizedCaseInsensitiveCompare:(NSString *)string
|
||||||
|
{
|
||||||
|
// FIXME: This does only a normal compare
|
||||||
|
return [self compare: string
|
||||||
|
options: NSCaseInsensitiveSearch
|
||||||
|
range: ((NSRange){0, [self length]})];
|
||||||
|
}
|
||||||
|
|
||||||
- (BOOL) writeToFile: (NSString*)filename
|
- (BOOL) writeToFile: (NSString*)filename
|
||||||
atomically: (BOOL)useAuxiliaryFile
|
atomically: (BOOL)useAuxiliaryFile
|
||||||
{
|
{
|
||||||
|
@ -2500,6 +2573,14 @@ handle_printf_atsign (FILE *stream,
|
||||||
return [d writeToFile: filename atomically: useAuxiliaryFile];
|
return [d writeToFile: filename atomically: useAuxiliaryFile];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL)writeToURL:(NSURL *)anURL atomically:(BOOL)atomically
|
||||||
|
{
|
||||||
|
id d;
|
||||||
|
if (!(d = [self dataUsingEncoding: [NSString defaultCStringEncoding]]))
|
||||||
|
d = [self dataUsingEncoding: NSUnicodeStringEncoding];
|
||||||
|
return [d writeToURL: anURL atomically: atomically];
|
||||||
|
}
|
||||||
|
|
||||||
- (void) descriptionWithLocale: (NSDictionary*)aLocale
|
- (void) descriptionWithLocale: (NSDictionary*)aLocale
|
||||||
indent: (unsigned)level
|
indent: (unsigned)level
|
||||||
to: (id<GNUDescriptionDestination>)output
|
to: (id<GNUDescriptionDestination>)output
|
||||||
|
|
Loading…
Reference in a new issue