mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +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
dff26ccc9c
commit
6a580f0b53
2 changed files with 36 additions and 16 deletions
|
@ -3,6 +3,12 @@
|
|||
* Source/NSString.m: Implement ([-localizedStringWithFormat:]).
|
||||
Fix ([-localizedCompare:]) and ([-localizedCaseInsensitiveCompare:]).
|
||||
(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>
|
||||
|
||||
|
|
|
@ -222,6 +222,8 @@ pathSepMember(unichar c)
|
|||
@implementation NSString
|
||||
|
||||
static NSStringEncoding _DefaultStringEncoding;
|
||||
static const unichar byteOrderMark = 0xFFFE;
|
||||
static const unichar byteOrderMarkSwapped = 0xFEFF;
|
||||
|
||||
#if HAVE_REGISTER_PRINTF_FUNCTION
|
||||
#include <stdio.h>
|
||||
|
@ -998,8 +1000,7 @@ handle_printf_atsign (FILE *stream,
|
|||
- (id) initWithData: (NSData*)data
|
||||
encoding: (NSStringEncoding)encoding
|
||||
{
|
||||
if ((encoding == [NSString defaultCStringEncoding])
|
||||
|| (encoding == NSASCIIStringEncoding))
|
||||
if (encoding == NSASCIIStringEncoding)
|
||||
{
|
||||
unsigned len = [data length];
|
||||
|
||||
|
@ -1091,19 +1092,26 @@ handle_printf_atsign (FILE *stream,
|
|||
{
|
||||
NSStringEncoding enc;
|
||||
NSData *d = [NSDataClass dataWithContentsOfFile: path];
|
||||
const unsigned char *test;
|
||||
unsigned int len = [d length];
|
||||
const unichar *test;
|
||||
|
||||
if (d == nil)
|
||||
return nil;
|
||||
if ([d length] < 2)
|
||||
|
||||
if (len == 0)
|
||||
return @"";
|
||||
|
||||
test = [d bytes];
|
||||
if (test != 0 &&
|
||||
(((test[0]==0xFF) && (test[1]==0xFE))
|
||||
|| ((test[1]==0xFF) && (test[0]==0xFE))))
|
||||
enc = NSUnicodeStringEncoding;
|
||||
if ((test != NULL) && (len > 1)
|
||||
&& ((test[0] == byteOrderMark) || (test[0] == byteOrderMarkSwapped)))
|
||||
{
|
||||
/* somebody set up us the BOM! */
|
||||
enc = NSUnicodeStringEncoding;
|
||||
}
|
||||
else
|
||||
enc = [NSString defaultCStringEncoding];
|
||||
{
|
||||
enc = [NSString defaultCStringEncoding];
|
||||
}
|
||||
return [self initWithData: d encoding: enc];
|
||||
}
|
||||
|
||||
|
@ -1111,19 +1119,25 @@ handle_printf_atsign (FILE *stream,
|
|||
{
|
||||
NSStringEncoding enc;
|
||||
NSData *d = [NSDataClass dataWithContentsOfURL: url];
|
||||
unsigned int len = [d length];
|
||||
const unsigned char *test;
|
||||
|
||||
if (d == nil)
|
||||
return nil;
|
||||
if ([d length] < 2)
|
||||
|
||||
if (len == 0)
|
||||
return @"";
|
||||
|
||||
test = [d bytes];
|
||||
if (test != 0
|
||||
&& (((test[0]==0xFF) && (test[1]==0xFE))
|
||||
|| ((test[1]==0xFF) && (test[0]==0xFE))))
|
||||
enc = NSUnicodeStringEncoding;
|
||||
if ((test != NULL) && (len > 1)
|
||||
&& ((test[0] == byteOrderMark) || (test[0] == byteOrderMarkSwapped)))
|
||||
{
|
||||
enc = NSUnicodeStringEncoding;
|
||||
}
|
||||
else
|
||||
enc = [NSString defaultCStringEncoding];
|
||||
{
|
||||
enc = [NSString defaultCStringEncoding];
|
||||
}
|
||||
return [self initWithData: d encoding: enc];
|
||||
}
|
||||
|
||||
|
@ -3094,7 +3108,7 @@ handle_printf_atsign (FILE *stream,
|
|||
length: count
|
||||
freeWhenDone: YES];
|
||||
}
|
||||
else if (enc == NSASCIIStringEncoding || enc == _DefaultStringEncoding)
|
||||
else if (enc == NSASCIIStringEncoding)
|
||||
{
|
||||
unsigned char *chars;
|
||||
|
||||
|
|
Loading…
Reference in a new issue