[前][次][番号順一覧][スレッド一覧]

ruby-changes:44241

From: nobu <ko1@a...>
Date: Sat, 1 Oct 2016 18:00:10 +0900 (JST)
Subject: [ruby-changes:44241] nobu:r56314 (trunk): date_parse.c: str_end_with

nobu	2016-10-01 18:00:05 +0900 (Sat, 01 Oct 2016)

  New Revision: 56314

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56314

  Log:
    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.

  Modified files:
    trunk/ext/date/date_parse.c
Index: ext/date/date_parse.c
===================================================================
--- ext/date/date_parse.c	(revision 56313)
+++ ext/date/date_parse.c	(revision 56314)
@@ -342,6 +342,13 @@ subx(VALUE str, VALUE rep, VALUE pat, VA https://github.com/ruby/ruby/blob/trunk/ext/date/date_parse.c#L342
 
 #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) https://github.com/ruby/ruby/blob/trunk/ext/date/date_parse.c#L391
 	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;
 	}

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]