changed the way to fall back to utf8 when system functions are not available

This commit is contained in:
hyung-hwan 2015-04-27 13:03:32 +00:00
parent c6644d5b52
commit 40c6e5f5fe
2 changed files with 31 additions and 15 deletions

View File

@ -50,13 +50,7 @@ static qse_cmgr_t builtin_cmgr[] =
#endif #endif
}; };
#if defined(_WIN32) && defined(HAVE_WCRTOMB) #define DEFAULT_CMGR QSE_CMGR_SLMB
/* read the comment at the bottom of qse_slwcrtoslmb() in slmb.c
* for the condition above. */
# define DEFAULT_CMGR QSE_CMGR_SLMB
#else
# define DEFAULT_CMGR QSE_CMGR_UTF8
#endif
static qse_cmgr_t* dfl_cmgr = &builtin_cmgr[DEFAULT_CMGR]; static qse_cmgr_t* dfl_cmgr = &builtin_cmgr[DEFAULT_CMGR];
static qse_cmgr_finder_t cmgr_finder = QSE_NULL; static qse_cmgr_finder_t cmgr_finder = QSE_NULL;

View File

@ -25,6 +25,7 @@
*/ */
#include <qse/cmn/slmb.h> #include <qse/cmn/slmb.h>
#include <qse/cmn/utf8.h>
#include "mem.h" #include "mem.h"
#if !defined(QSE_HAVE_CONFIG_H) #if !defined(QSE_HAVE_CONFIG_H)
@ -50,11 +51,24 @@
# include <windows.h> # include <windows.h>
#endif #endif
#if defined(_WIN32) || (defined(HAVE_WCRTOMB) && defined(HAVE_MBRTOWC) && defined(HAVE_MBRLEN))
/* use system locale */
# undef FORCE_UTF8
#else
/* force to use UTF8 as required functions are not available */
# define FORCE_UTF8 1
#endif
qse_size_t qse_slwcrtoslmb ( qse_size_t qse_slwcrtoslmb (
qse_wchar_t wc, qse_mchar_t* mb, qse_wchar_t wc, qse_mchar_t* mb,
qse_size_t mbl, qse_mbstate_t* state) qse_size_t mbl, qse_mbstate_t* state)
{ {
#if defined(_WIN32)
#if defined(FORCE_UTF8)
return qse_uctoutf8 (wc, mb, mbl);
#elif defined(_WIN32)
int n; int n;
/* CP_THREAD_ACP results in ERROR_INVALID_PARAMETER /* CP_THREAD_ACP results in ERROR_INVALID_PARAMETER
@ -104,10 +118,8 @@ qse_size_t qse_slwcrtoslmb (
#else #else
/* not supported */ /* not supported */
/* make sure to update the precessor condition to set DEFAULT_CMGR
* in mbwc.c when you have different implementation here */
return 0; return 0;
#endif #endif
} }
@ -115,7 +127,11 @@ qse_size_t qse_slmbrtoslwc (
const qse_mchar_t* mb, qse_size_t mbl, const qse_mchar_t* mb, qse_size_t mbl,
qse_wchar_t* wc, qse_mbstate_t* state) qse_wchar_t* wc, qse_mbstate_t* state)
{ {
#if defined(_WIN32) #if defined(FORCE_UTF8)
return qse_utf8touc (mb, mbl, wc);
#elif defined(_WIN32)
qse_size_t dbcslen; qse_size_t dbcslen;
int n; int n;
@ -192,7 +208,10 @@ qse_size_t qse_slmbrtoslwc (
qse_size_t qse_slmbrlen ( qse_size_t qse_slmbrlen (
const qse_mchar_t* mb, qse_size_t mbl, qse_mbstate_t* state) const qse_mchar_t* mb, qse_size_t mbl, qse_mbstate_t* state)
{ {
#if defined(_WIN32) #if defined(FORCE_UTF8)
return qse_utf8len (mb, mbl);
#elif defined(_WIN32)
qse_size_t dbcslen; qse_size_t dbcslen;
QSE_ASSERT (mb != QSE_NULL); QSE_ASSERT (mb != QSE_NULL);
@ -303,7 +322,10 @@ qse_size_t qse_slmblen (const qse_mchar_t* mb, qse_size_t mbl)
qse_size_t qse_slmblenmax (void) qse_size_t qse_slmblenmax (void)
{ {
#if defined(_WIN32) #if defined(FORCE_UTF8)
return qse_utf8lenmax ();
#elif defined(_WIN32)
/* Windows doesn't handle utf8 properly even when your code page /* Windows doesn't handle utf8 properly even when your code page
* is CP_UTF8(65001). you should use functions in utf8.c for utf8 * is CP_UTF8(65001). you should use functions in utf8.c for utf8
* handling on windows. 2 is the maximum for DBCS encodings. */ * handling on windows. 2 is the maximum for DBCS encodings. */