summaryrefslogtreecommitdiff
path: root/ext
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
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')
-rw-r--r--ext/date/date_parse.c17
-rw-r--r--ext/date/date_strptime.c6
2 files changed, 13 insertions, 10 deletions
diff --git a/ext/date/date_parse.c b/ext/date/date_parse.c
index 76642c4be5..74730c6c80 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();
diff --git a/ext/date/date_strptime.c b/ext/date/date_strptime.c
index fdc75660ab..897f5f8807 100644
--- a/ext/date/date_strptime.c
+++ b/ext/date/date_strptime.c
@@ -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++;