enhanced a few code segments that convert a digit to a number
This commit is contained in:
parent
f2615f05a5
commit
595aab7555
@ -189,12 +189,12 @@ Awk::Value::IntIndex::IntIndex (long_t x)
|
|||||||
ptr = buf;
|
ptr = buf;
|
||||||
len = 0;
|
len = 0;
|
||||||
|
|
||||||
#define NTOC(n) ((n) + QSE_T('0'))
|
#define NTOC(n) (QSE_T("0123456789")[n])
|
||||||
|
|
||||||
int base = 10;
|
int base = 10;
|
||||||
long_t last = x % base;
|
long_t last = x % base;
|
||||||
long_t y = 0;
|
long_t y = 0;
|
||||||
int dig = 0;
|
int dig = 0;
|
||||||
|
|
||||||
if (x < 0) buf[len++] = QSE_T('-');
|
if (x < 0) buf[len++] = QSE_T('-');
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@
|
|||||||
# include "syscall.h"
|
# include "syscall.h"
|
||||||
#endif
|
#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) \
|
#define WRITE_CHAR(c) \
|
||||||
do { \
|
do { \
|
||||||
qse_char_t __xxx_c = c; \
|
qse_char_t __xxx_c = c; \
|
||||||
|
@ -30,20 +30,20 @@ static int fmt_unsigned_to_mbs (
|
|||||||
qse_mchar_t tmp[(QSE_SIZEOF(qse_uintmax_t) * 8)];
|
qse_mchar_t tmp[(QSE_SIZEOF(qse_uintmax_t) * 8)];
|
||||||
int reslen, base, xsize, reqlen, pflen;
|
int reslen, base, xsize, reqlen, pflen;
|
||||||
qse_mchar_t* p, * bp, * be;
|
qse_mchar_t* p, * bp, * be;
|
||||||
qse_mchar_t xbasechar;
|
const qse_mchar_t* xbasestr;
|
||||||
|
|
||||||
base = base_and_flags & 0xFF;
|
base = base_and_flags & 0xFF;
|
||||||
if (base < 2 || base > 36) return -1;
|
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 */
|
/* store the resulting numeric string into 'tmp' first */
|
||||||
p = tmp;
|
p = tmp;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
int digit = value % base;
|
*p++ = xbasestr[value % base];
|
||||||
if (digit < 10) *p++ = digit + QSE_MT('0');
|
|
||||||
else *p++ = digit + xbasechar - 10;
|
|
||||||
value /= base;
|
value /= base;
|
||||||
}
|
}
|
||||||
while (value > 0);
|
while (value > 0);
|
||||||
@ -210,20 +210,20 @@ static int fmt_unsigned_to_wcs (
|
|||||||
qse_wchar_t tmp[(QSE_SIZEOF(qse_uintmax_t) * 8)];
|
qse_wchar_t tmp[(QSE_SIZEOF(qse_uintmax_t) * 8)];
|
||||||
int reslen, base, xsize, reqlen, pflen;
|
int reslen, base, xsize, reqlen, pflen;
|
||||||
qse_wchar_t* p, * bp, * be;
|
qse_wchar_t* p, * bp, * be;
|
||||||
qse_wchar_t xbasechar;
|
const qse_wchar_t* xbasestr;
|
||||||
|
|
||||||
base = base_and_flags & 0xFF;
|
base = base_and_flags & 0xFF;
|
||||||
if (base < 2 || base > 36) return -1;
|
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 */
|
/* store the resulting numeric string into 'tmp' first */
|
||||||
p = tmp;
|
p = tmp;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
int digit = value % base;
|
*p++ = xbasestr[value % base];
|
||||||
if (digit < 10) *p++ = digit + QSE_WT('0');
|
|
||||||
else *p++ = digit + xbasechar - 10;
|
|
||||||
value /= base;
|
value /= base;
|
||||||
}
|
}
|
||||||
while (value > 0);
|
while (value > 0);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: utf8.c 50 2009-02-10 05:48:05Z hyunghwan.chung $
|
* $Id$
|
||||||
*
|
*
|
||||||
Copyright 2006-2011 Chung, Hyung-Hwan.
|
Copyright 2006-2011 Chung, Hyung-Hwan.
|
||||||
This file is part of QSE.
|
This file is part of QSE.
|
||||||
|
@ -77,10 +77,7 @@ static QSE_INLINE int digit_to_num (qse_mchar_t c)
|
|||||||
|
|
||||||
static QSE_INLINE int xdigit_to_num (qse_mchar_t c)
|
static QSE_INLINE int xdigit_to_num (qse_mchar_t c)
|
||||||
{
|
{
|
||||||
if (c >= QSE_MT('0') && c <= QSE_MT('9')) return c - QSE_MT('0');
|
return QSE_MXDIGITTONUM (c);
|
||||||
if (c >= QSE_MT('A') && c <= QSE_MT('Z')) return c - QSE_MT('A') + 10;
|
|
||||||
if (c >= QSE_MT('a') && c <= QSE_MT('z')) return c - QSE_MT('a') + 10;
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -598,13 +598,6 @@ static void free_all_cids (qse_sed_t* sed)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static QSE_INLINE int xdigit_to_num (qse_cint_t c)
|
|
||||||
{
|
|
||||||
return (c >= QSE_T('0') && c <= QSE_T('9'))? (c - QSE_T('0')):
|
|
||||||
(c >= QSE_T('A') && c <= QSE_T('F'))? (c - QSE_T('A') + 10):
|
|
||||||
(c >= QSE_T('a') && c <= QSE_T('f'))? (c - QSE_T('a') + 10): -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int trans_escaped (qse_sed_t* sed, qse_cint_t c, qse_cint_t* ec, int* xamp)
|
static int trans_escaped (qse_sed_t* sed, qse_cint_t c, qse_cint_t* ec, int* xamp)
|
||||||
{
|
{
|
||||||
if (xamp) *xamp = 0;
|
if (xamp) *xamp = 0;
|
||||||
@ -643,13 +636,13 @@ Omitted for clash with regular expression \b.
|
|||||||
qse_cint_t peeped;
|
qse_cint_t peeped;
|
||||||
|
|
||||||
PEEPNXTSC (sed, peeped, -1);
|
PEEPNXTSC (sed, peeped, -1);
|
||||||
cc = xdigit_to_num (peeped);
|
cc = QSE_XDIGITTONUM (peeped);
|
||||||
if (cc <= -1) break;
|
if (cc <= -1) break;
|
||||||
NXTSC (sed, peeped, -1); /* consume the character peeped */
|
NXTSC (sed, peeped, -1); /* consume the character peeped */
|
||||||
c = cc;
|
c = cc;
|
||||||
|
|
||||||
PEEPNXTSC (sed, peeped, -1);
|
PEEPNXTSC (sed, peeped, -1);
|
||||||
cc = xdigit_to_num (peeped);
|
cc = QSE_XDIGITTONUM (peeped);
|
||||||
if (cc <= -1) break;
|
if (cc <= -1) break;
|
||||||
NXTSC (sed, peeped, -1); /* consume the character peeped */
|
NXTSC (sed, peeped, -1); /* consume the character peeped */
|
||||||
c = (c << 4) | cc;
|
c = (c << 4) | cc;
|
||||||
@ -667,7 +660,7 @@ Omitted for clash with regular expression \b.
|
|||||||
qse_cint_t peeped;
|
qse_cint_t peeped;
|
||||||
|
|
||||||
PEEPNXTSC (sed, peeped, -1);
|
PEEPNXTSC (sed, peeped, -1);
|
||||||
cc = xdigit_to_num (peeped);
|
cc = QSE_XDIGITTONUM (peeped);
|
||||||
if (cc <= -1) break;
|
if (cc <= -1) break;
|
||||||
NXTSC (sed, peeped, -1); /* consume the character peeped */
|
NXTSC (sed, peeped, -1); /* consume the character peeped */
|
||||||
c = cc;
|
c = cc;
|
||||||
@ -675,7 +668,7 @@ Omitted for clash with regular expression \b.
|
|||||||
for (i = 1; i < QSE_SIZEOF(qse_char_t) * 2; i++)
|
for (i = 1; i < QSE_SIZEOF(qse_char_t) * 2; i++)
|
||||||
{
|
{
|
||||||
PEEPNXTSC (sed, peeped, -1);
|
PEEPNXTSC (sed, peeped, -1);
|
||||||
cc = xdigit_to_num (peeped);
|
cc = QSE_XDIGITTONUM (peeped);
|
||||||
if (cc <= -1) break;
|
if (cc <= -1) break;
|
||||||
NXTSC (sed, peeped, -1); /* consume the character peeped */
|
NXTSC (sed, peeped, -1); /* consume the character peeped */
|
||||||
c = (c << 4) | cc;
|
c = (c << 4) | cc;
|
||||||
@ -2120,7 +2113,8 @@ static int write_first_line (
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define NTOC(n) (((n) >= 10)? (((n) - 10) + QSE_T('A')): (n) + QSE_T('0'))
|
#define NTOC(n) (QSE_T("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")[n])
|
||||||
|
|
||||||
static int write_num (qse_sed_t* sed, qse_ulong_t x, int base, int width)
|
static int write_num (qse_sed_t* sed, qse_ulong_t x, int base, int width)
|
||||||
{
|
{
|
||||||
qse_ulong_t last = x % base;
|
qse_ulong_t last = x % base;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include <qse/cmn/fmt.h>
|
#include <qse/cmn/fmt.h>
|
||||||
#include <qse/cmn/main.h>
|
#include <qse/cmn/main.h>
|
||||||
|
#include <qse/cmn/stdio.h>
|
||||||
|
|
||||||
static int test_main (int argc, qse_char_t* argv[], qse_char_t* envp[])
|
static int test_main (int argc, qse_char_t* argv[], qse_char_t* envp[])
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include <qse/cmn/fmt.h>
|
#include <qse/cmn/fmt.h>
|
||||||
#include <qse/cmn/main.h>
|
#include <qse/cmn/main.h>
|
||||||
|
#include <qse/cmn/stdio.h>
|
||||||
|
|
||||||
static int test_main (int argc, qse_char_t* argv[], qse_char_t* envp[])
|
static int test_main (int argc, qse_char_t* argv[], qse_char_t* envp[])
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user