13 # define strdup _wcsdup
16 #if (defined SunOS || defined Linux)
19 # include <langinfo.h>
20 #endif // SunOS || Linux
22 #if (defined SunOS || defined Linux)
23 const char * findLocale()
25 static char * Locale = NULL;
28 Locale = strdup(nl_langinfo(CODESET));
32 if (strcmp(Locale,
"646") == 0)
36 Locale = strdup(
"8859-1");
41 Locale = strdup(
"ISO-8859-1");
47 #endif // SunOS || Linux
55 size = MultiByteToWideChar(CP_UTF8,
62 WCHAR * pWideChar =
new WCHAR[size];
64 MultiByteToWideChar(CP_UTF8,
77 #if (defined SunOS || defined Linux)
78 static iconv_t Converter = NULL;
80 if (Converter == NULL)
82 char From[] =
"UTF-8";
83 const char * To = findLocale();
85 Converter = iconv_open(To, From);
88 if (Converter == (iconv_t)(-1))
91 size_t Utf8Length = utf8.length();
92 char * Utf8 = strdup(utf8.c_str());
93 #if (defined COPASI_ICONV_CONST_CHAR) // non standard iconv declaration :(
94 const char * pUtf8 = Utf8;
99 size_t LocaleLength = Utf8Length + 1;
100 size_t SpaceLeft = Utf8Length;
101 char * Locale =
new char[LocaleLength];
102 char * pLocale = Locale;
106 iconv(Converter, &pUtf8, &Utf8Length, &pLocale, &SpaceLeft))
121 char * pTmp = Locale;
122 size_t OldLength = LocaleLength;
123 LocaleLength += 2 * Utf8Length;
125 Locale =
new char[LocaleLength];
127 sizeof(
char) * (OldLength - SpaceLeft - 1));
128 pLocale = Locale + OldLength - SpaceLeft - 1;
129 SpaceLeft += 2 * Utf8Length;
142 iconv(Converter, NULL, &Utf8Length, NULL, &LocaleLength);
149 #endif // SunOS || Linux
161 mpStr((str != NULL) ? strdup(str) : NULL)
165 mpStr((src.mpStr != NULL) ? strdup(src.mpStr) : NULL)
198 mpStr = (rhs != NULL) ? strdup(rhs) : NULL;
213 size = WideCharToMultiByte(CP_UTF8,
222 char * pUtf8 =
new char[size];
224 WideCharToMultiByte(CP_UTF8,
233 std::string Utf8 = pUtf8;
239 #if (defined SunOS || defined Linux)
240 static iconv_t Converter = NULL;
242 if (Converter == NULL)
245 const char * From = findLocale();
247 Converter = iconv_open(To, From);
250 if (Converter == (iconv_t)(-1))
253 size_t LocaleLength = strlen(
mpStr);
254 char * Locale = strdup(
mpStr);
255 #if (COPASI_ICONV_CONST_CHAR) // non standard iconv declaration :(
256 const char * pLocale = Locale;
258 char * pLocale = Locale;
261 size_t Utf8Length = LocaleLength + 1;
262 size_t SpaceLeft = LocaleLength;
263 char * Utf8 =
new char[Utf8Length];
268 iconv(Converter, &pLocale, &LocaleLength, &pUtf8, &SpaceLeft))
284 size_t OldLength = Utf8Length;
285 Utf8Length += 2 * LocaleLength;
287 Utf8 =
new char[Utf8Length];
289 sizeof(
char) * (OldLength - SpaceLeft - 1));
290 pUtf8 = Utf8 + OldLength - SpaceLeft - 1;
291 SpaceLeft += 2 * LocaleLength;
301 std::string Result = Utf8;
304 iconv(Converter, NULL, &LocaleLength, NULL, &Utf8Length);
311 #endif // SunOS || Linux
314 std::string Result =
mpStr;
CLocaleString & operator=(const CLocaleString &rhs)
const lchar * c_str() const
std::string toUtf8() const
static CLocaleString fromUtf8(const std::string &utf8)