medfall

A super great game engine
Log | Files | Refs

commit 0d493b8e619fa7055d2562317d156618257b1e9d
parent e8974017795617a7d1c000d851b7605a888dcfb8
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sun Aug 27 23:59:26 +0100

More ggformat updates

Diffstat:
ggformat.cc | 26++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/ggformat.cc b/ggformat.cc @@ -80,7 +80,7 @@ void format( FormatBuffer * fb, bool x, const FormatOpts & opts ) { } template< typename T > -static void int_helper( FormatBuffer * fb, const char * fmt_decimal, const T & x, const FormatOpts & opts ) { +static void int_helper( FormatBuffer * fb, const char * fmt_length, const char * fmt_decimal, const T & x, const FormatOpts & opts ) { ShortString fmt; fmt += "%"; if( opts.plus_sign ) fmt += "+"; @@ -88,9 +88,11 @@ static void int_helper( FormatBuffer * fb, const char * fmt_decimal, const T & x if( opts.zero_pad ) fmt += "0"; if( opts.width != -1 ) fmt += opts.width; if( opts.number_format == FormatOpts::DECIMAL ) { + fmt += fmt_length; fmt += fmt_decimal; } else if( opts.number_format == FormatOpts::HEX ) { + fmt += fmt_length; fmt += "x"; } else if( opts.number_format == FormatOpts::BINARY ) { @@ -110,19 +112,19 @@ static void int_helper( FormatBuffer * fb, const char * fmt_decimal, const T & x format_helper( fb, fmt, x ); } -#define INT_OVERLOADS( T ) \ +#define INT_OVERLOADS( T, fmt_length ) \ void format( FormatBuffer * fb, signed T x, const FormatOpts & opts ) { \ - int_helper( fb, "d", x, opts ); \ + int_helper( fb, fmt_length, "d", x, opts ); \ } \ void format( FormatBuffer * fb, unsigned T x, const FormatOpts & opts ) { \ - int_helper( fb, "u", x, opts ); \ + int_helper( fb, fmt_length, "u", x, opts ); \ } -INT_OVERLOADS( char ) -INT_OVERLOADS( short ) -INT_OVERLOADS( int ) -INT_OVERLOADS( long ) -INT_OVERLOADS( long long ) +INT_OVERLOADS( char, "hh" ) +INT_OVERLOADS( short, "h" ) +INT_OVERLOADS( int, "" ) +INT_OVERLOADS( long, "l" ) +INT_OVERLOADS( long long, "ll" ) #undef INT_OVERLOADS @@ -159,8 +161,6 @@ static const char * parse_format_precision( const char * p, const char * one_pas } static const char * parse_format_number_format( const char * p, const char * one_past_end, FormatOpts::NumberFormat * number_format ) { - *number_format = FormatOpts::DECIMAL; - bool hex = false; const char * after_hex = parse_format_bool( p, one_past_end, 'x', &hex ); @@ -250,7 +250,9 @@ void ggformat_literals( FormatBuffer * fb, const char * literals, size_t len ) { copied_len++; } fb->len += copied_len; - fb->buf[ fb->len < fb->capacity - 1 ? fb->len : fb->capacity - 1 ] = '\0'; + if( fb->capacity > 0 ) { + fb->buf[ fb->len < fb->capacity - 1 ? fb->len : fb->capacity - 1 ] = '\0'; + } } void ggformat_impl( FormatBuffer * fb, const char * fmt ) {