2013-10-24 14:55:15 +00:00
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
Copyright 2006-2012 Chung, Hyung-Hwan.
|
|
|
|
This file is part of QSE.
|
|
|
|
|
|
|
|
QSE is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as
|
|
|
|
published by the Free Software Foundation, either version 3 of
|
|
|
|
the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
QSE is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with QSE. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <qse/cmn/str.h>
|
2013-10-28 09:40:25 +00:00
|
|
|
#include <qse/cmn/mbwc.h>
|
2013-10-24 14:55:15 +00:00
|
|
|
#include "fmt.h"
|
|
|
|
|
2013-10-28 09:40:25 +00:00
|
|
|
struct mbuf_t
|
2013-10-24 14:55:15 +00:00
|
|
|
{
|
2013-10-28 09:40:25 +00:00
|
|
|
qse_mchar_t* ptr;
|
2013-10-24 14:55:15 +00:00
|
|
|
qse_size_t len;
|
|
|
|
qse_size_t capa;
|
|
|
|
};
|
2013-10-28 09:40:25 +00:00
|
|
|
typedef struct mbuf_t mbuf_t;
|
2013-10-24 14:55:15 +00:00
|
|
|
|
2013-10-28 09:40:25 +00:00
|
|
|
struct wbuf_t
|
2013-10-24 14:55:15 +00:00
|
|
|
{
|
2013-10-28 09:40:25 +00:00
|
|
|
qse_wchar_t* ptr;
|
2013-10-24 14:55:15 +00:00
|
|
|
qse_size_t len;
|
|
|
|
qse_size_t capa;
|
|
|
|
};
|
|
|
|
typedef struct wbuf_t wbuf_t;
|
|
|
|
|
2013-10-28 09:40:25 +00:00
|
|
|
|
|
|
|
static int put_mchar (qse_mchar_t c, void* ctx)
|
2013-10-24 14:55:15 +00:00
|
|
|
{
|
2013-10-28 09:40:25 +00:00
|
|
|
mbuf_t* buf = (mbuf_t*)ctx;
|
2013-10-29 14:14:43 +00:00
|
|
|
|
|
|
|
/* do not copy but return success if the buffer pointer
|
|
|
|
* points to NULL. this is to let the caller specify
|
|
|
|
* NULL as a buffer to get the length required for the
|
|
|
|
* full formatting excluding the terminating NULL.
|
|
|
|
* The actual length required is the return value + 1. */
|
|
|
|
if (buf->ptr == QSE_NULL)
|
|
|
|
{
|
|
|
|
buf->len++;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else if (buf->len < buf->capa)
|
2013-10-28 09:40:25 +00:00
|
|
|
{
|
|
|
|
buf->ptr[buf->len++] = c;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-10-29 14:14:43 +00:00
|
|
|
/* buffer is full stop. but no error */
|
|
|
|
return 0;
|
2013-10-24 14:55:15 +00:00
|
|
|
}
|
|
|
|
|
2013-10-28 09:40:25 +00:00
|
|
|
static int put_wchar (qse_wchar_t c, void* ctx)
|
2013-10-24 14:55:15 +00:00
|
|
|
{
|
2013-10-28 09:40:25 +00:00
|
|
|
wbuf_t* buf = (wbuf_t*)ctx;
|
2013-10-29 14:14:43 +00:00
|
|
|
|
|
|
|
/* do not copy but return success if the buffer pointer
|
|
|
|
* points to NULL. this is to let the caller specify
|
|
|
|
* NULL as a buffer to get the length required for the
|
|
|
|
* full formatting excluding the terminating NULL.
|
|
|
|
* The actual length required is the return value + 1. */
|
|
|
|
if (buf->ptr == QSE_NULL) return 1;
|
|
|
|
|
2013-10-28 09:40:25 +00:00
|
|
|
if (buf->len < buf->capa)
|
|
|
|
{
|
|
|
|
buf->ptr[buf->len++] = c;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-10-29 14:14:43 +00:00
|
|
|
/* buffer is full stop. but no error */
|
|
|
|
return 0;
|
2013-10-24 14:55:15 +00:00
|
|
|
}
|
|
|
|
|
2013-10-28 09:40:25 +00:00
|
|
|
static int wcs_to_mbs (
|
|
|
|
const qse_wchar_t* wcs, qse_size_t* wcslen,
|
|
|
|
qse_mchar_t* mbs, qse_size_t* mbslen, void* ctx)
|
2013-10-24 14:55:15 +00:00
|
|
|
{
|
2013-10-28 09:40:25 +00:00
|
|
|
return qse_wcsntombsnwithcmgr (wcs, wcslen, mbs, mbslen, qse_getdflcmgr());
|
2013-10-24 14:55:15 +00:00
|
|
|
}
|
|
|
|
|
2013-10-28 09:40:25 +00:00
|
|
|
static int mbs_to_wcs (
|
|
|
|
const qse_mchar_t* mbs, qse_size_t* mbslen,
|
|
|
|
qse_wchar_t* wcs, qse_size_t* wcslen, void* ctx)
|
2013-10-24 14:55:15 +00:00
|
|
|
{
|
2013-10-28 09:40:25 +00:00
|
|
|
return qse_mbsntowcsnwithcmgr (mbs, mbslen, wcs, wcslen, qse_getdflcmgr());
|
2013-10-24 14:55:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------- */
|
|
|
|
|
|
|
|
#undef T
|
|
|
|
#undef char_t
|
|
|
|
#undef buf_t
|
2013-10-28 09:40:25 +00:00
|
|
|
#undef fmtout_t
|
2013-10-24 14:55:15 +00:00
|
|
|
#undef fmtout
|
2013-10-28 09:40:25 +00:00
|
|
|
#undef put_char
|
|
|
|
#undef conv_char
|
2013-10-24 14:55:15 +00:00
|
|
|
#undef strfmt
|
|
|
|
#undef strxfmt
|
|
|
|
|
|
|
|
#define T(x) QSE_MT(x)
|
|
|
|
#define char_t qse_mchar_t
|
|
|
|
#define buf_t mbuf_t
|
2013-10-28 09:40:25 +00:00
|
|
|
#define fmtout_t qse_mfmtout_t
|
2013-10-24 14:55:15 +00:00
|
|
|
#define fmtout qse_mfmtout
|
2013-10-28 09:40:25 +00:00
|
|
|
#define put_char put_mchar
|
|
|
|
#define conv_char wcs_to_mbs
|
2013-10-24 14:55:15 +00:00
|
|
|
#define strfmt qse_mbsfmt
|
|
|
|
#define strxfmt qse_mbsxfmt
|
|
|
|
#include "str-fmt.h"
|
|
|
|
|
|
|
|
/* ----------------------------------- */
|
|
|
|
|
|
|
|
#undef T
|
|
|
|
#undef char_t
|
|
|
|
#undef buf_t
|
2013-10-28 09:40:25 +00:00
|
|
|
#undef fmtout_t
|
2013-10-24 14:55:15 +00:00
|
|
|
#undef fmtout
|
2013-10-28 09:40:25 +00:00
|
|
|
#undef put_char
|
|
|
|
#undef conv_char
|
2013-10-24 14:55:15 +00:00
|
|
|
#undef strfmt
|
|
|
|
#undef strxfmt
|
|
|
|
|
|
|
|
#define T(x) QSE_WT(x)
|
|
|
|
#define char_t qse_wchar_t
|
|
|
|
#define buf_t wbuf_t
|
2013-10-28 09:40:25 +00:00
|
|
|
#define fmtout_t qse_wfmtout_t
|
2013-10-24 14:55:15 +00:00
|
|
|
#define fmtout qse_wfmtout
|
2013-10-28 09:40:25 +00:00
|
|
|
#define put_char put_wchar
|
|
|
|
#define conv_char mbs_to_wcs
|
|
|
|
#define strfmt qse_wcsfmt
|
|
|
|
#define strxfmt qse_wcsxfmt
|
2013-10-24 14:55:15 +00:00
|
|
|
#include "str-fmt.h"
|
|
|
|
|