mirror of
https://github.com/gnustep/libs-base.git
synced 2025-06-03 01:50:55 +00:00
Bugfix in ucing iconv to generate unicode from cstring ... was returning
wrong length. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@10644 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
bf97ef27e6
commit
c42a367cac
1 changed files with 16 additions and 12 deletions
|
@ -64,8 +64,11 @@ typedef unsigned char unc;
|
||||||
static NSStringEncoding defEnc = GSUndefinedEncoding;
|
static NSStringEncoding defEnc = GSUndefinedEncoding;
|
||||||
|
|
||||||
#ifdef HAVE_ICONV
|
#ifdef HAVE_ICONV
|
||||||
// FIXME: We should check dynamically which encodings are found on this computer,
|
/*
|
||||||
// as different implementation of iconv will support different encodings.
|
* FIXME: We should check dynamically which encodings are found on this
|
||||||
|
* computer as different implementation of iconv will support different
|
||||||
|
* encodings.
|
||||||
|
*/
|
||||||
static NSStringEncoding _availableEncodings[] = {
|
static NSStringEncoding _availableEncodings[] = {
|
||||||
NSASCIIStringEncoding,
|
NSASCIIStringEncoding,
|
||||||
NSNEXTSTEPStringEncoding,
|
NSNEXTSTEPStringEncoding,
|
||||||
|
@ -335,7 +338,8 @@ iconv_stringforencoding(NSStringEncoding enc)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
iconv_strtoustr(unichar *u2, int size2, const char *s1, int size1, NSStringEncoding enc)
|
iconv_cstrtoustr(unichar *u2, int size2, const char *s1, int size1,
|
||||||
|
NSStringEncoding enc)
|
||||||
{
|
{
|
||||||
iconv_t conv;
|
iconv_t conv;
|
||||||
int usize = sizeof(unichar)*size2;
|
int usize = sizeof(unichar)*size2;
|
||||||
|
@ -356,12 +360,12 @@ iconv_strtoustr(unichar *u2, int size2, const char *s1, int size1, NSStringEncod
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return u1 - (char*)u2;
|
return (u1 - (char*)u2)/sizeof(unichar); // Num unicode chars produced.
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
iconv_ustrtostr(char *s2, int size2, const unichar *u1, int size1,
|
iconv_ustrtocstr(char *s2, int size2, const unichar *u1, int size1,
|
||||||
NSStringEncoding enc)
|
NSStringEncoding enc)
|
||||||
{
|
{
|
||||||
iconv_t conv;
|
iconv_t conv;
|
||||||
int usize = sizeof(unichar)*size1;
|
int usize = sizeof(unichar)*size1;
|
||||||
|
@ -432,7 +436,7 @@ encode_chartouni(char c, NSStringEncoding enc)
|
||||||
{
|
{
|
||||||
unichar u;
|
unichar u;
|
||||||
|
|
||||||
if (iconv_strtoustr(&u, 1, &c, 1, enc) > 0)
|
if (iconv_cstrtoustr(&u, 1, &c, 1, enc) > 0)
|
||||||
return u;
|
return u;
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -516,7 +520,7 @@ encode_unitochar(unichar u, NSStringEncoding enc)
|
||||||
#ifdef HAVE_ICONV
|
#ifdef HAVE_ICONV
|
||||||
{
|
{
|
||||||
char c[4];
|
char c[4];
|
||||||
int r = iconv_ustrtostr(c, 4, &u, 1, enc);
|
int r = iconv_ustrtocstr(c, 4, &u, 1, enc);
|
||||||
|
|
||||||
if (r > 0)
|
if (r > 0)
|
||||||
return c[0];
|
return c[0];
|
||||||
|
@ -604,7 +608,7 @@ encode_unitochar_strict(unichar u, NSStringEncoding enc)
|
||||||
#ifdef HAVE_ICONV
|
#ifdef HAVE_ICONV
|
||||||
{
|
{
|
||||||
unsigned char c[4];
|
unsigned char c[4];
|
||||||
int r = iconv_ustrtostr(c, 4, &u, 1, enc);
|
int r = iconv_ustrtocstr(c, 4, &u, 1, enc);
|
||||||
|
|
||||||
if (r == 2)
|
if (r == 2)
|
||||||
#ifdef WORDS_BIGENDIAN
|
#ifdef WORDS_BIGENDIAN
|
||||||
|
@ -912,7 +916,7 @@ int encode_ustrtocstr(char *dst, int dl, const unichar *src, int sl,
|
||||||
|
|
||||||
default:
|
default:
|
||||||
#ifdef HAVE_ICONV
|
#ifdef HAVE_ICONV
|
||||||
return iconv_ustrtostr(dst, dl, src, sl, enc);
|
return iconv_ustrtocstr(dst, dl, src, sl, enc);
|
||||||
#else
|
#else
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
|
@ -1050,7 +1054,7 @@ int encode_ustrtocstr(char *dst, int dl, const unichar *src, int sl,
|
||||||
default:
|
default:
|
||||||
#ifdef HAVE_ICONV
|
#ifdef HAVE_ICONV
|
||||||
// FIXME: The non-strict encoding is still missing
|
// FIXME: The non-strict encoding is still missing
|
||||||
return iconv_ustrtostr(dst, dl, src, sl, enc);
|
return iconv_ustrtocstr(dst, dl, src, sl, enc);
|
||||||
#else
|
#else
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
|
@ -1137,7 +1141,7 @@ int encode_cstrtoustr(unichar *dst, int dl, const char *src, int sl,
|
||||||
|
|
||||||
default:
|
default:
|
||||||
#ifdef HAVE_ICONV
|
#ifdef HAVE_ICONV
|
||||||
return iconv_strtoustr(dst, dl, src, sl, enc);
|
return iconv_cstrtoustr(dst, dl, src, sl, enc);
|
||||||
#else
|
#else
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue