2011-11-05 00:50:55 +00:00
|
|
|
#include <qse/cmn/fmt.h>
|
|
|
|
#include <qse/cmn/main.h>
|
2012-01-03 14:41:15 +00:00
|
|
|
#include <qse/cmn/mbwc.h>
|
2016-04-29 03:55:42 +00:00
|
|
|
#include <qse/si/sio.h>
|
2011-11-05 00:50:55 +00:00
|
|
|
|
2012-01-03 14:41:15 +00:00
|
|
|
#include <locale.h>
|
|
|
|
#if defined(_WIN32)
|
|
|
|
# include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2012-10-15 09:46:29 +00:00
|
|
|
static int test_main (int argc, qse_char_t* argv[])
|
2011-11-05 00:50:55 +00:00
|
|
|
{
|
|
|
|
qse_char_t buf[129];
|
|
|
|
int bases[] = { 2, 8, 10, 16 };
|
2011-11-07 00:01:19 +00:00
|
|
|
qse_char_t* prefix[] = { QSE_T("0b"), QSE_T("0"), QSE_NULL, QSE_T("0x") };
|
2011-11-05 00:50:55 +00:00
|
|
|
int flags[] =
|
|
|
|
{
|
|
|
|
QSE_FMTINTMAX_PLUSSIGN,
|
|
|
|
QSE_FMTINTMAX_FILLRIGHT | QSE_FMTINTMAX_PLUSSIGN,
|
|
|
|
QSE_FMTINTMAX_FILLCENTER | QSE_FMTINTMAX_PLUSSIGN
|
|
|
|
};
|
|
|
|
int i, j, k;
|
|
|
|
qse_intmax_t nums[] = { -12345, 12345, 0, QSE_TYPE_MAX(qse_intmax_t) };
|
|
|
|
|
|
|
|
/* note that nums[3] may not be printed properly with %d in printf().
|
|
|
|
* however, the formatting result with qse_fmtintmax() should be printed
|
|
|
|
* properly.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2011-11-14 15:15:44 +00:00
|
|
|
qse_printf (QSE_T("[PRECISION -1]\n"));
|
2011-11-05 00:50:55 +00:00
|
|
|
for (k = 0; k < QSE_COUNTOF(nums) ; k++)
|
|
|
|
{
|
|
|
|
for (i = 0; i < QSE_COUNTOF(bases); i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < QSE_COUNTOF(flags); j++)
|
|
|
|
{
|
2011-11-14 15:15:44 +00:00
|
|
|
int n = qse_fmtintmax (buf, QSE_COUNTOF(buf), nums[k], bases[i] | flags[j] | QSE_FMTINTMAX_NOTRUNC, -1, QSE_T('.'), prefix[i]);
|
|
|
|
if (n <= -1)
|
|
|
|
{
|
2011-11-15 15:58:32 +00:00
|
|
|
qse_printf (QSE_T("%8d => [%4d:%05X] ERROR[%d]\n"), (int)nums[k], bases[i], flags[j], n);
|
2011-11-14 15:15:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-11-15 15:58:32 +00:00
|
|
|
qse_printf (QSE_T("%8d => [%4d:%05X] [%s]\n"), (int)nums[k], bases[i], flags[j], buf);
|
2011-11-14 15:15:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
qse_printf (QSE_T("------------------------------\n"));
|
|
|
|
}
|
|
|
|
|
|
|
|
qse_printf (QSE_T("[PRECISION 0]\n"));
|
|
|
|
for (k = 0; k < QSE_COUNTOF(nums) ; k++)
|
|
|
|
{
|
|
|
|
for (i = 0; i < QSE_COUNTOF(bases); i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < QSE_COUNTOF(flags); j++)
|
|
|
|
{
|
|
|
|
int n = qse_fmtintmax (buf, QSE_COUNTOF(buf), nums[k], bases[i] | flags[j] | QSE_FMTINTMAX_NOTRUNC | QSE_FMTINTMAX_NOZERO, 0, QSE_T('*'), prefix[i]);
|
2011-11-05 00:50:55 +00:00
|
|
|
if (n <= -1)
|
|
|
|
{
|
2011-11-15 15:58:32 +00:00
|
|
|
qse_printf (QSE_T("%8d => [%4d:%05X] ERROR[%d]\n"), (int)nums[k], bases[i], flags[j], n);
|
2011-11-05 00:50:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-11-15 15:58:32 +00:00
|
|
|
qse_printf (QSE_T("%8d => [%4d:%05X] [%s]\n"), (int)nums[k], bases[i], flags[j], buf);
|
2011-11-05 00:50:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
qse_printf (QSE_T("------------------------------\n"));
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-15 09:46:29 +00:00
|
|
|
int qse_main (int argc, qse_achar_t* argv[])
|
2011-11-05 00:50:55 +00:00
|
|
|
{
|
2015-03-11 06:12:48 +00:00
|
|
|
int x;
|
|
|
|
|
2012-01-03 14:41:15 +00:00
|
|
|
#if defined(_WIN32)
|
2015-03-11 06:12:48 +00:00
|
|
|
char locale[100];
|
|
|
|
UINT codepage = GetConsoleOutputCP();
|
2012-01-03 14:41:15 +00:00
|
|
|
if (codepage == CP_UTF8)
|
|
|
|
{
|
|
|
|
/*SetConsoleOUtputCP (CP_UTF8);*/
|
2012-10-15 09:36:39 +00:00
|
|
|
qse_setdflcmgrbyid (QSE_CMGR_UTF8);
|
2012-01-03 14:41:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprintf (locale, ".%u", (unsigned int)codepage);
|
|
|
|
setlocale (LC_ALL, locale);
|
2015-04-27 08:37:57 +00:00
|
|
|
/*qse_setdflcmgrbyid (QSE_CMGR_SLMB);*/
|
2012-01-03 14:41:15 +00:00
|
|
|
}
|
|
|
|
#else
|
2015-03-11 06:12:48 +00:00
|
|
|
setlocale (LC_ALL, "");
|
2015-04-27 08:37:57 +00:00
|
|
|
/*qse_setdflcmgrbyid (QSE_CMGR_SLMB);*/
|
2012-01-03 14:41:15 +00:00
|
|
|
#endif
|
2017-09-16 08:54:25 +00:00
|
|
|
qse_open_stdsios ();
|
2018-09-13 03:16:23 +00:00
|
|
|
x = qse_run_main (argc, argv, test_main);
|
2017-09-16 08:54:25 +00:00
|
|
|
qse_close_stdsios ();
|
2015-03-11 06:12:48 +00:00
|
|
|
return x;
|
2011-11-05 00:50:55 +00:00
|
|
|
}
|
|
|
|
|