From 67f53505ce1313616748cc55eba373ec4b05622a Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sat, 19 Aug 2006 22:15:34 +0000 Subject: [PATCH] Added request am41635 and fixed a bug with passing (1<<31) --- amxmodx/format.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/amxmodx/format.cpp b/amxmodx/format.cpp index ad049302..ac1cccc6 100644 --- a/amxmodx/format.cpp +++ b/amxmodx/format.cpp @@ -224,6 +224,50 @@ void AddFloat(U **buf_p, size_t &maxlen, double fval, int width, int prec) } } +template +void AddUInt(U **buf_p, size_t &maxlen, unsigned int val, int width, int flags) +{ + U text[32]; + int digits; + U *buf; + + digits = 0; + do { + text[digits++] = '0' + val % 10; + val /= 10; + } while (val); + + buf = *buf_p; + + if( !(flags & LADJUST) ) + { + while (digits < width && maxlen) + { + *buf++ = (flags & ZEROPAD) ? '0' : ' '; + width--; + maxlen--; + } + } + + while (digits-- && maxlen) + { + *buf++ = text[digits]; + width--; + maxlen--; + } + + if (flags & LADJUST) + { + while (width-- && maxlen) + { + *buf++ = (flags & ZEROPAD) ? '0' : ' '; + maxlen--; + } + } + + *buf_p = buf; +} + template void AddInt(U **buf_p, size_t &maxlen, int val, int width, int flags) { @@ -231,15 +275,22 @@ void AddInt(U **buf_p, size_t &maxlen, int val, int width, int flags) int digits; int signedVal; U *buf; + unsigned int unsignedVal; digits = 0; signedVal = val; if (val < 0) - val = -val; + { + /* we want the unsigned version */ + val--; + unsignedVal = ~val; + } else { + unsignedVal = val; + } do { - text[digits++] = '0' + val % 10; - val /= 10; - } while (val); + text[digits++] = '0' + unsignedVal % 10; + unsignedVal /= 10; + } while (unsignedVal); if (signedVal < 0) text[digits++] = '-'; @@ -360,6 +411,11 @@ reswitch: AddInt(&buf_p, llen, *get_amxaddr(amx, params[arg]), width, flags); arg++; break; + case 'u': + CHECK_ARGS(0); + AddUInt(&buf_p, llen, static_cast(*get_amxaddr(amx, params[arg])), width, flags); + arg++; + break; case 'f': CHECK_ARGS(0); AddFloat(&buf_p, llen, amx_ctof(*get_amxaddr(amx, params[arg])), width, prec);