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

* ext/date/date_{parse,strptime}.c: introduced some macros.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31480 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
tadf 2011-05-08 09:41:38 +00:00
parent 1816a4a6a9
commit 1348dd26b0
3 changed files with 17 additions and 10 deletions

View file

@ -1,3 +1,7 @@
Sun May 8 18:40:03 2011 Tadayoshi Funaba <tadf@dotrb.org>
* ext/date/date_{parse,strptime}.c: introduced some macros.
Sun May 8 17:17:13 2011 Tadayoshi Funaba <tadf@dotrb.org>
* test/date/*.rb: use skip /w messages.

View file

@ -53,6 +53,9 @@ static const char *abbr_months[] = {
"jul", "aug", "sep", "oct", "nov", "dec"
};
#define issign(c) ((c) == '-' || (c) == '+')
#define asp_string() rb_str_new(" ", 1)
static void
s3e(VALUE hash, VALUE y, VALUE m, VALUE d, int bc)
{
@ -87,12 +90,11 @@ s3e(VALUE hash, VALUE y, VALUE m, VALUE d, int bc)
size_t l;
s = RSTRING_PTR(y);
while (*s != '-' && *s != '+' && !isdigit(*s))
while (!issign(*s) && !isdigit(*s))
s++;
bp = s;
if (*s == '-' || *s == '+') {
if (issign(*s))
s++;
}
l = strspn(s, "0123456789");
ep = s + l;
if (*ep) {
@ -137,10 +139,10 @@ s3e(VALUE hash, VALUE y, VALUE m, VALUE d, int bc)
VALUE iy;
s = RSTRING_PTR(y);
while (*s != '-' && *s != '+' && !isdigit(*s))
while (!issign(*s) && !isdigit(*s))
s++;
bp = s;
if (*s == '-' || *s == '+') {
if (issign(*s)) {
s++;
sign = 1;
}
@ -253,8 +255,7 @@ subs(VALUE str, VALUE pat, VALUE hash, int (*cb)(VALUE, VALUE))
be = f_begin(m, INT2FIX(0));
en = f_end(m, INT2FIX(0));
f_aset2(str, be, LONG2NUM(NUM2LONG(en) - NUM2LONG(be)),
rb_str_new(" ", 1));
f_aset2(str, be, LONG2NUM(NUM2LONG(en) - NUM2LONG(be)), asp_string());
(*cb)(m, hash);
}
@ -1243,7 +1244,7 @@ date__parse(VALUE str, VALUE comp)
str = rb_str_dup(str);
REGCOMP_0(pat);
f_gsub_bang(str, pat, rb_str_new(" ", 1));
f_gsub_bang(str, pat, asp_string());
}
hash = rb_hash_new();

View file

@ -52,6 +52,8 @@ static const char *extz_pats[] = {
#define f_aref(o,i) rb_funcall(o, rb_intern("[]"), 1, i)
#define f_end(o,i) rb_funcall(o, rb_intern("end"), 1, i)
#define issign(c) ((c) == '-' || (c) == '+')
static int
num_pattern_p(const char *s)
{
@ -344,7 +346,7 @@ date__strptime_internal(const char *str, size_t slen,
int sign = 1;
size_t osi;
if (str[si] == '-' || str[si] == '+') {
if (issign(str[si])) {
if (str[si] == '-')
sign = -1;
si++;
@ -526,7 +528,7 @@ date__strptime_internal(const char *str, size_t slen,
VALUE n;
int sign = 1;
if (str[si] == '-' || str[si] == '+') {
if (issign(str[si])) {
if (str[si] == '-')
sign = -1;
si++;