diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | stream.c | 8 |
2 files changed, 15 insertions, 1 deletions
@@ -1,5 +1,13 @@ 2011-12-22 Kaz Kylheku <kaz@kylheku.com> + * stream.c (vformat): If width is specified for ~s or ~a, and + the object is not a string or number, then print it to a string + and treat it as a string, adjusting it within the field. + Also, do not simply abort on an unknown format directive + but throw a proper exception. + +2011-12-22 Kaz Kylheku <kaz@kylheku.com> + * stream.c (vformat): Left-adjusted field is now specified using < rather than '-'. The +, space and leading 0 are specified on the precision, not the width. @@ -1020,6 +1020,11 @@ val vformat(val stream, val fmtstr, va_list vl) pnum = (char *) chk_malloc(nchars + 1); mp_toradix(mp(obj), (unsigned char *) pnum, 10); goto output_num; + } else if (width != 0) { + val str = format(nil, ch == 'a' ? lit("~a") : lit("~s"), obj, nao); + if (!vformat_str(stream, str, width, left, precision)) + return nil; + continue; } if (ch == 'a') obj_pprint(obj, stream); @@ -1032,7 +1037,8 @@ val vformat(val stream, val fmtstr, va_list vl) sprintf(num_buf, num_fmt->hex, value); goto output_num; default: - abort(); + uw_throwf(error_s, lit("unknown format directive character ~s\n"), + chr(ch), nao); output_num: { val res = vformat_num(stream, pnum, width, left, |