aboutsummaryrefslogtreecommitdiffstats
path: root/ext
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-10-01 09:00:05 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-10-01 09:00:05 +0000
commit7b28db580f849220324dc614381fee27c3a8c35d (patch)
tree7e892ae120c7b2ad122fd0e850529b77e7e6721b /ext
parent0ba9ccd77e8ca38c2abc659a14120eb35e9d7075 (diff)
downloadruby-7b28db580f849220324dc614381fee27c3a8c35d.tar.gz
date_parse.c: str_end_with
* ext/date/date_parse.c (str_end_with): extract to tell if a string ends with the other string. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56314 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/date/date_parse.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/ext/date/date_parse.c b/ext/date/date_parse.c
index 08deaa049e..97923d7623 100644
--- a/ext/date/date_parse.c
+++ b/ext/date/date_parse.c
@@ -342,6 +342,13 @@ subx(VALUE str, VALUE rep, VALUE pat, VALUE hash, int (*cb)(VALUE, VALUE))
#include "zonetab.h"
+static int
+str_end_with(const char *s, long l, const char *w)
+{
+ int n = (int)strlen(w);
+ return (l >= n && strncmp(s - n, w, n) == 0);
+}
+
VALUE
date_zone_to_diff(VALUE str)
{
@@ -384,14 +391,14 @@ date_zone_to_diff(VALUE str)
static const char DST2[] = " dst";
int dst = 0;
- if (l >= (int)sizeof(STD) - 1 && strcmp(d - (sizeof(STD) - 1), STD) == 0) {
+ if (str_end_with(d, l, STD)) {
l -= sizeof(STD) - 1;
}
- else if (l >= (int)sizeof(DST1) - 1 && strcmp(d - (sizeof(DST1) - 1), DST1) == 0) {
+ else if (str_end_with(d, l, DST1)) {
l -= sizeof(DST1) - 1;
dst = 1;
}
- else if (l >= (int)sizeof(DST2) - 1 && strcmp(d - (sizeof(DST2) - 1), DST2) == 0) {
+ else if (str_end_with(d, l, DST2)) {
l -= sizeof(DST2) - 1;
dst = 1;
}