String encoding fixes

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@17917 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2003-10-18 06:10:41 +00:00
parent 0720ce45b5
commit ec9d52dff8
4 changed files with 36 additions and 13 deletions

View file

@ -1,3 +1,16 @@
Sat Oct 18 07:10:00 2003 Richard Frith-Macdonald <rfm@gnu.org>
* Source/Additions/Unicode.m: Allow GNUSTEP_STRING_ENCODING to give
any supported iconv name in additiuon to OpenStep names. Make check
case insensitive.
Documentation/Base.gsdoc: Remove obsolete comment that
GNUSTEP_STRING_ENCODING may not specify a mu7ltibyte encoding.
2003-10-16 Bruno Haible <bruno@clisp.org>
* Source/NSString.m (initWithContentsOfFile:, initWithContentsOfURL:):
Fix recognition of UTF-8 BOM.
Fri Oct 17 14:28:49 2003 Nicola Pero <n.pero@mi.flashnet.it>
* Source/GNUmakefile (LIBRARY_VAR): Unused variable removed.

View file

@ -198,8 +198,7 @@
<p>
This is used to specify the default encoding for 8-bit
strings. It defaults to NSISOLatin1StringEncoding, but
may be any of the 8-bit encodings supported by your system
(excluding multi-byte encodings).
may be any of the 8-bit encodings supported by your system.
</p>
</desc>
<term>GNUSTEP_HOST_CPU</term>

View file

@ -573,7 +573,8 @@ GetDefEncoding()
{
count = 0;
while (str_encoding_table[count].enc
&& strcmp(str_encoding_table[count].ename, encoding))
&& strcasecmp(str_encoding_table[count].ename, encoding)
&& strcasecmp(str_encoding_table[count].iconv, encoding))
{
count++;
}

View file

@ -1321,7 +1321,7 @@ handle_printf_atsign (FILE *stream,
NSStringEncoding enc = _DefaultStringEncoding;
NSData *d;
unsigned int len;
const unichar *test;
const unsigned char *data_bytes;
d = [[NSDataClass alloc] initWithContentsOfFile: path];
if (d == nil)
@ -1336,15 +1336,20 @@ handle_printf_atsign (FILE *stream,
RELEASE(self);
return @"";
}
test = [d bytes];
if ((test != NULL) && (len > 1))
data_bytes = [d bytes];
if ((data_bytes != NULL) && (len >= 2))
{
if ((test[0] == byteOrderMark) || (test[0] == byteOrderMarkSwapped))
const unichar *data_ucs2chars = (const unichar *) data_bytes;
if ((data_ucs2chars[0] == byteOrderMark)
|| (data_ucs2chars[0] == byteOrderMarkSwapped))
{
/* somebody set up us the BOM! */
enc = NSUnicodeStringEncoding;
}
else if (len > 2 && test[0] == 0xEF && test[1] == 0xBB && test[2] == 0xBF)
else if (len >= 3
&& data_bytes[0] == 0xEF
&& data_bytes[1] == 0xBB
&& data_bytes[2] == 0xBF)
{
enc = NSUTF8StringEncoding;
}
@ -1363,7 +1368,7 @@ handle_printf_atsign (FILE *stream,
NSStringEncoding enc = _DefaultStringEncoding;
NSData *d = [NSDataClass dataWithContentsOfURL: url];
unsigned int len = [d length];
const unichar *test;
const unsigned char *data_bytes;
if (d == nil)
{
@ -1376,14 +1381,19 @@ handle_printf_atsign (FILE *stream,
RELEASE(self);
return @"";
}
test = [d bytes];
if ((test != NULL) && (len > 1))
data_bytes = [d bytes];
if ((data_bytes != NULL) && (len >= 2))
{
if ((test[0] == byteOrderMark) || (test[0] == byteOrderMarkSwapped))
const unichar *data_ucs2chars = (const unichar *) data_bytes;
if ((data_ucs2chars[0] == byteOrderMark)
|| (data_ucs2chars[0] == byteOrderMarkSwapped))
{
enc = NSUnicodeStringEncoding;
}
else if (len > 2 && test[0] == 0xEF && test[1] == 0xBB && test[2] == 0xBF)
else if (len >= 3
&& data_bytes[0] == 0xEF
&& data_bytes[1] == 0xBB
&& data_bytes[2] == 0xBF)
{
enc = NSUTF8StringEncoding;
}