mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 16:50:58 +00:00
More NSString changes.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@9462 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
b8bdc50640
commit
af46212b24
2 changed files with 36 additions and 16 deletions
|
@ -3,6 +3,12 @@
|
||||||
* Source/NSString.m: Implement ([-localizedStringWithFormat:]).
|
* Source/NSString.m: Implement ([-localizedStringWithFormat:]).
|
||||||
Fix ([-localizedCompare:]) and ([-localizedCaseInsensitiveCompare:]).
|
Fix ([-localizedCompare:]) and ([-localizedCaseInsensitiveCompare:]).
|
||||||
(They will work when ([-compare:options:range:locale:]) works.)
|
(They will work when ([-compare:options:range:locale:]) works.)
|
||||||
|
Fix ([-initWithContentsOfFile:]) and ([-initWithContentsOfURL:]) so
|
||||||
|
that they deal with 1 byte of data, and clarify Unicode BOM test with
|
||||||
|
new class variables byteOrderMark and byteOrderMarkSwapped.
|
||||||
|
In ([-initWithData:encoding:]) and ([-initWithCoder:]), don't treat
|
||||||
|
the default C string encoding the same as ASCII. GCC 3.0 supports
|
||||||
|
UTF-8 as a C string encoding, so this behavior is undesirable.
|
||||||
|
|
||||||
2001-03-19 Jonathan Gapen <jagapen@home.com>
|
2001-03-19 Jonathan Gapen <jagapen@home.com>
|
||||||
|
|
||||||
|
|
|
@ -222,6 +222,8 @@ pathSepMember(unichar c)
|
||||||
@implementation NSString
|
@implementation NSString
|
||||||
|
|
||||||
static NSStringEncoding _DefaultStringEncoding;
|
static NSStringEncoding _DefaultStringEncoding;
|
||||||
|
static const unichar byteOrderMark = 0xFFFE;
|
||||||
|
static const unichar byteOrderMarkSwapped = 0xFEFF;
|
||||||
|
|
||||||
#if HAVE_REGISTER_PRINTF_FUNCTION
|
#if HAVE_REGISTER_PRINTF_FUNCTION
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -998,8 +1000,7 @@ handle_printf_atsign (FILE *stream,
|
||||||
- (id) initWithData: (NSData*)data
|
- (id) initWithData: (NSData*)data
|
||||||
encoding: (NSStringEncoding)encoding
|
encoding: (NSStringEncoding)encoding
|
||||||
{
|
{
|
||||||
if ((encoding == [NSString defaultCStringEncoding])
|
if (encoding == NSASCIIStringEncoding)
|
||||||
|| (encoding == NSASCIIStringEncoding))
|
|
||||||
{
|
{
|
||||||
unsigned len = [data length];
|
unsigned len = [data length];
|
||||||
|
|
||||||
|
@ -1091,19 +1092,26 @@ handle_printf_atsign (FILE *stream,
|
||||||
{
|
{
|
||||||
NSStringEncoding enc;
|
NSStringEncoding enc;
|
||||||
NSData *d = [NSDataClass dataWithContentsOfFile: path];
|
NSData *d = [NSDataClass dataWithContentsOfFile: path];
|
||||||
const unsigned char *test;
|
unsigned int len = [d length];
|
||||||
|
const unichar *test;
|
||||||
|
|
||||||
if (d == nil)
|
if (d == nil)
|
||||||
return nil;
|
return nil;
|
||||||
if ([d length] < 2)
|
|
||||||
|
if (len == 0)
|
||||||
return @"";
|
return @"";
|
||||||
|
|
||||||
test = [d bytes];
|
test = [d bytes];
|
||||||
if (test != 0 &&
|
if ((test != NULL) && (len > 1)
|
||||||
(((test[0]==0xFF) && (test[1]==0xFE))
|
&& ((test[0] == byteOrderMark) || (test[0] == byteOrderMarkSwapped)))
|
||||||
|| ((test[1]==0xFF) && (test[0]==0xFE))))
|
{
|
||||||
enc = NSUnicodeStringEncoding;
|
/* somebody set up us the BOM! */
|
||||||
|
enc = NSUnicodeStringEncoding;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
enc = [NSString defaultCStringEncoding];
|
{
|
||||||
|
enc = [NSString defaultCStringEncoding];
|
||||||
|
}
|
||||||
return [self initWithData: d encoding: enc];
|
return [self initWithData: d encoding: enc];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1111,19 +1119,25 @@ handle_printf_atsign (FILE *stream,
|
||||||
{
|
{
|
||||||
NSStringEncoding enc;
|
NSStringEncoding enc;
|
||||||
NSData *d = [NSDataClass dataWithContentsOfURL: url];
|
NSData *d = [NSDataClass dataWithContentsOfURL: url];
|
||||||
|
unsigned int len = [d length];
|
||||||
const unsigned char *test;
|
const unsigned char *test;
|
||||||
|
|
||||||
if (d == nil)
|
if (d == nil)
|
||||||
return nil;
|
return nil;
|
||||||
if ([d length] < 2)
|
|
||||||
|
if (len == 0)
|
||||||
return @"";
|
return @"";
|
||||||
|
|
||||||
test = [d bytes];
|
test = [d bytes];
|
||||||
if (test != 0
|
if ((test != NULL) && (len > 1)
|
||||||
&& (((test[0]==0xFF) && (test[1]==0xFE))
|
&& ((test[0] == byteOrderMark) || (test[0] == byteOrderMarkSwapped)))
|
||||||
|| ((test[1]==0xFF) && (test[0]==0xFE))))
|
{
|
||||||
enc = NSUnicodeStringEncoding;
|
enc = NSUnicodeStringEncoding;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
enc = [NSString defaultCStringEncoding];
|
{
|
||||||
|
enc = [NSString defaultCStringEncoding];
|
||||||
|
}
|
||||||
return [self initWithData: d encoding: enc];
|
return [self initWithData: d encoding: enc];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3094,7 +3108,7 @@ handle_printf_atsign (FILE *stream,
|
||||||
length: count
|
length: count
|
||||||
freeWhenDone: YES];
|
freeWhenDone: YES];
|
||||||
}
|
}
|
||||||
else if (enc == NSASCIIStringEncoding || enc == _DefaultStringEncoding)
|
else if (enc == NSASCIIStringEncoding)
|
||||||
{
|
{
|
||||||
unsigned char *chars;
|
unsigned char *chars;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue