1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

sprintf.c: use FILL

* sprintf.c (rb_str_format): use FILL and FILL_ macros instead of
  while loop.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58021 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2017-03-19 12:46:31 +00:00
parent d8bf178531
commit f30ed02b8a

View file

@ -74,6 +74,7 @@ sign_bits(int base, const char *p)
} while (0)
#define FILL(c, l) do { \
if ((l) <= 0) break;\
CHECK(l);\
FILL_(c, l);\
} while (0)
@ -758,20 +759,15 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
if ((flags&FWIDTH) && (width > slen)) {
width -= (int)slen;
if (!(flags&FMINUS)) {
CHECK(width);
while (width--) {
buf[blen++] = ' ';
}
FILL(' ', width);
width = 0;
}
CHECK(len);
memcpy(&buf[blen], RSTRING_PTR(str), len);
RB_GC_GUARD(str);
blen += len;
if (flags&FMINUS) {
CHECK(width);
while (width--) {
buf[blen++] = ' ';
}
FILL(' ', width);
}
rb_enc_associate(result, enc);
break;
@ -1009,10 +1005,8 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
width -= prec;
}
if (!(flags&FMINUS)) {
CHECK(width);
while (width-- > 0) {
buf[blen++] = ' ';
}
FILL(' ', width);
width = 0;
}
if (sc) PUSH(&sc, 1);
if (prefix) {
@ -1021,23 +1015,18 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
}
CHECK(prec - len);
if (dots) PUSH("..", 2);
if (!sign && valsign < 0) {
char c = sign_bits(base, p);
while (len < prec--) {
buf[blen++] = c;
if (prec > len) {
if (!sign && valsign < 0) {
char c = sign_bits(base, p);
FILL_(c, prec - len);
}
}
else if ((flags & (FMINUS|FPREC)) != FMINUS) {
while (len < prec--) {
buf[blen++] = '0';
else if ((flags & (FMINUS|FPREC)) != FMINUS) {
FILL_('0', prec - len);
}
}
PUSH(s, len);
RB_GC_GUARD(tmp);
CHECK(width);
while (width-- > 0) {
buf[blen++] = ' ';
}
FILL(' ', width);
}
break;