2008-03-18 22:09:04 +00:00
|
|
|
/*
|
2012-08-16 03:47:55 +00:00
|
|
|
* $Id$
|
2008-03-18 22:09:04 +00:00
|
|
|
*
|
2019-06-06 05:28:23 +00:00
|
|
|
Copyright (c) 2006-2019 Chung, Hyung-Hwan. All rights reserved.
|
2009-01-06 04:40:25 +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.
|
2009-01-06 04:40:25 +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.
|
2008-03-18 22:09:04 +00:00
|
|
|
*/
|
|
|
|
|
2008-12-21 21:35:07 +00:00
|
|
|
#include <qse/cmn/str.h>
|
2009-01-18 01:48:21 +00:00
|
|
|
#include <qse/cmn/chr.h>
|
2016-04-29 03:55:42 +00:00
|
|
|
#include "mem-prv.h"
|
2008-03-18 22:09:04 +00:00
|
|
|
|
2014-08-30 05:40:57 +00:00
|
|
|
|
|
|
|
/*---------------------------------------------------------------
|
|
|
|
* multi-byte string to number conversion
|
|
|
|
*---------------------------------------------------------------*/
|
2017-12-18 07:20:02 +00:00
|
|
|
int qse_mbstoi (const qse_mchar_t* mbs, int base, const qse_mchar_t** end)
|
2008-03-19 00:29:25 +00:00
|
|
|
{
|
|
|
|
int v;
|
2017-12-18 07:20:02 +00:00
|
|
|
|
|
|
|
QSE_MBSTONUM (v, mbs, end, base, 1);
|
2008-03-19 00:29:25 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2018-01-19 15:57:44 +00:00
|
|
|
long int qse_mbstol (const qse_mchar_t* mbs, int base, const qse_mchar_t** end)
|
2008-03-19 00:29:25 +00:00
|
|
|
{
|
2018-01-19 15:57:44 +00:00
|
|
|
long int v;
|
2017-12-18 07:20:02 +00:00
|
|
|
QSE_MBSTONUM (v, mbs, end, base, 1);
|
2008-03-19 00:29:25 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2017-12-18 07:20:02 +00:00
|
|
|
unsigned int qse_mbstoui (const qse_mchar_t* mbs, int base, const qse_mchar_t** end)
|
2008-03-19 00:29:25 +00:00
|
|
|
{
|
|
|
|
unsigned int v;
|
2017-12-18 07:20:02 +00:00
|
|
|
QSE_MBSTONUM (v, mbs, end, base, 0);
|
2008-03-19 00:29:25 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2018-01-19 15:57:44 +00:00
|
|
|
unsigned long int qse_mbstoul (const qse_mchar_t* mbs, int base, const qse_mchar_t** end)
|
2008-03-19 00:29:25 +00:00
|
|
|
{
|
2018-01-19 15:57:44 +00:00
|
|
|
unsigned long int v;
|
2017-12-18 07:20:02 +00:00
|
|
|
QSE_MBSTONUM (v, mbs, end, base, 0);
|
2008-03-19 00:29:25 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2017-12-18 07:20:02 +00:00
|
|
|
/* ----- */
|
|
|
|
|
|
|
|
int qse_mbsxtoi (const qse_mchar_t* mbs, qse_size_t len, int base, const qse_mchar_t** end)
|
2008-03-19 00:29:25 +00:00
|
|
|
{
|
|
|
|
int v;
|
2017-12-18 07:20:02 +00:00
|
|
|
QSE_MBSXTONUM (v, mbs, len, end, base, 1);
|
2008-03-19 00:29:25 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2018-01-19 15:57:44 +00:00
|
|
|
long int qse_mbsxtol (const qse_mchar_t* mbs, qse_size_t len, int base, const qse_mchar_t** end)
|
2008-03-19 00:29:25 +00:00
|
|
|
{
|
2018-01-19 15:57:44 +00:00
|
|
|
long int v;
|
2017-12-18 07:20:02 +00:00
|
|
|
QSE_MBSXTONUM (v, mbs, len, end, base, 1);
|
2008-03-19 00:29:25 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2017-12-18 07:20:02 +00:00
|
|
|
unsigned int qse_mbsxtoui (const qse_mchar_t* mbs, qse_size_t len, int base, const qse_mchar_t** end)
|
2008-03-19 00:29:25 +00:00
|
|
|
{
|
|
|
|
unsigned int v;
|
2017-12-18 07:20:02 +00:00
|
|
|
QSE_MBSXTONUM (v, mbs, len, end, base, 0);
|
2008-03-19 00:29:25 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2018-01-19 15:57:44 +00:00
|
|
|
unsigned long int qse_mbsxtoul (const qse_mchar_t* mbs, qse_size_t len, int base, const qse_mchar_t** end)
|
2008-03-19 00:29:25 +00:00
|
|
|
{
|
2018-01-19 15:57:44 +00:00
|
|
|
unsigned long int v;
|
2017-12-18 07:20:02 +00:00
|
|
|
QSE_MBSXTONUM (v, mbs, len, end, base, 0);
|
2008-03-19 00:29:25 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2017-12-18 07:20:02 +00:00
|
|
|
/* ----- */
|
|
|
|
|
|
|
|
qse_int_t qse_mbstoint (const qse_mchar_t* mbs, int base, const qse_mchar_t** end)
|
2008-03-18 22:09:04 +00:00
|
|
|
{
|
2008-12-21 21:35:07 +00:00
|
|
|
qse_int_t v;
|
2017-12-18 07:20:02 +00:00
|
|
|
QSE_MBSTONUM (v, mbs, end, base, 1);
|
2008-03-18 22:09:04 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2017-12-18 07:20:02 +00:00
|
|
|
qse_long_t qse_mbstolong (const qse_mchar_t* mbs, int base, const qse_mchar_t** end)
|
2008-03-18 22:09:04 +00:00
|
|
|
{
|
2008-12-21 21:35:07 +00:00
|
|
|
qse_long_t v;
|
2017-12-18 07:20:02 +00:00
|
|
|
QSE_MBSTONUM (v, mbs, end, base, 1);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
qse_intmax_t qse_mbstointmax (const qse_mchar_t* mbs, int base, const qse_mchar_t** end)
|
|
|
|
{
|
|
|
|
qse_intmax_t v;
|
|
|
|
QSE_MBSTONUM (v, mbs, end, base, 1);
|
2008-03-18 22:09:04 +00:00
|
|
|
return v;
|
|
|
|
}
|
2017-12-18 07:20:02 +00:00
|
|
|
/* ----- */
|
2008-03-18 22:09:04 +00:00
|
|
|
|
2017-12-18 07:20:02 +00:00
|
|
|
qse_uint_t qse_mbstouint (const qse_mchar_t* mbs, int base, const qse_mchar_t** end)
|
2008-03-18 22:09:04 +00:00
|
|
|
{
|
2008-12-21 21:35:07 +00:00
|
|
|
qse_uint_t v;
|
2017-12-18 07:20:02 +00:00
|
|
|
QSE_MBSTONUM (v, mbs, end, base, 0);
|
2008-03-18 22:09:04 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2017-12-18 07:20:02 +00:00
|
|
|
qse_ulong_t qse_mbstoulong (const qse_mchar_t* mbs, int base, const qse_mchar_t** end)
|
2008-03-18 22:09:04 +00:00
|
|
|
{
|
2008-12-21 21:35:07 +00:00
|
|
|
qse_ulong_t v;
|
2017-12-18 07:20:02 +00:00
|
|
|
QSE_MBSTONUM (v, mbs, end, base, 0);
|
2008-03-19 00:29:25 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2017-12-18 07:20:02 +00:00
|
|
|
qse_uintmax_t qse_mbstouintmax (const qse_mchar_t* mbs, int base, const qse_mchar_t** end)
|
|
|
|
{
|
|
|
|
qse_uintmax_t v;
|
|
|
|
QSE_MBSTONUM (v, mbs, end, base, 0);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----- */
|
|
|
|
|
|
|
|
qse_int_t qse_mbsxtoint (const qse_mchar_t* mbs, qse_size_t len, int base, const qse_mchar_t** end)
|
2008-03-19 00:29:25 +00:00
|
|
|
{
|
2008-12-21 21:35:07 +00:00
|
|
|
qse_int_t v;
|
2017-12-18 07:20:02 +00:00
|
|
|
QSE_MBSXTONUM (v, mbs, len, end, base, 1);
|
2008-03-19 00:29:25 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2017-12-18 07:20:02 +00:00
|
|
|
qse_long_t qse_mbsxtolong (const qse_mchar_t* mbs, qse_size_t len, int base, const qse_mchar_t** end)
|
2008-03-19 00:29:25 +00:00
|
|
|
{
|
2008-12-21 21:35:07 +00:00
|
|
|
qse_long_t v;
|
2017-12-18 07:20:02 +00:00
|
|
|
QSE_MBSXTONUM (v, mbs, len, end, base, 1);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
qse_intmax_t qse_mbsxtointmax (const qse_mchar_t* mbs, qse_size_t len, int base, const qse_mchar_t** end)
|
|
|
|
{
|
|
|
|
qse_intmax_t v;
|
|
|
|
QSE_MBSXTONUM (v, mbs, len, end, base, 1);
|
2008-03-19 00:29:25 +00:00
|
|
|
return v;
|
|
|
|
}
|
2017-12-18 07:20:02 +00:00
|
|
|
/* ----- */
|
2008-03-19 00:29:25 +00:00
|
|
|
|
2017-12-18 07:20:02 +00:00
|
|
|
qse_uint_t qse_mbsxtouint (const qse_mchar_t* mbs, qse_size_t len, int base, const qse_mchar_t** end)
|
2008-03-19 00:29:25 +00:00
|
|
|
{
|
2008-12-21 21:35:07 +00:00
|
|
|
qse_uint_t v;
|
2017-12-18 07:20:02 +00:00
|
|
|
QSE_MBSXTONUM (v, mbs, len, end, base, 0);
|
2008-03-19 00:29:25 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2017-12-18 07:20:02 +00:00
|
|
|
qse_ulong_t qse_mbsxtoulong (const qse_mchar_t* mbs, qse_size_t len, int base, const qse_mchar_t** end)
|
2008-03-19 00:29:25 +00:00
|
|
|
{
|
2008-12-21 21:35:07 +00:00
|
|
|
qse_ulong_t v;
|
2017-12-18 07:20:02 +00:00
|
|
|
QSE_MBSXTONUM (v, mbs, len, end, base, 0);
|
2014-08-30 05:40:57 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-18 07:20:02 +00:00
|
|
|
qse_uintmax_t qse_mbsxtouintmax (const qse_mchar_t* mbs, qse_size_t len, int base, const qse_mchar_t** end)
|
|
|
|
{
|
|
|
|
qse_uintmax_t v;
|
|
|
|
QSE_MBSXTONUM (v, mbs, len, end, base, 0);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2014-08-30 05:40:57 +00:00
|
|
|
/*---------------------------------------------------------------
|
|
|
|
* wide string to number conversion
|
|
|
|
*---------------------------------------------------------------*/
|
2017-12-18 07:20:02 +00:00
|
|
|
int qse_wcstoi (const qse_wchar_t* wcs, int base, const qse_wchar_t** end)
|
2014-08-30 05:40:57 +00:00
|
|
|
{
|
|
|
|
int v;
|
2017-12-18 07:20:02 +00:00
|
|
|
QSE_WCSTONUM (v, wcs, end, base, 1);
|
2014-08-30 05:40:57 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2018-01-19 15:57:44 +00:00
|
|
|
long int qse_wcstol (const qse_wchar_t* wcs, int base, const qse_wchar_t** end)
|
2014-08-30 05:40:57 +00:00
|
|
|
{
|
2018-01-19 15:57:44 +00:00
|
|
|
long int v;
|
2017-12-18 07:20:02 +00:00
|
|
|
QSE_WCSTONUM (v, wcs, end, base, 1);
|
2014-08-30 05:40:57 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2017-12-18 07:20:02 +00:00
|
|
|
unsigned int qse_wcstoui (const qse_wchar_t* wcs, int base, const qse_wchar_t** end)
|
2014-08-30 05:40:57 +00:00
|
|
|
{
|
|
|
|
unsigned int v;
|
2017-12-18 07:20:02 +00:00
|
|
|
QSE_WCSTONUM (v, wcs, end, base, 0);
|
2014-08-30 05:40:57 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2018-01-19 15:57:44 +00:00
|
|
|
unsigned long int qse_wcstoul (const qse_wchar_t* wcs, int base, const qse_wchar_t** end)
|
2014-08-30 05:40:57 +00:00
|
|
|
{
|
2018-01-19 15:57:44 +00:00
|
|
|
unsigned long int v;
|
2017-12-18 07:20:02 +00:00
|
|
|
QSE_WCSTONUM (v, wcs, end, base, 0);
|
2014-08-30 05:40:57 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2017-12-18 07:20:02 +00:00
|
|
|
/* ----- */
|
|
|
|
|
|
|
|
int qse_wcsxtoi (const qse_wchar_t* wcs, qse_size_t len, int base, const qse_wchar_t** end)
|
2014-08-30 05:40:57 +00:00
|
|
|
{
|
|
|
|
int v;
|
2017-12-18 07:20:02 +00:00
|
|
|
QSE_WCSXTONUM (v, wcs, len, end, base, 1);
|
2008-03-18 22:09:04 +00:00
|
|
|
return v;
|
|
|
|
}
|
2008-10-18 05:43:20 +00:00
|
|
|
|
2018-01-19 15:57:44 +00:00
|
|
|
long int qse_wcsxtol (const qse_wchar_t* wcs, qse_size_t len, int base, const qse_wchar_t** end)
|
2014-08-30 05:40:57 +00:00
|
|
|
{
|
2018-01-19 15:57:44 +00:00
|
|
|
long int v;
|
2017-12-18 07:20:02 +00:00
|
|
|
QSE_WCSXTONUM (v, wcs, len, end, base, 1);
|
2014-08-30 05:40:57 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2017-12-18 07:20:02 +00:00
|
|
|
unsigned int qse_wcsxtoui (const qse_wchar_t* wcs, qse_size_t len, int base, const qse_wchar_t** end)
|
2014-08-30 05:40:57 +00:00
|
|
|
{
|
|
|
|
unsigned int v;
|
2017-12-18 07:20:02 +00:00
|
|
|
QSE_WCSXTONUM (v, wcs, len, end, base, 0);
|
2014-08-30 05:40:57 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2018-01-19 15:57:44 +00:00
|
|
|
unsigned long int qse_wcsxtoul (const qse_wchar_t* wcs, qse_size_t len, int base, const qse_wchar_t** end)
|
2014-08-30 05:40:57 +00:00
|
|
|
{
|
2018-01-19 15:57:44 +00:00
|
|
|
unsigned long int v;
|
2017-12-18 07:20:02 +00:00
|
|
|
QSE_WCSXTONUM (v, wcs, len, end, base, 0);
|
2014-08-30 05:40:57 +00:00
|
|
|
return v;
|
|
|
|
}
|
2011-03-26 10:02:04 +00:00
|
|
|
|
2017-12-18 07:20:02 +00:00
|
|
|
/* ----- */
|
|
|
|
|
|
|
|
qse_int_t qse_wcstoint (const qse_wchar_t* wcs, int base, const qse_wchar_t** end)
|
2014-08-30 05:40:57 +00:00
|
|
|
{
|
|
|
|
qse_int_t v;
|
2017-12-18 07:20:02 +00:00
|
|
|
QSE_WCSTONUM (v, wcs, end, base, 1);
|
2014-08-30 05:40:57 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2017-12-18 07:20:02 +00:00
|
|
|
qse_long_t qse_wcstolong (const qse_wchar_t* wcs, int base, const qse_wchar_t** end)
|
2014-08-30 05:40:57 +00:00
|
|
|
{
|
|
|
|
qse_long_t v;
|
2017-12-18 07:20:02 +00:00
|
|
|
QSE_WCSTONUM (v, wcs, end, base, 1);
|
2014-08-30 05:40:57 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2017-12-18 07:20:02 +00:00
|
|
|
qse_intmax_t qse_wcstointmax (const qse_wchar_t* wcs, int base, const qse_wchar_t** end)
|
|
|
|
{
|
|
|
|
qse_intmax_t v;
|
|
|
|
QSE_WCSTONUM (v, wcs, end, base, 1);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----- */
|
|
|
|
qse_uint_t qse_wcstouint (const qse_wchar_t* wcs, int base, const qse_wchar_t** end)
|
2014-08-30 05:40:57 +00:00
|
|
|
{
|
|
|
|
qse_uint_t v;
|
2017-12-18 07:20:02 +00:00
|
|
|
QSE_WCSTONUM (v, wcs, end, base, 0);
|
2014-08-30 05:40:57 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2017-12-18 07:20:02 +00:00
|
|
|
qse_ulong_t qse_wcstoulong (const qse_wchar_t* wcs, int base, const qse_wchar_t** end)
|
2014-08-30 05:40:57 +00:00
|
|
|
{
|
|
|
|
qse_ulong_t v;
|
2017-12-18 07:20:02 +00:00
|
|
|
QSE_WCSTONUM (v, wcs, end, base, 0);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
qse_uintmax_t qse_wcstouintmax (const qse_wchar_t* wcs, int base, const qse_wchar_t** end)
|
|
|
|
{
|
|
|
|
qse_uintmax_t v;
|
|
|
|
QSE_WCSTONUM (v, wcs, end, base, 0);
|
2014-08-30 05:40:57 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2017-12-18 07:20:02 +00:00
|
|
|
/* ----- */
|
|
|
|
qse_int_t qse_wcsxtoint (const qse_wchar_t* wcs, qse_size_t len, int base, const qse_wchar_t** end)
|
2014-08-30 05:40:57 +00:00
|
|
|
{
|
|
|
|
qse_int_t v;
|
2017-12-18 07:20:02 +00:00
|
|
|
QSE_WCSXTONUM (v, wcs, len, end, base, 1);
|
2014-08-30 05:40:57 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2017-12-18 07:20:02 +00:00
|
|
|
qse_long_t qse_wcsxtolong (const qse_wchar_t* wcs, qse_size_t len, int base, const qse_wchar_t** end)
|
2014-08-30 05:40:57 +00:00
|
|
|
{
|
|
|
|
qse_long_t v;
|
2017-12-18 07:20:02 +00:00
|
|
|
QSE_WCSXTONUM (v, wcs, len, end, base, 1);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
qse_intmax_t qse_wcsxtointmax (const qse_wchar_t* wcs, qse_size_t len, int base, const qse_wchar_t** end)
|
|
|
|
{
|
|
|
|
qse_intmax_t v;
|
|
|
|
QSE_WCSXTONUM (v, wcs, len, end, base, 1);
|
2014-08-30 05:40:57 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2017-12-18 07:20:02 +00:00
|
|
|
/* ----- */
|
|
|
|
qse_uint_t qse_wcsxtouint (const qse_wchar_t* wcs, qse_size_t len, int base, const qse_wchar_t** end)
|
2014-08-30 05:40:57 +00:00
|
|
|
{
|
|
|
|
qse_uint_t v;
|
2017-12-18 07:20:02 +00:00
|
|
|
QSE_WCSXTONUM (v, wcs, len, end, base, 0);
|
2014-08-30 05:40:57 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2017-12-18 07:20:02 +00:00
|
|
|
qse_ulong_t qse_wcsxtoulong (const qse_wchar_t* wcs, qse_size_t len, int base, const qse_wchar_t** end)
|
2014-08-30 05:40:57 +00:00
|
|
|
{
|
|
|
|
qse_ulong_t v;
|
2017-12-18 07:20:02 +00:00
|
|
|
QSE_WCSXTONUM (v, wcs, len, end, base, 0);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
qse_uintmax_t qse_wcsxtouintmax (const qse_wchar_t* wcs, qse_size_t len, int base, const qse_wchar_t** end)
|
|
|
|
{
|
|
|
|
qse_uintmax_t v;
|
|
|
|
QSE_WCSXTONUM (v, wcs, len, end, base, 0);
|
2014-08-30 05:40:57 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------
|
|
|
|
* case conversion
|
|
|
|
*---------------------------------------------------------------*/
|
2011-03-26 10:02:04 +00:00
|
|
|
qse_size_t qse_mbslwr (qse_mchar_t* str)
|
|
|
|
{
|
|
|
|
qse_mchar_t* p = str;
|
|
|
|
for (p = str; *p != QSE_MT('\0'); p++) *p = QSE_TOMLOWER (*p);
|
|
|
|
return p - str;
|
|
|
|
}
|
|
|
|
|
|
|
|
qse_size_t qse_mbsupr (qse_mchar_t* str)
|
|
|
|
{
|
|
|
|
qse_mchar_t* p = str;
|
|
|
|
for (p = str; *p != QSE_MT('\0'); p++) *p = QSE_TOMUPPER (*p);
|
|
|
|
return p - str;
|
|
|
|
}
|
|
|
|
|
|
|
|
qse_size_t qse_wcslwr (qse_wchar_t* str)
|
|
|
|
{
|
|
|
|
qse_wchar_t* p = str;
|
|
|
|
for (p = str; *p != QSE_WT('\0'); p++) *p = QSE_TOWLOWER (*p);
|
|
|
|
return p - str;
|
|
|
|
}
|
|
|
|
|
|
|
|
qse_size_t qse_wcsupr (qse_wchar_t* str)
|
|
|
|
{
|
|
|
|
qse_wchar_t* p = str;
|
|
|
|
for (p = str; *p != QSE_WT('\0'); p++) *p = QSE_TOWUPPER (*p);
|
|
|
|
return p - str;
|
|
|
|
}
|
2014-08-30 05:40:57 +00:00
|
|
|
|
|
|
|
/*---------------------------------------------------------------
|
|
|
|
* Hexadecimal string conversion
|
|
|
|
*---------------------------------------------------------------*/
|
|
|
|
|
|
|
|
int qse_mbshextobin (const qse_mchar_t* hex, qse_size_t hexlen, qse_uint8_t* buf, qse_size_t buflen)
|
|
|
|
{
|
|
|
|
const qse_mchar_t* end = hex + hexlen;
|
|
|
|
qse_size_t bi = 0;
|
|
|
|
|
|
|
|
while (hex < end && bi < buflen)
|
|
|
|
{
|
|
|
|
int v;
|
|
|
|
|
2017-09-13 14:04:01 +00:00
|
|
|
v = QSE_MXDIGITTONUM(*hex);
|
|
|
|
if (v <= -1) return -1;
|
2014-08-30 05:40:57 +00:00
|
|
|
buf[bi] = buf[bi] * 16 + v;
|
|
|
|
|
|
|
|
hex++;
|
|
|
|
if (hex >= end) return -1;
|
|
|
|
|
2017-09-13 14:04:01 +00:00
|
|
|
v = QSE_MXDIGITTONUM(*hex);
|
|
|
|
if (v <= -1) return -1;
|
2014-08-30 05:40:57 +00:00
|
|
|
buf[bi] = buf[bi] * 16 + v;
|
|
|
|
|
|
|
|
hex++;
|
|
|
|
bi++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int qse_wcshextobin (const qse_wchar_t* hex, qse_size_t hexlen, qse_uint8_t* buf, qse_size_t buflen)
|
|
|
|
{
|
|
|
|
const qse_wchar_t* end = hex + hexlen;
|
|
|
|
qse_size_t bi = 0;
|
|
|
|
|
|
|
|
while (hex < end && bi < buflen)
|
|
|
|
{
|
|
|
|
int v;
|
|
|
|
|
2017-09-13 14:04:01 +00:00
|
|
|
v = QSE_WXDIGITTONUM(*hex);
|
|
|
|
if (v <= -1) return -1;
|
2014-08-30 05:40:57 +00:00
|
|
|
buf[bi] = buf[bi] * 16 + v;
|
|
|
|
|
|
|
|
hex++;
|
|
|
|
if (hex >= end) return -1;
|
|
|
|
|
2017-09-13 14:04:01 +00:00
|
|
|
v = QSE_WXDIGITTONUM(*hex);
|
|
|
|
if (v <= -1) return -1;
|
2014-08-30 05:40:57 +00:00
|
|
|
buf[bi] = buf[bi] * 16 + v;
|
|
|
|
|
|
|
|
hex++;
|
|
|
|
bi++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2019-03-15 08:10:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------
|
|
|
|
* Byte to string conversion
|
|
|
|
*---------------------------------------------------------------*/
|
|
|
|
qse_size_t qse_bytetombs (qse_byte_t byte, qse_mchar_t* buf, qse_size_t size, int flagged_radix, qse_mchar_t fill)
|
|
|
|
{
|
|
|
|
qse_mchar_t tmp[(QSE_SIZEOF(qse_byte_t) * 8)];
|
|
|
|
qse_mchar_t* p = tmp, * bp = buf, * be = buf + size - 1;
|
|
|
|
int radix;
|
|
|
|
qse_mchar_t radix_char;
|
|
|
|
|
|
|
|
radix = (flagged_radix & QSE_BYTETOSTR_RADIXMASK);
|
|
|
|
radix_char = (flagged_radix & QSE_BYTETOSTR_LOWERCASE)? QSE_MT('a'): QSE_MT('A');
|
|
|
|
if (radix < 2 || radix > 36 || size <= 0) return 0;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
qse_byte_t digit = byte % radix;
|
|
|
|
if (digit < 10) *p++ = digit + QSE_MT('0');
|
|
|
|
else *p++ = digit + radix_char - 10;
|
|
|
|
byte /= radix;
|
|
|
|
}
|
|
|
|
while (byte > 0);
|
|
|
|
|
|
|
|
if (fill != QSE_MT('\0'))
|
|
|
|
{
|
|
|
|
while (size - 1 > p - tmp)
|
|
|
|
{
|
|
|
|
*bp++ = fill;
|
|
|
|
size--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (p > tmp && bp < be) *bp++ = *--p;
|
|
|
|
*bp = QSE_MT('\0');
|
|
|
|
return bp - buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
qse_size_t qse_bytetowcs (qse_byte_t byte, qse_wchar_t* buf, qse_size_t size, int flagged_radix, qse_wchar_t fill)
|
|
|
|
{
|
|
|
|
qse_wchar_t tmp[(QSE_SIZEOF(qse_byte_t) * 8)];
|
|
|
|
qse_wchar_t* p = tmp, * bp = buf, * be = buf + size - 1;
|
|
|
|
int radix;
|
|
|
|
qse_wchar_t radix_char;
|
|
|
|
|
|
|
|
radix = (flagged_radix & QSE_BYTETOSTR_RADIXMASK);
|
|
|
|
radix_char = (flagged_radix & QSE_BYTETOSTR_LOWERCASE)? QSE_WT('a'): QSE_WT('A');
|
|
|
|
if (radix < 2 || radix > 36 || size <= 0) return 0;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
qse_byte_t digit = byte % radix;
|
|
|
|
if (digit < 10) *p++ = digit + QSE_WT('0');
|
|
|
|
else *p++ = digit + radix_char - 10;
|
|
|
|
byte /= radix;
|
|
|
|
}
|
|
|
|
while (byte > 0);
|
|
|
|
|
|
|
|
if (fill != QSE_WT('\0'))
|
|
|
|
{
|
|
|
|
while (size - 1 > p - tmp)
|
|
|
|
{
|
|
|
|
*bp++ = fill;
|
|
|
|
size--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (p > tmp && bp < be) *bp++ = *--p;
|
|
|
|
*bp = QSE_WT('\0');
|
|
|
|
return bp - buf;
|
|
|
|
}
|