From 051fa970e0cd973d6b51cfb0d0ff941db3bb9810 Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Wed, 28 Feb 2018 15:39:58 +0000 Subject: [PATCH] enhanced moo_inttostr() to access a negative integer to produce the alphabetic digits in the lower case --- moo/lib/bigint.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/moo/lib/bigint.c b/moo/lib/bigint.c index 5349d8d..4cc7850 100644 --- a/moo/lib/bigint.c +++ b/moo/lib/bigint.c @@ -70,7 +70,8 @@ #define IS_SIGN_DIFF(x,y) (((x) ^ (y)) < 0) /* digit character array */ -static char _digitc[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +static char _digitc_upper[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +static char _digitc_lower[] = "0123456789abcdefghijklmnopqrstuvwxyz"; /* exponent table */ static moo_uint8_t _exp_tab[] = @@ -3813,6 +3814,18 @@ oops_einval: static moo_oow_t oow_to_text (moo_t* moo, moo_oow_t w, int radix, moo_ooch_t* buf) { moo_ooch_t* ptr; + const char* _digitc; + + if (radix < 0) + { + _digitc = _digitc_lower; + radix = -radix; + } + else + { + _digitc = _digitc_upper; + } + MOO_ASSERT (moo, radix >= 2 && radix <= 36); ptr = buf; @@ -4007,6 +4020,17 @@ moo_oop_t moo_inttostr (moo_t* moo, moo_oop_t num, int radix) moo_ooch_t* xbuf = MOO_NULL; moo_oow_t xlen = 0, seglen, reqcapa; + const char* _digitc; + + if (radix < 0) + { + _digitc = _digitc_lower; + radix = -radix; + } + else + { + _digitc = _digitc_upper; + } MOO_ASSERT (moo, radix >= 2 && radix <= 36); if (!moo_isint(moo,num)) goto oops_einval;