ruby-changes:4002
From: ko1@a...
Date: Sat, 16 Feb 2008 03:48:47 +0900 (JST)
Subject: [ruby-changes:4002] akr - Ruby:r15492 (trunk): * encoding.c (rb_enc_nth): moved to string.c.
akr 2008-02-16 03:48:27 +0900 (Sat, 16 Feb 2008)
New Revision: 15492
Modified files:
trunk/ChangeLog
trunk/encoding.c
trunk/string.c
Log:
* encoding.c (rb_enc_nth): moved to string.c.
* string.c (rb_enc_nth): moved from string.c. use search_nonascii
for ASCII compatible string.
(str_nth): wrong optimization removed to fix
"a".force_encoding("EUC-JP").slice!(0,10) returns
"a\x00\x00\x00\x00\x00\x00\x00\x00\x00"
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/string.c?r1=15492&r2=15491&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=15492&r2=15491&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/encoding.c?r1=15492&r2=15491&diff_format=u
Index: encoding.c
===================================================================
--- encoding.c (revision 15491)
+++ encoding.c (revision 15492)
@@ -720,28 +720,6 @@
return rb_enc_from_encoding(enc);
}
-
-char*
-rb_enc_nth(const char *p, const char *e, int nth, rb_encoding *enc)
-{
- int c;
-
- if (rb_enc_mbmaxlen(enc) == 1) {
- p += nth;
- }
- else if (rb_enc_mbmaxlen(enc) == rb_enc_mbminlen(enc)) {
- p += nth * rb_enc_mbmaxlen(enc);
- }
- else {
- for (c=0; p<e && nth--; c++) {
- int n = rb_enc_mbclen(p, e, enc);
-
- p += n;
- }
- }
- return (char*)p;
-}
-
long
rb_enc_strlen(const char *p, const char *e, rb_encoding *enc)
{
Index: ChangeLog
===================================================================
--- ChangeLog (revision 15491)
+++ ChangeLog (revision 15492)
@@ -1,3 +1,13 @@
+Sat Feb 16 03:43:18 2008 Tanaka Akira <akr@f...>
+
+ * encoding.c (rb_enc_nth): moved to string.c.
+
+ * string.c (rb_enc_nth): moved from string.c. use search_nonascii
+ for ASCII compatible string.
+ (str_nth): wrong optimization removed to fix
+ "a".force_encoding("EUC-JP").slice!(0,10) returns
+ "a\x00\x00\x00\x00\x00\x00\x00\x00\x00"
+
Sat Feb 16 00:21:49 2008 Nobuyoshi Nakada <nobu@r...>
* range.c (rb_range_beg_len): check if responds to "begin" and "end"
Index: string.c
===================================================================
--- string.c (revision 15491)
+++ string.c (revision 15492)
@@ -891,20 +891,57 @@
return rb_check_string_type(str);
}
+char*
+rb_enc_nth(const char *p, const char *e, int nth, rb_encoding *enc)
+{
+ int c;
+
+ if (rb_enc_mbmaxlen(enc) == 1) {
+ p += nth;
+ }
+ else if (rb_enc_mbmaxlen(enc) == rb_enc_mbminlen(enc)) {
+ p += nth * rb_enc_mbmaxlen(enc);
+ }
+ else if (rb_enc_asciicompat(enc)) {
+ const char *p2, *e2;
+ int n;
+
+ while (p < e && 0 < nth) {
+ e2 = p + nth;
+ if (e < e2)
+ return (char *)e;
+ if (ISASCII(*p)) {
+ p2 = search_nonascii(p, e2);
+ if (!p2)
+ return (char *)e2;
+ nth -= p2 - p;
+ p = p2;
+ }
+ n = rb_enc_mbclen(p, e, enc);
+ p += n;
+ nth--;
+ }
+ if (nth != 0)
+ return (char *)e;
+ return (char *)p;
+ }
+ else {
+ for (c=0; p<e && nth--; c++) {
+ int n = rb_enc_mbclen(p, e, enc);
+
+ p += n;
+ }
+ }
+ if (p > e) p = e;
+ return (char*)p;
+}
+
static char*
str_nth(const char *p, const char *e, int nth, rb_encoding *enc, int singlebyte)
{
if (singlebyte)
p += nth;
else {
- if (rb_enc_asciicompat(enc)) {
- const char *p2 = search_nonascii(p, e);
-
- if (!p2 || p + nth < p2)
- return (char*)p + nth;
- nth -= p2 - p;
- p = p2;
- }
p = rb_enc_nth(p, e, nth, enc);
}
if (!p) return 0;
--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/