added qse_utf8cmgr and qse_loccmgr

This commit is contained in:
hyung-hwan 2012-01-02 15:11:43 +00:00
parent 5e0b9418d7
commit dd02292cc4
5 changed files with 55 additions and 37 deletions

View File

@ -42,6 +42,9 @@ struct qse_mbstate_t
extern "C" {
#endif
extern qse_cmgr_t* qse_utf8cmgr;
extern qse_cmgr_t* qse_loccmgr;
qse_cmgr_t* qse_getdflcmgr (
void
);

View File

@ -716,7 +716,6 @@ struct qse_mmgr_t
};
typedef struct qse_mmgr_t qse_mmgr_t;
typedef qse_size_t (*qse_cmgr_mbtowc_t) (
const qse_mchar_t* mb,
qse_size_t size,
@ -730,7 +729,8 @@ typedef qse_size_t (*qse_cmgr_wctomb_t) (
);
/**
* The qse_cmgr_t type defines the interface to various character handling.
* The qse_cmgr_t type defines the character-level interface to
* multibyte/wide-character string conversion.
*/
struct qse_cmgr_t
{

View File

@ -21,20 +21,23 @@
#include <qse/cmn/mbwc.h>
#include <qse/cmn/utf8.h>
static qse_cmgr_t utf8_cmgr =
static qse_cmgr_t builtin_cmgr[] =
{
qse_utf8touc,
qse_uctoutf8
{
qse_mbtowc,
qse_wctomb
},
{
qse_utf8touc,
qse_uctoutf8
}
};
static qse_cmgr_t locale_cmgr =
{
qse_mbtowc,
qse_wctomb
};
qse_cmgr_t* qse_loccmgr = &builtin_cmgr[0];
qse_cmgr_t* qse_utf8cmgr = &builtin_cmgr[1];
static qse_cmgr_t* dfl_cmgr = &locale_cmgr;
static qse_cmgr_t* dfl_cmgr = &builtin_cmgr[0];
qse_cmgr_t* qse_getdflcmgr (void)
{
@ -43,7 +46,7 @@ qse_cmgr_t* qse_getdflcmgr (void)
void qse_setdflcmgr (qse_cmgr_t* cmgr)
{
dfl_cmgr = (cmgr? cmgr: &locale_cmgr);
dfl_cmgr = (cmgr? cmgr: &builtin_cmgr[0]);
}
/* string conversion function using default character conversion manager */
@ -66,7 +69,8 @@ int qse_mbsntowcsnupto (
const qse_mchar_t* mbs, qse_size_t* mbslen,
qse_wchar_t* wcs, qse_size_t* wcslen, qse_wchar_t stopper)
{
return qse_mbsntowcsnuptowithcmgr (mbs, mbslen, wcs, wcslen, stopper, dfl_cmgr);
return qse_mbsntowcsnuptowithcmgr (
mbs, mbslen, wcs, wcslen, stopper, dfl_cmgr);
}
qse_wchar_t* qse_mbstowcsdup (const qse_mchar_t* mbs, qse_mmgr_t* mmgr)

View File

@ -1,4 +1,5 @@
#include <qse/cmn/sio.h>
#include <qse/cmn/mbwc.h>
#include <qse/cmn/mem.h>
#include <qse/cmn/fmt.h>
#include <qse/cmn/stdio.h>
@ -143,11 +144,24 @@ static int test3 (void)
int main ()
{
#if 0
#if defined(_WIN32)
UINT old_cp = GetConsoleOutputCP();
SetConsoleOutputCP (CP_UTF8);
#endif
char locale[100];
UINT codepage = GetConsoleOutputCP();
if (codepage == CP_UTF8)
{
/*SetConsoleOutputCP (CP_UTF8);*/
qse_setdflcmgr (qse_utf8cmgr);
}
else
{
sprintf (locale, ".%u", (unsigned int)codepage);
setlocale (LC_ALL, locale);
qse_setdflcmgr (qse_loccmgr);
}
#else
setlocale (LC_ALL, "");
qse_setdflcmgr (qse_loccmgr);
#endif
setlocale (LC_ALL, "");
@ -159,11 +173,5 @@ int main ()
R (test3);
qse_sio_close (g_out);
#if 0
#if defined(_WIN32)
SetConsoleOutputCP (old_cp);
#endif
#endif
return 0;
}

View File

@ -1,4 +1,5 @@
#include <qse/cmn/sio.h>
#include <qse/cmn/mbwc.h>
#include <qse/cmn/mem.h>
#include <qse/cmn/stdio.h>
@ -129,17 +130,22 @@ static int test3 (void)
int main ()
{
#if defined(_WIN32)
char codepage[100];
UINT old_cp = GetConsoleOutputCP();
SetConsoleOutputCP (CP_UTF8);
/* TODO: on windows this set locale only affects those mbcs fucntions in clib.
* it doesn't support utf8 i guess find a working way. the following won't work
sprintf (codepage, ".%d", GetACP());
setlocale (LC_ALL, codepage);
*/
char locale[100];
UINT codepage = GetConsoleOutputCP();
if (codepage == CP_UTF8)
{
/*SetConsoleOUtputCP (CP_UTF8);*/
qse_setdflcmgr (qse_utf8cmgr);
}
else
{
sprintf (locale, ".%u", (unsigned int)codepage);
setlocale (LC_ALL, locale);
qse_setdflcmgr (qse_loccmgr);
}
#else
setlocale (LC_ALL, "");
setlocale (LC_ALL, "");
qse_setdflcmgr (qse_loccmgr);
#endif
qse_printf (QSE_T("--------------------------------------------------------------------------------\n"));
@ -150,8 +156,5 @@ int main ()
R (test2);
R (test3);
#if defined(_WIN32)
SetConsoleOutputCP (old_cp);
#endif
return 0;
}