Minor tweaks and fixes for multi-characterset support.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@8323 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2000-12-14 09:47:02 +00:00
parent 3663488f22
commit 645073849f
4 changed files with 72 additions and 43 deletions

View file

@ -1,3 +1,12 @@
2000-12-04 Richard Frith-Macdonald <rfm@gnu.org>
* Source/Unicode.m: Tidied to conform to coding standards and changed
to use ISOLatin1 as the default cString encoding.
* Source/GSString.m: Fixed bug getting cString from unicode string -
raise exception when it should.
* Source/NSString.m: ditto. Also use lossyCString in various
places rather than cString.
2000-12-13 Nicola Pero <n.pero@mi.flashnet.it>
* Headers/gnustep/base/NSRange.h, Source/NSRange.m: Inlined

View file

@ -901,7 +901,8 @@ static inline void
getCString_u(ivars self, char *buffer, unsigned int maxLength,
NSRange aRange, NSRange *leftoverRange)
{
int len;
int len;
int result;
if (maxLength > self->_count)
{
@ -926,8 +927,13 @@ getCString_u(ivars self, char *buffer, unsigned int maxLength,
}
}
encode_ustrtostr_strict(buffer, &self->_contents.u[aRange.location],
maxLength, defEnc);
result = encode_ustrtostr_strict(buffer, &self->_contents.u[aRange.location],
len, defEnc);
if (result != len)
{
[NSException raise: NSCharacterConversionException
format: @"Can't get cString from Unicode string."];
}
buffer[len] = '\0';
}

View file

@ -670,7 +670,7 @@ handle_printf_atsign (FILE *stream,
arguments: (va_list)arg_list
{
#if defined(HAVE_VSPRINTF) || defined(HAVE_VASPRINTF)
const char *format_cp = [format cString];
const char *format_cp = [format lossyCString];
int format_len = strlen (format_cp);
#if HAVE_VASPRINTF
char *buf;
@ -783,7 +783,7 @@ handle_printf_atsign (FILE *stream,
format_to_go = spec_pos+1;
}
/* Get a C-string (char*) from the String object, and print it. */
cstring = [[(id) va_arg (arg_list, id) description] cString];
cstring = [[(id) va_arg (arg_list, id) description] lossyCString];
if (!cstring)
cstring = "<null string>";
cstring_len = strlen(cstring);
@ -930,7 +930,7 @@ handle_printf_atsign (FILE *stream,
format_to_go = spec_pos+1;
}
/* Get a C-string (char*) from the String object, and print it. */
cstring = [[(id) va_arg (arg_list, id) description] cString];
cstring = [[(id) va_arg (arg_list, id) description] lossyCString];
if (!cstring)
cstring = "<null string>";
strcat (buf+printed_len, cstring);
@ -1940,7 +1940,14 @@ handle_printf_atsign (FILE *stream,
count = 0;
while (count < len)
{
buffer[count]=unitochar((*caiImp)(self, caiSel, aRange.location + count));
buffer[count] = encode_unitochar(
(*caiImp)(self, caiSel, aRange.location + count),
_DefaultStringEncoding);
if (buffer[count] == 0)
{
[NSException raise: NSCharacterConversionException
format: @"unable to convert to cString"];
}
count++;
}
buffer[len] = '\0';
@ -1960,17 +1967,17 @@ handle_printf_atsign (FILE *stream,
- (double) doubleValue
{
return atof([self cString]);
return atof([self lossyCString]);
}
- (float) floatValue
{
return (float) atof([self cString]);
return (float) atof([self lossyCString]);
}
- (int) intValue
{
return atoi([self cString]);
return atoi([self lossyCString]);
}
// Working With Encodings

View file

@ -168,90 +168,97 @@ NSStringEncoding *GetAvailableEncodings()
return _availableEncodings;
}
NSStringEncoding GetDefEncoding()
NSStringEncoding
GetDefEncoding()
{
char *encoding;
unsigned int count;
NSStringEncoding ret,tmp;
NSStringEncoding *availableEncodings;
char *encoding;
unsigned int count;
NSStringEncoding ret;
NSStringEncoding tmp;
NSStringEncoding *availableEncodings;
availableEncodings = GetAvailableEncodings();
encoding = getenv("GNUSTEP_STRING_ENCODING");
if (encoding)
if (encoding != 0)
{
count = 0;
while (str_encoding_table[count].enc &&
strcmp(str_encoding_table[count].ename,encoding))
while (str_encoding_table[count].enc
&& strcmp(str_encoding_table[count].ename,encoding))
{
count++;
}
if (str_encoding_table[count].enc)
{
ret = str_encoding_table[count].enc;
if ((ret == NSUnicodeStringEncoding) ||
(ret == NSSymbolStringEncoding))
if ((ret == NSUnicodeStringEncoding)
|| (ret == NSSymbolStringEncoding))
{
fprintf(stderr, "WARNING: %s - encoding not supported as default c string encoding.\n", encoding);
fprintf(stderr, "NSASCIIStringEncoding set as default.\n");
ret = NSASCIIStringEncoding;
fprintf(stderr, "WARNING: %s - encoding not supported as "
"default c string encoding.\n", encoding);
fprintf(stderr, "NSISOLatin1StringEncoding set as default.\n");
ret = NSISOLatin1StringEncoding;
}
else /*encoding should be supported but is it implemented?*/
{
count = 0;
tmp = 0;
while ( !(availableEncodings[count] == 0) )
while (availableEncodings[count] != 0)
{
if ( !(ret == availableEncodings[count]) )
tmp = 0;
if (ret != availableEncodings[count])
{
tmp = 0;
}
else
{
tmp = ret;
break;
}
count++;
};
if (!tmp)
}
if (tmp != 0)
{
fprintf(stderr, "WARNING: %s - encoding not yet implemented.\n", encoding);
fprintf(stderr, "NSASCIIStringEncoding set as default.\n");
ret = NSASCIIStringEncoding;
};
};
fprintf(stderr, "WARNING: %s - encoding not yet "
"implemented.\n", encoding);
fprintf(stderr,
"NSISOLatin1StringEncoding set as default.\n");
ret = NSISOLatin1StringEncoding;
}
}
}
else /* encoding not found */
{
fprintf(stderr, "WARNING: %s - encoding not supported.\n", encoding);
fprintf(stderr, "NSASCIIStringEncoding set as default.\n");
ret = NSASCIIStringEncoding;
fprintf(stderr, "NSISOLatin1StringEncoding set as default.\n");
ret = NSISOLatin1StringEncoding;
}
}
else /* environment var not found */
{
/* This shouldn't be required. It really should be in UserDefaults - asf */
//fprintf(stderr,"WARNING: GNUSTEP_STRING_ENCODING environment variable not found\n");
//fprintf(stderr, "NSASCIIStringEncoding set as default.\n");
ret = NSASCIIStringEncoding;
/* shouldn't be required. It really should be in UserDefaults - asf */
//fprintf(stderr,"WARNING: GNUSTEP_STRING_ENCODING environment found\n");
//fprintf(stderr, "NSISOLatin1StringEncoding set as default.\n");
ret = NSISOLatin1StringEncoding;
}
// Cache the encoding
defEnc = ret;
return ret;
};
}
NSString*
GetEncodingName(NSStringEncoding encoding)
{
unsigned int count=0;
while (str_encoding_table[count].enc &&
!(str_encoding_table[count].enc == encoding))
while (str_encoding_table[count].enc
&& (str_encoding_table[count].enc != encoding))
{
count++;
}
return [NSString stringWithCString: str_encoding_table[count].ename];
};
}
#ifdef HAVE_ICONV