Bug in String.index?

Discussion in 'Ruby' started by Martin Kahlert, Apr 16, 2004.

  1. 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.
    Martin Kahlert, Apr 16, 2004
    #1
    1. Advertising

  2. Martin Kahlert

    Kent Dahl Guest

    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___)
    Kent Dahl, Apr 16, 2004
    #2
    1. Advertising

  3. Martin Kahlert

    Guest

    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
    , Apr 16, 2004
    #3
  4. Hi,

    In message "Re: Bug in String.index?"
    on 04/04/16, <> 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.
    Yukihiro Matsumoto, Apr 21, 2004
    #4
  5. Hi,

    In article <>,
    (Yukihiro Matsumoto) writes:
    > Hi,
    >
    > In message "Re: Bug in String.index?"
    > on 04/04/16, <> 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.
    Martin Kahlert, Apr 28, 2004
    #5
  6. Hi,

    In message "Re: Bug in String.index?"
    on 04/04/28, Martin Kahlert <> 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.
    Yukihiro Matsumoto, Apr 28, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. karthikeyavenkat
    Replies:
    2
    Views:
    554
    Bryce
    Mar 17, 2005
  2. Shawn W_
    Replies:
    5
    Views:
    256
    Aldric Giacomoni
    Sep 16, 2009
  3. ngoc
    Replies:
    5
    Views:
    165
    Tad McClellan
    May 11, 2006
  4. Tomasz Chmielewski

    sorting index-15, index-9, index-110 "the human way"?

    Tomasz Chmielewski, Mar 4, 2008, in forum: Perl Misc
    Replies:
    4
    Views:
    256
    Tomasz Chmielewski
    Mar 4, 2008
  5. Stefan Mueller
    Replies:
    7
    Views:
    171
    Thomas 'PointedEars' Lahn
    Nov 28, 2005
Loading...

Share This Page