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

ruby-changes:6435

From: naruse <ko1@a...>
Date: Tue, 8 Jul 2008 08:01:18 +0900 (JST)
Subject: [ruby-changes:6435] Ruby:r17951 (trunk): * dir.c (Next): use rb_enc_precise_mbclen.

naruse	2008-07-08 08:00:58 +0900 (Tue, 08 Jul 2008)

  New Revision: 17951

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=17951

  Log:
    * dir.c (Next): use rb_enc_precise_mbclen.

  Modified files:
    trunk/ChangeLog
    trunk/dir.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 17950)
+++ ChangeLog	(revision 17951)
@@ -1,3 +1,7 @@
+Tue Jul  8 07:59:40 2008  NARUSE, Yui  <naruse@r...>
+
+	* dir.c (Next): use rb_enc_precise_mbclen.
+
 Tue Jul  8 02:27:23 2008  NARUSE, Yui  <naruse@r...>
 
 	* dir.c: preserve encoding of strings in glob and fnmatch.
Index: dir.c
===================================================================
--- dir.c	(revision 17950)
+++ dir.c	(revision 17951)
@@ -80,8 +80,8 @@
 #define FNM_NOMATCH	1
 #define FNM_ERROR	2
 
-# define Next(p, enc) (rb_enc_right_char_head(p, p+1, enc))
-# define Inc(p, enc) ((p) = Next(p, enc))
+# define Next(p, e, enc) (p + rb_enc_precise_mbclen(p, e, enc))
+# define Inc(p, e, enc) ((p) = Next(p, e, enc))
 
 static int
 char_casecmp(const char *p1, const char *p2, rb_encoding *enc, const int nocase)
@@ -110,6 +110,7 @@
     int flags,
     rb_encoding *enc)
 {
+    const char *pend = p + strlen(p);
     const int nocase = flags & FNM_CASEFOLD;
     const int escape = !(flags & FNM_NOESCAPE);
 
@@ -126,14 +127,14 @@
 	    t1++;
 	if (!*t1)
 	    return NULL;
-	p = Next(t1, enc);
+	p = Next(t1, pend, enc);
 	if (p[0] == '-' && p[1] != ']') {
 	    const char *t2 = p + 1;
 	    if (escape && *t2 == '\\')
 		t2++;
 	    if (!*t2)
 		return NULL;
-	    p = Next(t2, enc);
+	    p = Next(t2, pend, enc);
 	    if (!ok && char_casecmp(t1, s, enc, nocase) <= 0 && char_casecmp(s, t2, enc, nocase) <= 0)
 		ok = 1;
 	}
@@ -170,7 +171,9 @@
     const char *stmp = 0;
 
     const char *p = *pcur;
+    const char *pend = p + strlen(p);
     const char *s = *scur;
+    const char *send = s + strlen(s);
 
     if (period && *s == '.' && *UNESCAPE(p) != '.') /* leading period */
 	RETURN(FNM_NOMATCH);
@@ -193,7 +196,7 @@
 	    if (ISEND(s))
 		RETURN(FNM_NOMATCH);
 	    p++;
-	    Inc(s, enc);
+	    Inc(s, send, enc);
 	    continue;
 
 	  case '[': {
@@ -202,7 +205,7 @@
 		RETURN(FNM_NOMATCH);
 	    if ((t = bracket(p + 1, s, flags, enc)) != 0) {
 		p = t;
-		Inc(s, enc);
+		Inc(s, send, enc);
 		continue;
 	    }
 	    goto failed;
@@ -217,14 +220,14 @@
 	    goto failed;
 	if (char_casecmp(p, s, enc, nocase) != 0)
 	    goto failed;
-	Inc(p, enc);
-	Inc(s, enc);
+	Inc(p, pend, enc);
+	Inc(s, send, enc);
 	continue;
 
       failed: /* try next '*' position */
 	if (ptmp && stmp) {
 	    p = ptmp;
-	    Inc(stmp, enc); /* !ISEND(*stmp) */
+	    Inc(stmp, send, enc); /* !ISEND(*stmp) */
 	    s = stmp;
 	    continue;
 	}
@@ -240,6 +243,7 @@
 {
     const char *p = RSTRING_PTR(pattern); /* pattern */
     const char *s = RSTRING_PTR(string); /* string */
+    const char *send = RSTRING_END(string);
     const int period = !(flags & FNM_DOTMATCH);
     const int pathname = flags & FNM_PATHNAME;
     rb_encoding *enc = rb_enc_get(pattern);
@@ -255,7 +259,7 @@
 		stmp = s;
 	    }
 	    if (fnmatch_helper(&p, &s, flags, enc) == 0) {
-		while (*s && *s != '/') Inc(s, enc);
+		while (*s && *s != '/') Inc(s, send, enc);
 		if (*p && *s) {
 		    p++;
 		    s++;
@@ -266,7 +270,7 @@
 	    }
 	    /* failed : try next recursion */
 	    if (ptmp && stmp && !(period && *stmp == '.')) {
-		while (*stmp && *stmp != '/') Inc(stmp, enc);
+		while (*stmp && *stmp != '/') Inc(stmp, send, enc);
 		if (*stmp) {
 		    p = ptmp;
 		    stmp++;
@@ -979,6 +983,7 @@
     const int nocase = flags & FNM_CASEFOLD;
 
     register const char *p = s;
+    register const char *pend = p + strlen(p);
     register char c;
 
     while ((c = *p++) != 0) {
@@ -998,7 +1003,7 @@
 		return 1;
 	}
 
-	p = Next(p-1, enc);
+	p = Next(p-1, pend, enc);
     }
 
     return 0;
@@ -1011,6 +1016,7 @@
     const int escape = !(flags & FNM_NOESCAPE);
 
     register const char *p = s;
+    register const char *pend = p + strlen(p);
     register char c;
     int open = 0;
 
@@ -1034,7 +1040,7 @@
 	    continue;
 	}
 
-	p = Next(p-1, enc);
+	p = Next(p-1, pend, enc);
     }
 
     return (char *)p-1;
@@ -1044,6 +1050,7 @@
 static void
 remove_backslashes(char *p, rb_encoding *enc)
 {
+    register const char *pend = p + strlen(p);
     char *t = p;
     char *s = p;
 
@@ -1055,7 +1062,7 @@
 	    s = ++p;
 	    if (!*p) break;
 	}
-	Inc(p, enc);
+	Inc(p, pend, enc);
     }
 
     while (*p++);
@@ -1456,6 +1463,7 @@
 {
     const int escape = !(flags & FNM_NOESCAPE);
     const char *p = str;
+    const char *pend = p + strlen(p);
     const char *s = p;
     const char *lbrace = 0, *rbrace = 0;
     int nest = 0, status = 0;
@@ -1471,7 +1479,7 @@
 	if (*p == '\\' && escape) {
 	    if (!*++p) break;
 	}
-	Inc(p, enc);
+	Inc(p, pend, enc);
     }
 
     if (lbrace && rbrace) {
@@ -1491,7 +1499,7 @@
 		if (*p == '\\' && escape) {
 		    if (++p == rbrace) break;
 		}
-		Inc(p, enc);
+		Inc(p, pend, enc);
 	    }
 	    memcpy(buf+shift, t, p-t);
 	    strcpy(buf+shift+(p-t), rbrace+1);

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

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