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

ruby-changes:3782

From: ko1@a...
Date: Sun, 27 Jan 2008 19:09:13 +0900 (JST)
Subject: [ruby-changes:3782] akr - Ruby:r15271 (trunk): * string.c (rb_str_succ): warning suppressed.

akr	2008-01-27 19:08:58 +0900 (Sun, 27 Jan 2008)

  New Revision: 15271

  Modified files:
    trunk/ChangeLog
    trunk/string.c

  Log:
    * string.c (rb_str_succ): warning suppressed.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/string.c?r1=15271&r2=15270&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=15271&r2=15270&diff_format=u

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 15270)
+++ ChangeLog	(revision 15271)
@@ -1,3 +1,7 @@
+Sun Jan 27 19:07:33 2008  Tanaka Akira  <akr@f...>
+
+	* string.c (rb_str_succ): warning suppressed.
+
 Sun Jan 27 18:18:13 2008  NARUSE, Yui  <naruse@r...>
 
 	* common.mk (help): show major targets.
@@ -16,7 +20,7 @@
 
 Sun Jan 27 16:27:22 2008  NARUSE, Yui  <naruse@r...>
 
-	* ext/nkf/nkt-utf8: update nkf.
+	* ext/nkf/nkf-utf8: update nkf.
 
 Sun Jan 27 16:25:27 2008  NARUSE, Yui  <naruse@r...>
 
Index: string.c
===================================================================
--- string.c	(revision 15270)
+++ string.c	(revision 15271)
@@ -2011,21 +2011,18 @@
 {
     int i, l;
     while (1) {
-        for (i = len-1; 0 <= i; i--) {
-            int c;
-            c = ++((unsigned char*)p)[i];
-            if (c != 0)
-                break;
-        }
+        for (i = len-1; 0 <= i && (unsigned char)p[i] == 0xff; i--)
+            p[i] = '\0';
         if (i < 0)
             return NEIGHBOR_WRAPPED;
+        ++((unsigned char*)p)[i];
         l = rb_enc_precise_mbclen(p, p+len, enc);
         if (MBCLEN_CHARFOUND(l)) {
             if (l == len) {
                 return NEIGHBOR_FOUND;
             }
             else {
-                memset(p+l, '\xff', len-l);
+                memset(p+l, 0xff, len-l);
             }
         }
         if (MBCLEN_INVALID(l) && i < len-1) {
@@ -2035,7 +2032,7 @@
                 if (!MBCLEN_INVALID(l2))
                     break;
             }
-            memset(p+len2+1, '\xff', len-(len2+1));
+            memset(p+len2+1, 0xff, len-(len2+1));
         }
     }
 }
@@ -2045,21 +2042,18 @@
 {
     int i, l;
     while (1) {
-        for (i = len-1; 0 <= i; i--) {
-            int c;
-            c = --((unsigned char*)p)[i];
-            if (c != 0xff)
-                break;
-        }
+        for (i = len-1; 0 <= i && (unsigned char)p[i] == 0; i--)
+            p[i] = '\xff';
         if (i < 0)
             return NEIGHBOR_WRAPPED;
+        --((unsigned char*)p)[i];
         l = rb_enc_precise_mbclen(p, p+len, enc);
         if (MBCLEN_CHARFOUND(l)) {
             if (l == len) {
                 return NEIGHBOR_FOUND;
             }
             else {
-                memset(p+l, '\0', len-l);
+                memset(p+l, 0, len-l);
             }
         }
         if (MBCLEN_INVALID(l) && i < len-1) {
@@ -2069,7 +2063,7 @@
                 if (!MBCLEN_INVALID(l2))
                     break;
             }
-            memset(p+len2+1, '\0', len-(len2+1));
+            memset(p+len2+1, 0, len-(len2+1));
         }
     }
 }
@@ -2173,8 +2167,8 @@
     char *sbeg, *s, *e;
     int c = -1;
     long l;
-    char carry[ONIGENC_CODE_TO_MBC_MAXLEN];
-    int carry_pos, carry_len;
+    char carry[ONIGENC_CODE_TO_MBC_MAXLEN] = "\1";
+    int carry_pos = 0, carry_len = 1;
 
     str = rb_str_new5(orig, RSTRING_PTR(orig), RSTRING_LEN(orig));
     rb_enc_copy(str, orig);
@@ -2198,8 +2192,6 @@
         carry_len = l;
     }
     if (c == -1) {		/* str contains no alnum */
-        carry[0] = '\001';
-        carry_len = 1;
 	s = e;
 	while ((s = rb_enc_prev_char(sbeg, s, enc)) != 0) {
             enum neighbor_char neighbor;
@@ -2211,23 +2203,15 @@
                 /* wrapped to \0...\0.  search next valid char. */
                 enc_succ_char(s, l, enc);
             }
-            c = 1;
             carry_pos = s - sbeg;
 	}
-        if (c == -1) {
-            c = 1;
-            carry_pos = 0;
-        }
     }
-    if (!s && c == 1) {
-	RESIZE_CAPA(str, RSTRING_LEN(str) + carry_len);
-	s = RSTRING_PTR(str) + carry_pos;
-	memmove(s + carry_len, s, RSTRING_LEN(str) - carry_pos);
-	memmove(s, carry, carry_len);
-	STR_SET_LEN(str, RSTRING_LEN(str) + carry_len);
-	RSTRING_PTR(str)[RSTRING_LEN(str)] = '\0';
-    }
-
+    RESIZE_CAPA(str, RSTRING_LEN(str) + carry_len);
+    s = RSTRING_PTR(str) + carry_pos;
+    memmove(s + carry_len, s, RSTRING_LEN(str) - carry_pos);
+    memmove(s, carry, carry_len);
+    STR_SET_LEN(str, RSTRING_LEN(str) + carry_len);
+    RSTRING_PTR(str)[RSTRING_LEN(str)] = '\0';
     return str;
 }
 

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

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