Mercurial > hg > th-libs
changeset 353:2bf43a139542
Modularize some of the padding code better.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 25 Feb 2016 09:17:54 +0200 |
parents | 75b20d9bef64 |
children | e96015ed35d0 |
files | th_string.c |
diffstat | 1 files changed, 10 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/th_string.c Thu Feb 25 09:17:23 2016 +0200 +++ b/th_string.c Thu Feb 25 09:17:54 2016 +0200 @@ -136,20 +136,20 @@ static int th_printf_pad_pre(th_printf_ctx *ctx, th_printf_vputch vputch, - int f_width, const int f_flags) + int f_width, const int f_flags, const char ch) { if (f_width > 0 && (f_flags & TH_PF_LEFT) == 0) - return th_printf_vput_repch(ctx, vputch, f_width, (f_flags & TH_PF_ZERO) ? '0' : ' '); + return th_printf_vput_repch(ctx, vputch, f_width, ch); else return 0; } static int th_printf_pad_post(th_printf_ctx *ctx, th_printf_vputch vputch, - int f_width, const int f_flags) + int f_width, const int f_flags, const char ch) { if (f_width > 0 && (f_flags & TH_PF_LEFT)) - return th_printf_vput_repch(ctx, vputch, f_width, ' '); + return th_printf_vput_repch(ctx, vputch, f_width, ch); else return 0; } @@ -211,7 +211,7 @@ if (f_sign && (f_flags & TH_PF_ZERO) && (ret = vputch(ctx, f_sign)) == EOF) return ret; - if ((ret = th_printf_pad_pre(ctx, vputch, nwidth, f_flags)) == EOF) + if ((ret = th_printf_pad_pre(ctx, vputch, nwidth, f_flags, (f_flags & TH_PF_ZERO) ? '0' : ' ')) == EOF) return ret; if (f_altstr && (ret = th_printf_vput_pstr(ctx, vputch, f_altstr)) == EOF) @@ -236,7 +236,7 @@ } // Postfix padding? - return th_printf_pad_post(ctx, vputch, nwidth, f_flags); + return th_printf_pad_post(ctx, vputch, nwidth, f_flags, ' '); } @@ -258,7 +258,7 @@ nwidth = f_width - f_len; // Prefix padding? - if ((ret = th_printf_pad_pre(ctx, vputch, nwidth, f_flags)) == EOF) + if ((ret = th_printf_pad_pre(ctx, vputch, nwidth, f_flags, ' ')) == EOF) return ret; while (*str && f_len--) @@ -268,7 +268,7 @@ } // Postfix padding? - if ((ret = th_printf_pad_post(ctx, vputch, nwidth, f_flags)) == EOF) + if ((ret = th_printf_pad_post(ctx, vputch, nwidth, f_flags, ' ')) == EOF) return ret; return ret; @@ -387,11 +387,11 @@ return -104; case 'c': - if ((ret = th_printf_pad_pre(ctx, vputch, f_width - 1, f_flags)) == EOF) + if ((ret = th_printf_pad_pre(ctx, vputch, f_width - 1, f_flags, ' ')) == EOF) goto out; if ((ret = vputch(ctx, va_arg(ap, int))) == EOF) goto out; - if ((ret = th_printf_pad_post(ctx, vputch, f_width - 1, f_flags)) == EOF) + if ((ret = th_printf_pad_post(ctx, vputch, f_width - 1, f_flags, ' ')) == EOF) goto out; break;