summaryrefslogtreecommitdiff
path: root/ext/date/date_parse.c
diff options
context:
space:
mode:
authortadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-08 09:41:38 +0000
committertadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-08 09:41:38 +0000
commit1348dd26b003665a8dc219ea8f5799834b40c941 (patch)
tree27179cfd769a582eea1ab735f9ed5d905932fbad /ext/date/date_parse.c
parent1816a4a6a994f6437b6b741fa3a84bfb4c827c04 (diff)
* 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
Diffstat (limited to 'ext/date/date_parse.c')
-rw-r--r--ext/date/date_parse.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/ext/date/date_parse.c b/ext/date/date_parse.c
index 76642c4..74730c6 100644
--- a/ext/date/date_parse.c
+++ b/ext/date/date_parse.c
@@ -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();