2011-12-31 15:24:48 +00:00
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
2019-06-06 05:28:23 +00:00
|
|
|
Copyright (c) 2006-2019 Chung, Hyung-Hwan. All rights reserved.
|
2011-12-31 15:24:48 +00:00
|
|
|
|
2014-11-19 14:42:24 +00:00
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
1. Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
2011-12-31 15:24:48 +00:00
|
|
|
|
2014-11-19 14:42:24 +00:00
|
|
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
|
|
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2011-12-31 15:24:48 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <qse/cmn/mbwc.h>
|
2012-01-03 14:41:15 +00:00
|
|
|
#include <qse/cmn/slmb.h>
|
2011-12-31 15:24:48 +00:00
|
|
|
#include <qse/cmn/utf8.h>
|
2013-01-16 05:04:56 +00:00
|
|
|
#include <qse/cmn/mb8.h>
|
2012-02-24 09:09:45 +00:00
|
|
|
#include <qse/cmn/cp949.h>
|
|
|
|
#include <qse/cmn/cp950.h>
|
2012-01-17 16:45:01 +00:00
|
|
|
#include <qse/cmn/str.h>
|
2011-12-31 15:24:48 +00:00
|
|
|
|
2012-01-03 14:41:15 +00:00
|
|
|
/* TODO: there is no guarantee that slwc is a unicode charater or vice versa.
|
|
|
|
* the ctype handling functions should be made wide-character
|
|
|
|
* dependent.
|
|
|
|
*/
|
|
|
|
|
2012-01-02 15:11:43 +00:00
|
|
|
static qse_cmgr_t builtin_cmgr[] =
|
2011-12-31 15:24:48 +00:00
|
|
|
{
|
2013-01-16 05:04:56 +00:00
|
|
|
/* keep the order aligned with qse_cmgr_id_t values in <qse/cmn/mbwc.h> */
|
|
|
|
{ qse_slmbtoslwc, qse_slwctoslmb },
|
|
|
|
{ qse_utf8touc, qse_uctoutf8 },
|
|
|
|
{ qse_mb8towc, qse_wctomb8 }
|
2012-12-18 08:12:15 +00:00
|
|
|
#if defined(QSE_ENABLE_XCMGRS)
|
2013-01-16 05:04:56 +00:00
|
|
|
,
|
|
|
|
{ qse_cp949touc, qse_uctocp949 },
|
|
|
|
{ qse_cp950touc, qse_uctocp950 }
|
2012-09-05 22:37:55 +00:00
|
|
|
#endif
|
2011-12-31 15:24:48 +00:00
|
|
|
};
|
|
|
|
|
2019-03-14 08:01:04 +00:00
|
|
|
#define DEFAULT_CMGR QSE_CMGR_UTF8
|
2015-04-27 08:37:57 +00:00
|
|
|
|
|
|
|
static qse_cmgr_t* dfl_cmgr = &builtin_cmgr[DEFAULT_CMGR];
|
2012-02-13 14:43:50 +00:00
|
|
|
static qse_cmgr_finder_t cmgr_finder = QSE_NULL;
|
2011-12-31 15:24:48 +00:00
|
|
|
|
|
|
|
qse_cmgr_t* qse_getdflcmgr (void)
|
|
|
|
{
|
|
|
|
return dfl_cmgr;
|
|
|
|
}
|
|
|
|
|
2015-04-27 08:37:57 +00:00
|
|
|
qse_cmgr_t* qse_setdflcmgr (qse_cmgr_t* cmgr)
|
2011-12-31 15:24:48 +00:00
|
|
|
{
|
2015-04-27 08:37:57 +00:00
|
|
|
dfl_cmgr = (cmgr? cmgr: &builtin_cmgr[DEFAULT_CMGR]);
|
|
|
|
return dfl_cmgr;
|
2012-09-05 22:37:55 +00:00
|
|
|
}
|
|
|
|
|
2015-04-27 08:37:57 +00:00
|
|
|
qse_cmgr_t* qse_setdflcmgrbyid (qse_cmgr_id_t id)
|
2012-09-05 22:37:55 +00:00
|
|
|
{
|
|
|
|
qse_cmgr_t* cmgr = qse_findcmgrbyid (id);
|
2015-04-27 08:37:57 +00:00
|
|
|
dfl_cmgr = (cmgr? cmgr: &builtin_cmgr[DEFAULT_CMGR]);
|
|
|
|
return dfl_cmgr;
|
2012-09-05 22:37:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
qse_cmgr_t* qse_findcmgrbyid (qse_cmgr_id_t id)
|
|
|
|
{
|
|
|
|
if (id < 0 || id >= QSE_COUNTOF(builtin_cmgr)) return QSE_NULL;
|
|
|
|
return &builtin_cmgr[id];
|
2011-12-31 15:24:48 +00:00
|
|
|
}
|
|
|
|
|
2012-02-13 14:43:50 +00:00
|
|
|
qse_cmgr_t* qse_findcmgr (const qse_char_t* name)
|
2012-01-17 16:45:01 +00:00
|
|
|
{
|
2013-01-16 05:04:56 +00:00
|
|
|
/* TODO: binary search or something better for performance improvement
|
|
|
|
* when there are many entries in the table */
|
2012-09-05 22:37:55 +00:00
|
|
|
static struct
|
|
|
|
{
|
|
|
|
const qse_char_t* name;
|
|
|
|
qse_cmgr_id_t id;
|
|
|
|
} tab[] =
|
|
|
|
{
|
|
|
|
{ QSE_T("utf8"), QSE_CMGR_UTF8 },
|
2012-12-18 08:12:15 +00:00
|
|
|
#if defined(QSE_ENABLE_XCMGRS)
|
2012-09-05 22:37:55 +00:00
|
|
|
{ QSE_T("cp949"), QSE_CMGR_CP949 },
|
|
|
|
{ QSE_T("cp950"), QSE_CMGR_CP950 },
|
|
|
|
#endif
|
2013-01-16 05:04:56 +00:00
|
|
|
{ QSE_T("slmb"), QSE_CMGR_SLMB },
|
|
|
|
{ QSE_T("mb8"), QSE_CMGR_MB8 }
|
2012-09-05 22:37:55 +00:00
|
|
|
};
|
|
|
|
|
2012-01-17 16:45:01 +00:00
|
|
|
if (name)
|
|
|
|
{
|
2012-09-05 22:37:55 +00:00
|
|
|
qse_size_t i;
|
|
|
|
|
2012-02-13 14:43:50 +00:00
|
|
|
if (cmgr_finder)
|
|
|
|
{
|
|
|
|
qse_cmgr_t* cmgr;
|
|
|
|
cmgr = cmgr_finder (name);
|
|
|
|
if (cmgr) return cmgr;
|
|
|
|
}
|
|
|
|
|
2012-08-09 10:15:11 +00:00
|
|
|
if (qse_strcasecmp(name, QSE_T("")) == 0) return dfl_cmgr;
|
2012-09-05 22:37:55 +00:00
|
|
|
|
|
|
|
for (i = 0; i < QSE_COUNTOF(tab); i++)
|
|
|
|
{
|
|
|
|
if (qse_strcasecmp(name, tab[i].name) == 0)
|
|
|
|
{
|
|
|
|
return &builtin_cmgr[tab[i].id];
|
|
|
|
}
|
|
|
|
}
|
2012-01-17 16:45:01 +00:00
|
|
|
}
|
2012-09-05 22:37:55 +00:00
|
|
|
|
2012-01-17 16:45:01 +00:00
|
|
|
return QSE_NULL;
|
|
|
|
}
|
|
|
|
|
2012-02-13 14:43:50 +00:00
|
|
|
void qse_setcmgrfinder (qse_cmgr_finder_t finder)
|
|
|
|
{
|
|
|
|
cmgr_finder = finder;
|
|
|
|
}
|
|
|
|
|
|
|
|
qse_cmgr_finder_t qse_getcmgrfinder (void)
|
|
|
|
{
|
|
|
|
return cmgr_finder;
|
|
|
|
}
|
|
|
|
|
2011-12-31 15:24:48 +00:00
|
|
|
/* string conversion function using default character conversion manager */
|
|
|
|
|
|
|
|
int qse_mbstowcs (
|
|
|
|
const qse_mchar_t* mbs, qse_size_t* mbslen,
|
|
|
|
qse_wchar_t* wcs, qse_size_t* wcslen)
|
|
|
|
{
|
|
|
|
return qse_mbstowcswithcmgr (mbs, mbslen, wcs, wcslen, dfl_cmgr);
|
|
|
|
}
|
|
|
|
|
2012-01-15 15:25:28 +00:00
|
|
|
int qse_mbstowcsall (
|
|
|
|
const qse_mchar_t* mbs, qse_size_t* mbslen,
|
|
|
|
qse_wchar_t* wcs, qse_size_t* wcslen)
|
|
|
|
{
|
|
|
|
return qse_mbstowcsallwithcmgr (mbs, mbslen, wcs, wcslen, dfl_cmgr);
|
|
|
|
}
|
|
|
|
|
2011-12-31 15:24:48 +00:00
|
|
|
int qse_mbsntowcsn (
|
|
|
|
const qse_mchar_t* mbs, qse_size_t* mbslen,
|
|
|
|
qse_wchar_t* wcs, qse_size_t* wcslen)
|
|
|
|
{
|
|
|
|
return qse_mbsntowcsnwithcmgr (mbs, mbslen, wcs, wcslen, dfl_cmgr);
|
|
|
|
}
|
|
|
|
|
2012-01-15 15:25:28 +00:00
|
|
|
int qse_mbsntowcsnall (
|
|
|
|
const qse_mchar_t* mbs, qse_size_t* mbslen,
|
|
|
|
qse_wchar_t* wcs, qse_size_t* wcslen)
|
|
|
|
{
|
|
|
|
return qse_mbsntowcsnallwithcmgr (mbs, mbslen, wcs, wcslen, dfl_cmgr);
|
|
|
|
}
|
|
|
|
|
2011-12-31 15:24:48 +00:00
|
|
|
int qse_mbsntowcsnupto (
|
|
|
|
const qse_mchar_t* mbs, qse_size_t* mbslen,
|
|
|
|
qse_wchar_t* wcs, qse_size_t* wcslen, qse_wchar_t stopper)
|
|
|
|
{
|
2012-01-02 15:11:43 +00:00
|
|
|
return qse_mbsntowcsnuptowithcmgr (
|
|
|
|
mbs, mbslen, wcs, wcslen, stopper, dfl_cmgr);
|
2011-12-31 15:24:48 +00:00
|
|
|
}
|
|
|
|
|
2012-10-18 06:52:03 +00:00
|
|
|
qse_wchar_t* qse_mbstowcsdup (
|
|
|
|
const qse_mchar_t* mbs, qse_size_t* wcslen, qse_mmgr_t* mmgr)
|
2011-12-31 15:24:48 +00:00
|
|
|
{
|
2012-10-18 06:52:03 +00:00
|
|
|
return qse_mbstowcsdupwithcmgr (mbs, wcslen, mmgr, dfl_cmgr);
|
2011-12-31 15:24:48 +00:00
|
|
|
}
|
|
|
|
|
2012-10-18 06:52:03 +00:00
|
|
|
qse_wchar_t* qse_mbstowcsalldup (
|
|
|
|
const qse_mchar_t* mbs, qse_size_t* wcslen, qse_mmgr_t* mmgr)
|
2012-01-15 15:25:28 +00:00
|
|
|
{
|
2012-10-18 06:52:03 +00:00
|
|
|
return qse_mbstowcsalldupwithcmgr (mbs, wcslen, mmgr, dfl_cmgr);
|
2012-01-15 15:25:28 +00:00
|
|
|
}
|
|
|
|
|
2012-10-29 14:41:39 +00:00
|
|
|
qse_wchar_t* qse_mbsntowcsdup (
|
|
|
|
const qse_mchar_t* mbs, qse_size_t* mbslen, qse_size_t* wcslen, qse_mmgr_t* mmgr)
|
|
|
|
{
|
|
|
|
return qse_mbsntowcsdupwithcmgr (mbs, mbslen, wcslen, mmgr, dfl_cmgr);
|
|
|
|
}
|
|
|
|
|
|
|
|
qse_wchar_t* qse_mbsntowcsalldup (
|
|
|
|
const qse_mchar_t* mbs, qse_size_t* mbslen, qse_size_t* wcslen, qse_mmgr_t* mmgr)
|
|
|
|
{
|
|
|
|
return qse_mbsntowcsalldupwithcmgr (mbs, mbslen, wcslen, mmgr, dfl_cmgr);
|
|
|
|
}
|
|
|
|
|
2012-10-18 06:52:03 +00:00
|
|
|
qse_wchar_t* qse_mbsatowcsdup (
|
|
|
|
const qse_mchar_t* mbs[], qse_size_t* wcslen, qse_mmgr_t* mmgr)
|
2011-12-31 15:24:48 +00:00
|
|
|
{
|
2012-10-18 06:52:03 +00:00
|
|
|
return qse_mbsatowcsdupwithcmgr (mbs, wcslen, mmgr, dfl_cmgr);
|
2011-12-31 15:24:48 +00:00
|
|
|
}
|
|
|
|
|
2012-10-18 06:52:03 +00:00
|
|
|
qse_wchar_t* qse_mbsatowcsalldup (
|
|
|
|
const qse_mchar_t* mbs[], qse_size_t* wcslen, qse_mmgr_t* mmgr)
|
2012-01-15 15:25:28 +00:00
|
|
|
{
|
2012-10-18 06:52:03 +00:00
|
|
|
return qse_mbsatowcsalldupwithcmgr (mbs, wcslen, mmgr, dfl_cmgr);
|
2012-01-15 15:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------- */
|
|
|
|
|
2011-12-31 15:24:48 +00:00
|
|
|
int qse_wcstombs (
|
|
|
|
const qse_wchar_t* wcs, qse_size_t* wcslen,
|
|
|
|
qse_mchar_t* mbs, qse_size_t* mbslen)
|
|
|
|
{
|
2020-08-28 09:37:46 +00:00
|
|
|
return qse_wcstombswithcmgr(wcs, wcslen, mbs, mbslen, dfl_cmgr);
|
2011-12-31 15:24:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int qse_wcsntombsn (
|
|
|
|
const qse_wchar_t* wcs, qse_size_t* wcslen,
|
|
|
|
qse_mchar_t* mbs, qse_size_t* mbslen)
|
|
|
|
{
|
2020-08-28 09:37:46 +00:00
|
|
|
return qse_wcsntombsnwithcmgr(wcs, wcslen, mbs, mbslen, dfl_cmgr);
|
2011-12-31 15:24:48 +00:00
|
|
|
}
|
|
|
|
|
2012-10-18 06:52:03 +00:00
|
|
|
qse_mchar_t* qse_wcstombsdup (
|
|
|
|
const qse_wchar_t* wcs, qse_size_t* mbslen, qse_mmgr_t* mmgr)
|
2011-12-31 15:24:48 +00:00
|
|
|
{
|
2020-08-28 09:37:46 +00:00
|
|
|
return qse_wcstombsdupwithcmgr(wcs, mbslen, mmgr, dfl_cmgr);
|
2011-12-31 15:24:48 +00:00
|
|
|
}
|
|
|
|
|
2012-10-18 06:52:03 +00:00
|
|
|
qse_mchar_t* qse_wcsntombsdup (
|
|
|
|
const qse_wchar_t* wcs, qse_size_t wcslen,
|
|
|
|
qse_size_t* mbslen, qse_mmgr_t* mmgr)
|
2012-09-30 13:56:20 +00:00
|
|
|
{
|
2020-08-28 09:37:46 +00:00
|
|
|
return qse_wcsntombsdupwithcmgr(wcs, wcslen, mbslen, mmgr, dfl_cmgr);
|
2012-09-30 13:56:20 +00:00
|
|
|
}
|
|
|
|
|
2012-10-18 06:52:03 +00:00
|
|
|
qse_mchar_t* qse_wcsatombsdup (
|
|
|
|
const qse_wchar_t* wcs[], qse_size_t* mbslen, qse_mmgr_t* mmgr)
|
2011-12-31 15:24:48 +00:00
|
|
|
{
|
2020-08-28 09:37:46 +00:00
|
|
|
return qse_wcsatombsdupwithcmgr(wcs, mbslen, mmgr, dfl_cmgr);
|
2011-12-31 15:24:48 +00:00
|
|
|
}
|
|
|
|
|
2012-10-18 06:52:03 +00:00
|
|
|
qse_mchar_t* qse_wcsnatombsdup (
|
2014-07-08 14:30:42 +00:00
|
|
|
const qse_wcstr_t wcs[], qse_size_t* mbslen, qse_mmgr_t* mmgr)
|
2012-10-18 06:52:03 +00:00
|
|
|
{
|
2020-08-28 09:37:46 +00:00
|
|
|
return qse_wcsnatombsdupwithcmgr(wcs, mbslen, mmgr, dfl_cmgr);
|
2012-10-18 06:52:03 +00:00
|
|
|
}
|