Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Ruby (http://www.velocityreviews.com/forums/f66-ruby.html)
-   -   Bug in String.index? (http://www.velocityreviews.com/forums/t814152-bug-in-string-index.html)

Martin Kahlert 04-16-2004 10:50 AM

Bug in String.index?
 
Hi!
Is this a bug or a strange feature?

a = ""
a << 240
puts a[0]
puts a.index(240)

gives:
240
nil

ruby --version:
ruby 1.7.3 (2002-12-16) [i686-linux]
(1.8.1 shows the same behaviour)


Thanks for any workaround in advance
Martin.

Kent Dahl 04-16-2004 11:15 AM

Re: Bug in String.index?
 
Martin Kahlert wrote:
> Is this a bug or a strange feature?


No idea.

> Thanks for any workaround in advance


It seems like

a.index( 240.chr )

works as expected.

(ruby 1.8.0 (2003-08-04) [i586-linux-gnu])

--
(\[ Kent Dahl ]/)_ _~_ _____[ http://www.pvv.org/~kentda/ ]_____/~
))\_student_/(( \__d L b__/ Master of Science in Technology )
( \__\_|_/__/ ) _) Industrial economics and technology management (
\____/__\____/ (____engineering.discipline_=_Computer::Technology ___)


nobu.nokada@softhome.net 04-16-2004 11:26 AM

Re: Bug in String.index?
 
Hi,

At Fri, 16 Apr 2004 19:54:15 +0900,
Martin Kahlert wrote in [ruby-talk:97342]:
> Is this a bug or a strange feature?


A bug.


Index: string.c
================================================== =================
RCS file: /cvs/ruby/src/ruby/string.c,v
retrieving revision 1.190
diff -u -2 -p -r1.190 string.c
--- string.c 14 Apr 2004 04:06:25 -0000 1.190
+++ string.c 16 Apr 2004 11:25:30 -0000
@@ -1079,5 +1079,5 @@ rb_str_index_m(argc, argv, str)
case T_FIXNUM:
{
- int c = FIX2INT(sub);
+ char c = (char)FIX2INT(sub);
long len = RSTRING(str)->len;
char *p = RSTRING(str)->ptr;
@@ -1202,5 +1202,5 @@ rb_str_rindex_m(argc, argv, str)
case T_FIXNUM:
{
- int c = FIX2INT(sub);
+ char c = (char)FIX2INT(sub);
char *p = RSTRING(str)->ptr + pos;
char *pbeg = RSTRING(str)->ptr;


--
Nobu Nakada



Yukihiro Matsumoto 04-21-2004 04:16 PM

Re: Bug in String.index?
 
Hi,

In message "Re: Bug in String.index?"
on 04/04/16, nobu.nokada@softhome.net <nobu.nokada@softhome.net> writes:

|At Fri, 16 Apr 2004 19:54:15 +0900,
|Martin Kahlert wrote in [ruby-talk:97342]:
|> Is this a bug or a strange feature?
|
|A bug.

Indeed. I will fix.

matz.



Martin Kahlert 04-28-2004 12:59 PM

Re: Bug in String.index?
 
Hi,

In article <1082564201.620493.6072.nullmailer@picachu.netlab. jp>,
matz@ruby-lang.org (Yukihiro Matsumoto) writes:
> Hi,
>
> In message "Re: Bug in String.index?"
> on 04/04/16, nobu.nokada@softhome.net <nobu.nokada@softhome.net> writes:
>
>|At Fri, 16 Apr 2004 19:54:15 +0900,
>|Martin Kahlert wrote in [ruby-talk:97342]:
>|> Is this a bug or a strange feature?
>|
>|A bug.
>
> Indeed. I will fix.
>
> matz.


Thanks a lot for all replies - especially for nobu.nokada's patch!
Will this patch be included into the stable series?
In my today's snapshot it does not work out of the box and the patch seems
not to be in, yet.

Regards
Martin.



Yukihiro Matsumoto 04-28-2004 03:35 PM

Re: Bug in String.index?
 
Hi,

In message "Re: Bug in String.index?"
on 04/04/28, Martin Kahlert <mkcon@gmx.net> writes:

|Thanks a lot for all replies - especially for nobu.nokada's patch!
|Will this patch be included into the stable series?
|In my today's snapshot it does not work out of the box and the patch seems
|not to be in, yet.

I'm working on local copy. Wait for a few days.

matz.




All times are GMT. The time now is 01:27 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.