enhanced a few code segments that convert a digit to a number

This commit is contained in:
2011-11-09 00:54:27 +00:00
parent f2615f05a5
commit 595aab7555
8 changed files with 25 additions and 32 deletions

View File

@ -43,7 +43,7 @@
# include "syscall.h"
#endif
#define NTOC(n) (((n) >= 10)? (((n) - 10) + QSE_T('A')): (n) + QSE_T('0'))
#define NTOC(n) (QSE_T("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")[n])
#define WRITE_CHAR(c) \
do { \
qse_char_t __xxx_c = c; \

View File

@ -30,20 +30,20 @@ static int fmt_unsigned_to_mbs (
qse_mchar_t tmp[(QSE_SIZEOF(qse_uintmax_t) * 8)];
int reslen, base, xsize, reqlen, pflen;
qse_mchar_t* p, * bp, * be;
qse_mchar_t xbasechar;
const qse_mchar_t* xbasestr;
base = base_and_flags & 0xFF;
if (base < 2 || base > 36) return -1;
xbasechar = (base_and_flags & QSE_FMTINTMAXTOMBS_UPPERCASE)? QSE_MT('A'): QSE_MT('a');
xbasestr = (base_and_flags & QSE_FMTINTMAXTOMBS_UPPERCASE)?
QSE_MT("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"):
QSE_MT("0123456789abcdefghijklmnopqrstuvwxyz");
/* store the resulting numeric string into 'tmp' first */
p = tmp;
do
{
int digit = value % base;
if (digit < 10) *p++ = digit + QSE_MT('0');
else *p++ = digit + xbasechar - 10;
*p++ = xbasestr[value % base];
value /= base;
}
while (value > 0);
@ -210,20 +210,20 @@ static int fmt_unsigned_to_wcs (
qse_wchar_t tmp[(QSE_SIZEOF(qse_uintmax_t) * 8)];
int reslen, base, xsize, reqlen, pflen;
qse_wchar_t* p, * bp, * be;
qse_wchar_t xbasechar;
const qse_wchar_t* xbasestr;
base = base_and_flags & 0xFF;
if (base < 2 || base > 36) return -1;
xbasechar = (base_and_flags & QSE_FMTINTMAXTOWCS_UPPERCASE)? QSE_WT('A'): QSE_WT('a');
xbasestr = (base_and_flags & QSE_FMTINTMAXTOWCS_UPPERCASE)?
QSE_WT("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"):
QSE_WT("0123456789abcdefghijklmnopqrstuvwxyz");
/* store the resulting numeric string into 'tmp' first */
p = tmp;
do
{
int digit = value % base;
if (digit < 10) *p++ = digit + QSE_WT('0');
else *p++ = digit + xbasechar - 10;
*p++ = xbasestr[value % base];
value /= base;
}
while (value > 0);

View File

@ -1,5 +1,5 @@
/*
* $Id: utf8.c 50 2009-02-10 05:48:05Z hyunghwan.chung $
* $Id$
*
Copyright 2006-2011 Chung, Hyung-Hwan.
This file is part of QSE.