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

trivial changes

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35647 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
tadf 2012-05-14 21:39:25 +00:00
parent 3e972bbaba
commit b6de661b54
2 changed files with 25 additions and 21 deletions

View file

@ -1,6 +1,6 @@
/* /*
date_strftime.c: based on a public-domain implementation of ANSI C date_strftime.c: based on a public-domain implementation of ANSI C
library routine of strftime, which is originally written by Arnold library routine strftime, which is originally written by Arnold
Robbins. Robbins.
*/ */
@ -84,7 +84,8 @@ date_strftime_with_tmx(char *s, size_t maxsize, const char *format,
if (precision <= 0) precision = (def_prec); \ if (precision <= 0) precision = (def_prec); \
if (flags & BIT_OF(LEFT)) precision = 1; \ if (flags & BIT_OF(LEFT)) precision = 1; \
l = snprintf(s, endp - s, \ l = snprintf(s, endp - s, \
((padding == '0' || (!padding && (def_pad) == '0')) ? "%0*"fmt : "%*"fmt), \ ((padding == '0' || (!padding && (def_pad) == '0')) ? \
"%0*"fmt : "%*"fmt), \
precision, (val)); \ precision, (val)); \
if (l < 0) goto err; \ if (l < 0) goto err; \
s += l; \ s += l; \
@ -121,8 +122,8 @@ date_strftime_with_tmx(char *s, size_t maxsize, const char *format,
result = rb_str_format(2, args, rb_str_new2("%0*"fmt)); \ result = rb_str_format(2, args, rb_str_new2("%0*"fmt)); \
else \ else \
result = rb_str_format(2, args, rb_str_new2("%*"fmt)); \ result = rb_str_format(2, args, rb_str_new2("%*"fmt)); \
l = strlcpy(s, StringValueCStr(result), endp-s); \ l = strlcpy(s, StringValueCStr(result), endp - s); \
if ((size_t)(endp-s) <= l) \ if ((size_t)(endp - s) <= l) \
goto err; \ goto err; \
s += l; \ s += l; \
} \ } \
@ -176,14 +177,14 @@ date_strftime_with_tmx(char *s, size_t maxsize, const char *format,
i = 1, tp = "?"; i = 1, tp = "?";
else { else {
if (*format == 'B') if (*format == 'B')
i = strlen(tp = months_l[mon-1]); i = strlen(tp = months_l[mon - 1]);
else else
i = 3, tp = months_l[mon-1]; i = 3, tp = months_l[mon - 1];
} }
} }
break; break;
case 'C': case 'C': /* century (year/100) */
FMTV('0', 2, "d", div(tmx_year, INT2FIX(100))); FMTV('0', 2, "d", div(tmx_year, INT2FIX(100)));
continue; continue;
@ -272,7 +273,8 @@ date_strftime_with_tmx(char *s, size_t maxsize, const char *format,
subsec = div(subsec, INT2FIX(1)); subsec = div(subsec, INT2FIX(1));
if (FIXNUM_P(subsec)) { if (FIXNUM_P(subsec)) {
(void)snprintf(s, endp - s, "%0*ld", precision, FIX2LONG(subsec)); (void)snprintf(s, endp - s, "%0*ld",
precision, FIX2LONG(subsec));
s += precision; s += precision;
} }
else { else {
@ -280,7 +282,7 @@ date_strftime_with_tmx(char *s, size_t maxsize, const char *format,
args[0] = INT2FIX(precision); args[0] = INT2FIX(precision);
args[1] = subsec; args[1] = subsec;
result = rb_str_format(2, args, rb_str_new2("%0*d")); result = rb_str_format(2, args, rb_str_new2("%0*d"));
(void)strlcpy(s, StringValueCStr(result), endp-s); (void)strlcpy(s, StringValueCStr(result), endp - s);
s += precision; s += precision;
} }
} }
@ -321,7 +323,7 @@ date_strftime_with_tmx(char *s, size_t maxsize, const char *format,
i = 2; i = 2;
break; break;
case 'Q': case 'Q': /* microseconds since Unix epoch */
FMTV('0', 1, "d", tmx_msecs); FMTV('0', 1, "d", tmx_msecs);
continue; continue;
@ -338,7 +340,7 @@ date_strftime_with_tmx(char *s, size_t maxsize, const char *format,
FMT('0', 2, "d", v); FMT('0', 2, "d", v);
continue; continue;
case 's': case 's': /* seconds since Unix epoch */
FMTV('0', 1, "d", tmx_secs); FMTV('0', 1, "d", tmx_secs);
continue; continue;
@ -352,8 +354,7 @@ date_strftime_with_tmx(char *s, size_t maxsize, const char *format,
FMT('0', 2, "d", v); FMT('0', 2, "d", v);
continue; continue;
case 'u': case 'u': /* weekday, Monday == 1, 1 - 7 */
/* ISO 8601: Weekday as a decimal number [1 (Monday) - 7] */
v = range(1, tmx_cwday, 7); v = range(1, tmx_cwday, 7);
FMT('0', 1, "d", v); FMT('0', 1, "d", v);
continue; continue;
@ -413,7 +414,7 @@ date_strftime_with_tmx(char *s, size_t maxsize, const char *format,
} }
break; break;
case 'z': /* time zone offset east of UTC e.g. -0600 */ case 'z': /* offset from UTC */
{ {
long off, aoff; long off, aoff;
int hl, hw; int hl, hw;
@ -434,32 +435,35 @@ date_strftime_with_tmx(char *s, size_t maxsize, const char *format,
switch (colons) { switch (colons) {
case 0: /* %z -> +hhmm */ case 0: /* %z -> +hhmm */
precision = precision <= (3 + hw) ? hw : precision-3; precision = precision <= (3 + hw) ? hw : precision - 3;
NEEDS(precision + 3); NEEDS(precision + 3);
break; break;
case 1: /* %:z -> +hh:mm */ case 1: /* %:z -> +hh:mm */
precision = precision <= (4 + hw) ? hw : precision-4; precision = precision <= (4 + hw) ? hw : precision - 4;
NEEDS(precision + 4); NEEDS(precision + 4);
break; break;
case 2: /* %::z -> +hh:mm:ss */ case 2: /* %::z -> +hh:mm:ss */
precision = precision <= (7 + hw) ? hw : precision-7; precision = precision <= (7 + hw) ? hw : precision - 7;
NEEDS(precision + 7); NEEDS(precision + 7);
break; break;
case 3: /* %:::z -> +hh[:mm[:ss]] */ case 3: /* %:::z -> +hh[:mm[:ss]] */
{ {
if (aoff % 3600 == 0) { if (aoff % 3600 == 0) {
precision = precision <= (1 + hw) ? hw : precision-1; precision = precision <= (1 + hw) ?
hw : precision - 1;
NEEDS(precision + 3); NEEDS(precision + 3);
} }
else if (aoff % 60 == 0) { else if (aoff % 60 == 0) {
precision = precision <= (4 + hw) ? hw : precision-4; precision = precision <= (4 + hw) ?
hw : precision - 4;
NEEDS(precision + 4); NEEDS(precision + 4);
} }
else { else {
precision = precision <= (7 + hw) ? hw : precision-7; precision = precision <= (7 + hw) ?
hw : precision - 7;
NEEDS(precision + 7); NEEDS(precision + 7);
} }
} }