medfall

A super great game engine
Log | Files | Refs

commit d48a75a2452429f1e2c1f5bd3019c603a707ff97
parent fe92c9f6e9b0b3aa94a11e53547f96a54f3b6cf9
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Tue May 16 03:26:05 +0300

ggformat + modifier

Diffstat:
ggformat.cc | 3+++
ggformat.h | 3++-
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/ggformat.cc b/ggformat.cc @@ -48,6 +48,7 @@ void format( FormatBuffer * fb, double x, const FormatOpts & opts ) { ShortString fmt; fmt += "%"; int precision = opts.precision != -1 ? opts.precision : 5; + if( opts.plus_sign ) fmt += "+"; if( opts.left_align ) fmt += "-"; if( opts.width != -1 ) fmt += opts.width + 1 + precision; fmt += "."; @@ -82,6 +83,7 @@ template< typename T > static void int_helper( FormatBuffer * fb, const char * fmt_decimal, const T & x, const FormatOpts & opts ) { ShortString fmt; fmt += "%"; + if( opts.plus_sign ) fmt += "+"; if( opts.left_align ) fmt += "-"; if( opts.zero_pad ) fmt += "0"; if( opts.width != -1 ) fmt += opts.width; @@ -180,6 +182,7 @@ FormatOpts parse_formatopts( const char * fmt, size_t len ) { const char * start = fmt; const char * one_past_end = start + len; + start = parse_format_bool( start, one_past_end, '+', &opts.plus_sign ); start = parse_format_bool( start, one_past_end, '-', &opts.left_align ); start = parse_format_bool( start, one_past_end, '0', &opts.zero_pad ); start = parse_format_int( start, one_past_end, &opts.width ); diff --git a/ggformat.h b/ggformat.h @@ -28,8 +28,9 @@ struct FormatOpts { int width = -1; int precision = -1; - bool zero_pad = false; + bool plus_sign = false; bool left_align = false; + bool zero_pad = false; NumberFormat number_format = DECIMAL; };