summaryrefslogtreecommitdiff
path: root/sprintf.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-12-10 06:23:44 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-12-10 06:23:44 +0000
commit60b2446bea0297c47f56deb308c29a5c1af64cc9 (patch)
tree2bcb6184518b5e93ec49a03b275258a817511abd /sprintf.c
parent4dcd8a95c7acf13a87283c11f72f7a8a7ad15019 (diff)
* sprintf.c (rb_f_sprintf): preceding ".." for negative numbers
still left; removed. * sprintf.c (rb_f_sprintf): should not prepend '0' if width > prec for example "%5.3d". * process.c (Init_process): add Process.exit and Process.abort * pack.c (utf8_to_uv): raise ArgumentError for malformed/redundant UTF-8 sequences. * process.c (last_status_set): add pid attribute to Process::Status. * pack.c (uv_to_utf8): limit maximum length of the encoded string to 6 bytes, even when the platform supports 8 bytes long integers. * pack.c (utf8_to_uv): do not decode sequences longer than 6 bytes. * object.c (copy_object): use "copy_object" method, not "become". git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3123 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sprintf.c')
-rw-r--r--sprintf.c62
1 files changed, 24 insertions, 38 deletions
diff --git a/sprintf.c b/sprintf.c
index f5e9542..1013d66 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -436,16 +436,14 @@ rb_f_sprintf(argc, argv)
if (s[0] == '-') {
s++;
sc = '-';
- width--;
}
else if (flags & FPLUS) {
sc = '+';
- width--;
}
else if (flags & FSPACE) {
sc = ' ';
- width--;
}
+ width--;
goto format_integer;
}
if (!RBIGNUM(val)->sign) {
@@ -492,11 +490,17 @@ rb_f_sprintf(argc, argv)
pp++;
}
}
- if (prec < len) prec = len;
- width -= prec;
- if (!(flags&(FZERO|FMINUS)) && v >= 0) {
+ if ((flags&(FZERO|FPREC)) == FZERO) {
+ prec = width;
+ width = 0;
+ }
+ else {
+ if (prec < len) prec = len;
+ width -= prec;
+ }
+ if (!(flags&FMINUS)) {
CHECK(width);
- while (width-->0) {
+ while (width-- > 0) {
buf[blen++] = ' ';
}
}
@@ -504,36 +508,9 @@ rb_f_sprintf(argc, argv)
if (prefix) {
int plen = strlen(prefix);
PUSH(prefix, plen);
- if (pos) pos += plen;
- }
- if (!(flags & FMINUS)) {
- char c = ' ';
-
- if (v < 0) {
- c = '.';
- if ((flags & FPREC) && prec > len) {
- pos = blen;
- }
- else {
- pos = blen + 2;
- }
- }
- else if (flags & FZERO) c = '0';
- CHECK(width);
- while (width-->0) {
- buf[blen++] = c;
- }
}
CHECK(prec - len);
- while (len < prec--) {
- buf[blen++] = v < 0 ? '.' : '0';
- }
- PUSH(s, len);
- CHECK(width);
- while (width-->0) {
- buf[blen++] = ' ';
- }
- if (pos >= 0 && buf[pos] == '.') {
+ if (v < 0) {
char c = '.';
switch (base) {
@@ -546,11 +523,20 @@ rb_f_sprintf(argc, argv)
case 2:
c = '1'; break;
}
- s = &buf[pos];
- while (*s && *s == '.') {
- *s++ = c;
+ while (len < prec--) {
+ buf[blen++] = c;
}
}
+ else {
+ while (len < prec--) {
+ buf[blen++] = '0';
+ }
+ }
+ PUSH(s, len);
+ CHECK(width);
+ while (width-- > 0) {
+ buf[blen++] = ' ';
+ }
}
break;