Skip to content

Commit

Permalink
- fix redeclaration
Browse files Browse the repository at this point in the history
  • Loading branch information
fbergmann committed Feb 19, 2025
1 parent ef20ed4 commit bbcf32d
Showing 1 changed file with 57 additions and 53 deletions.
110 changes: 57 additions & 53 deletions copasi/commandline/CLocaleString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,27 +227,28 @@ std::string CLocaleString::toUtf8() const
int size;

size = WideCharToMultiByte(CP_UTF8, // code page
0, // performance and mapping flags
mpStr, // address of wide-character string
-1, // NULL terminated
NULL, // address of buffer for new string
0, // size of buffer
NULL, // address of default for unmappable characters
NULL) + 1; // address of flag set when default char used
0, // performance and mapping flags
mpStr, // address of wide-character string
-1, // NULL terminated
NULL, // address of buffer for new string
0, // size of buffer
NULL, // address of default for unmappable characters
NULL)
+ 1; // address of flag set when default char used

char * pUtf8 = new char[size];

WideCharToMultiByte(CP_UTF8, // code page
0, // address of wide-character string
mpStr, // address of wide-character string
-1, // NULL terminated
pUtf8, // address of buffer for new string
size, // size of buffer
NULL, // address of default for unmappable characters
NULL); // address of flag set when default char used
0, // address of wide-character string
mpStr, // address of wide-character string
-1, // NULL terminated
pUtf8, // address of buffer for new string
size, // size of buffer
NULL, // address of default for unmappable characters
NULL); // address of flag set when default char used

std::string Utf8 = pUtf8;
delete [] pUtf8;
delete[] pUtf8;

return Utf8;
#endif // WIN32
Expand All @@ -263,73 +264,76 @@ std::string CLocaleString::toUtf8() const
Converter = iconv_open(To, From);
}

if (Converter == (iconv_t)(-1))
if (Converter == (iconv_t) (-1))
return mpStr;

size_t LocaleLength = strlen(mpStr);
char * Locale = strdup(mpStr);
#if (COPASI_ICONV_CONST_CHAR) // non standard iconv declaration :(
# if (COPASI_ICONV_CONST_CHAR) // non standard iconv declaration :(
const char * pLocale = Locale;
#else
# else
char * pLocale = Locale;
#endif
# endif

size_t Utf8Length = LocaleLength + 1;
size_t SpaceLeft = LocaleLength;
char * Utf8 = new char[Utf8Length];
char * pUtf8 = Utf8;

while (LocaleLength)
if ((size_t)(-1) ==
iconv(Converter, &pLocale, &LocaleLength, &pUtf8, &SpaceLeft))
if ((size_t) (-1) == iconv(Converter, &pLocale, &LocaleLength, &pUtf8, &SpaceLeft))
{
switch (errno)
{
case EILSEQ:
pUtf8 = Utf8;
LocaleLength = 0;
break;

case EINVAL:
pUtf8 = Utf8;
LocaleLength = 0;
break;

case E2BIG:
char * pTmp = Utf8;
size_t OldLength = Utf8Length;
Utf8Length += 2 * LocaleLength;

Utf8 = new char[Utf8Length];
memcpy(Utf8, pTmp,
sizeof(char) * (OldLength - SpaceLeft - 1));
pUtf8 = Utf8 + OldLength - SpaceLeft - 1;
SpaceLeft += 2 * LocaleLength;
delete [] pTmp;

break;
case EILSEQ:
pUtf8 = Utf8;
LocaleLength = 0;
break;

case EINVAL:
pUtf8 = Utf8;
LocaleLength = 0;
break;

case E2BIG:
char * pTmp = Utf8;
size_t OldLength = Utf8Length;
Utf8Length += 2 * LocaleLength;

Utf8 = new char[Utf8Length];
memcpy(Utf8, pTmp,
sizeof(char) * (OldLength - SpaceLeft - 1));
pUtf8 = Utf8 + OldLength - SpaceLeft - 1;
SpaceLeft += 2 * LocaleLength;
delete[] pTmp;

break;
}

continue;
}

*pUtf8 = 0x00; // NULL terminate the string.
std::string Result = Utf8;
{
std::string Result = Utf8;

// Reset the Converter
iconv(Converter, NULL, &LocaleLength, NULL, &Utf8Length);
// Reset the Converter
iconv(Converter, NULL, &LocaleLength, NULL, &Utf8Length);

// Release memory
free(Locale);
delete [] Utf8;
// Release memory
free(Locale);
delete[] Utf8;

return Result;
return Result;
}
#endif // SunOS || Linux


#if !defined(WIN32) || defined(__MINGW32__) || defined(__MINGW64__)
std::string Result = mpStr;
return Result;
{
std::string Result = mpStr;
return Result;
}
#endif
}

Expand Down

0 comments on commit bbcf32d

Please # to comment.