mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 08:41:03 +00:00
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:
parent
38e2332a79
commit
7c3869a9fa
4 changed files with 72 additions and 43 deletions
|
@ -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>
|
2000-12-13 Nicola Pero <n.pero@mi.flashnet.it>
|
||||||
|
|
||||||
* Headers/gnustep/base/NSRange.h, Source/NSRange.m: Inlined
|
* Headers/gnustep/base/NSRange.h, Source/NSRange.m: Inlined
|
||||||
|
|
|
@ -901,7 +901,8 @@ static inline void
|
||||||
getCString_u(ivars self, char *buffer, unsigned int maxLength,
|
getCString_u(ivars self, char *buffer, unsigned int maxLength,
|
||||||
NSRange aRange, NSRange *leftoverRange)
|
NSRange aRange, NSRange *leftoverRange)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
|
int result;
|
||||||
|
|
||||||
if (maxLength > self->_count)
|
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],
|
result = encode_ustrtostr_strict(buffer, &self->_contents.u[aRange.location],
|
||||||
maxLength, defEnc);
|
len, defEnc);
|
||||||
|
if (result != len)
|
||||||
|
{
|
||||||
|
[NSException raise: NSCharacterConversionException
|
||||||
|
format: @"Can't get cString from Unicode string."];
|
||||||
|
}
|
||||||
buffer[len] = '\0';
|
buffer[len] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -670,7 +670,7 @@ handle_printf_atsign (FILE *stream,
|
||||||
arguments: (va_list)arg_list
|
arguments: (va_list)arg_list
|
||||||
{
|
{
|
||||||
#if defined(HAVE_VSPRINTF) || defined(HAVE_VASPRINTF)
|
#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);
|
int format_len = strlen (format_cp);
|
||||||
#if HAVE_VASPRINTF
|
#if HAVE_VASPRINTF
|
||||||
char *buf;
|
char *buf;
|
||||||
|
@ -783,7 +783,7 @@ handle_printf_atsign (FILE *stream,
|
||||||
format_to_go = spec_pos+1;
|
format_to_go = spec_pos+1;
|
||||||
}
|
}
|
||||||
/* Get a C-string (char*) from the String object, and print it. */
|
/* 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)
|
if (!cstring)
|
||||||
cstring = "<null string>";
|
cstring = "<null string>";
|
||||||
cstring_len = strlen(cstring);
|
cstring_len = strlen(cstring);
|
||||||
|
@ -930,7 +930,7 @@ handle_printf_atsign (FILE *stream,
|
||||||
format_to_go = spec_pos+1;
|
format_to_go = spec_pos+1;
|
||||||
}
|
}
|
||||||
/* Get a C-string (char*) from the String object, and print it. */
|
/* 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)
|
if (!cstring)
|
||||||
cstring = "<null string>";
|
cstring = "<null string>";
|
||||||
strcat (buf+printed_len, cstring);
|
strcat (buf+printed_len, cstring);
|
||||||
|
@ -1940,7 +1940,14 @@ handle_printf_atsign (FILE *stream,
|
||||||
count = 0;
|
count = 0;
|
||||||
while (count < len)
|
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++;
|
count++;
|
||||||
}
|
}
|
||||||
buffer[len] = '\0';
|
buffer[len] = '\0';
|
||||||
|
@ -1960,17 +1967,17 @@ handle_printf_atsign (FILE *stream,
|
||||||
|
|
||||||
- (double) doubleValue
|
- (double) doubleValue
|
||||||
{
|
{
|
||||||
return atof([self cString]);
|
return atof([self lossyCString]);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (float) floatValue
|
- (float) floatValue
|
||||||
{
|
{
|
||||||
return (float) atof([self cString]);
|
return (float) atof([self lossyCString]);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int) intValue
|
- (int) intValue
|
||||||
{
|
{
|
||||||
return atoi([self cString]);
|
return atoi([self lossyCString]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Working With Encodings
|
// Working With Encodings
|
||||||
|
|
|
@ -168,90 +168,97 @@ NSStringEncoding *GetAvailableEncodings()
|
||||||
return _availableEncodings;
|
return _availableEncodings;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSStringEncoding GetDefEncoding()
|
NSStringEncoding
|
||||||
|
GetDefEncoding()
|
||||||
{
|
{
|
||||||
char *encoding;
|
char *encoding;
|
||||||
unsigned int count;
|
unsigned int count;
|
||||||
NSStringEncoding ret,tmp;
|
NSStringEncoding ret;
|
||||||
NSStringEncoding *availableEncodings;
|
NSStringEncoding tmp;
|
||||||
|
NSStringEncoding *availableEncodings;
|
||||||
|
|
||||||
availableEncodings = GetAvailableEncodings();
|
availableEncodings = GetAvailableEncodings();
|
||||||
|
|
||||||
encoding = getenv("GNUSTEP_STRING_ENCODING");
|
encoding = getenv("GNUSTEP_STRING_ENCODING");
|
||||||
if (encoding)
|
if (encoding != 0)
|
||||||
{
|
{
|
||||||
count = 0;
|
count = 0;
|
||||||
while (str_encoding_table[count].enc &&
|
while (str_encoding_table[count].enc
|
||||||
strcmp(str_encoding_table[count].ename,encoding))
|
&& strcmp(str_encoding_table[count].ename,encoding))
|
||||||
{
|
{
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
if (str_encoding_table[count].enc)
|
if (str_encoding_table[count].enc)
|
||||||
{
|
{
|
||||||
ret = str_encoding_table[count].enc;
|
ret = str_encoding_table[count].enc;
|
||||||
if ((ret == NSUnicodeStringEncoding) ||
|
if ((ret == NSUnicodeStringEncoding)
|
||||||
(ret == NSSymbolStringEncoding))
|
|| (ret == NSSymbolStringEncoding))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "WARNING: %s - encoding not supported as default c string encoding.\n", encoding);
|
fprintf(stderr, "WARNING: %s - encoding not supported as "
|
||||||
fprintf(stderr, "NSASCIIStringEncoding set as default.\n");
|
"default c string encoding.\n", encoding);
|
||||||
ret = NSASCIIStringEncoding;
|
fprintf(stderr, "NSISOLatin1StringEncoding set as default.\n");
|
||||||
|
ret = NSISOLatin1StringEncoding;
|
||||||
}
|
}
|
||||||
else /*encoding should be supported but is it implemented?*/
|
else /*encoding should be supported but is it implemented?*/
|
||||||
{
|
{
|
||||||
count = 0;
|
count = 0;
|
||||||
tmp = 0;
|
tmp = 0;
|
||||||
while ( !(availableEncodings[count] == 0) )
|
while (availableEncodings[count] != 0)
|
||||||
{
|
{
|
||||||
if ( !(ret == availableEncodings[count]) )
|
if (ret != availableEncodings[count])
|
||||||
tmp = 0;
|
{
|
||||||
|
tmp = 0;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tmp = ret;
|
tmp = ret;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
count++;
|
count++;
|
||||||
};
|
}
|
||||||
if (!tmp)
|
if (tmp != 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "WARNING: %s - encoding not yet implemented.\n", encoding);
|
fprintf(stderr, "WARNING: %s - encoding not yet "
|
||||||
fprintf(stderr, "NSASCIIStringEncoding set as default.\n");
|
"implemented.\n", encoding);
|
||||||
ret = NSASCIIStringEncoding;
|
fprintf(stderr,
|
||||||
};
|
"NSISOLatin1StringEncoding set as default.\n");
|
||||||
};
|
ret = NSISOLatin1StringEncoding;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else /* encoding not found */
|
else /* encoding not found */
|
||||||
{
|
{
|
||||||
fprintf(stderr, "WARNING: %s - encoding not supported.\n", encoding);
|
fprintf(stderr, "WARNING: %s - encoding not supported.\n", encoding);
|
||||||
fprintf(stderr, "NSASCIIStringEncoding set as default.\n");
|
fprintf(stderr, "NSISOLatin1StringEncoding set as default.\n");
|
||||||
ret = NSASCIIStringEncoding;
|
ret = NSISOLatin1StringEncoding;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else /* environment var not found */
|
else /* environment var not found */
|
||||||
{
|
{
|
||||||
/* This shouldn't be required. It really should be in UserDefaults - asf */
|
/* shouldn't be required. It really should be in UserDefaults - asf */
|
||||||
//fprintf(stderr,"WARNING: GNUSTEP_STRING_ENCODING environment variable not found\n");
|
//fprintf(stderr,"WARNING: GNUSTEP_STRING_ENCODING environment found\n");
|
||||||
//fprintf(stderr, "NSASCIIStringEncoding set as default.\n");
|
//fprintf(stderr, "NSISOLatin1StringEncoding set as default.\n");
|
||||||
ret = NSASCIIStringEncoding;
|
ret = NSISOLatin1StringEncoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cache the encoding
|
// Cache the encoding
|
||||||
defEnc = ret;
|
defEnc = ret;
|
||||||
return ret;
|
return ret;
|
||||||
};
|
}
|
||||||
|
|
||||||
NSString*
|
NSString*
|
||||||
GetEncodingName(NSStringEncoding encoding)
|
GetEncodingName(NSStringEncoding encoding)
|
||||||
{
|
{
|
||||||
unsigned int count=0;
|
unsigned int count=0;
|
||||||
|
|
||||||
while (str_encoding_table[count].enc &&
|
while (str_encoding_table[count].enc
|
||||||
!(str_encoding_table[count].enc == encoding))
|
&& (str_encoding_table[count].enc != encoding))
|
||||||
{
|
{
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return [NSString stringWithCString: str_encoding_table[count].ename];
|
return [NSString stringWithCString: str_encoding_table[count].ename];
|
||||||
};
|
}
|
||||||
|
|
||||||
#ifdef HAVE_ICONV
|
#ifdef HAVE_ICONV
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue