From: Brian Candler Date: 2003-04-12T03:34:00+09:00 Subject: Re: rb_str_chomp or rb_str_strip On Sat, Apr 12, 2003 at 02:46:42AM +0900, Jim Freeze wrote: > On Saturday, 12 April 2003 at 1:58:00 +0900, ts wrote: > > >>>>> "J" == Jim Freeze writes: > > > > J> is #chomp! called via: > > > > J> res = rb_funcall2(str, rb_intern("chomp!"), 0, 0); > > > > Is there an efficient way to test for a character in a string? > > Using rb_funcall, I could do: > > VALUE testchr = rb_str_new("+", 1); > VALUE chr = rb_funcall(str,rb_intern("[]"), 1, INT2FIX(0)); > > Now that I have testchr and chr, I don't know how to compare them. > and, it seems awfully inefficient. > > I'd rather do someting like: > > if ( '+' == *(RSTRING(str)->ptr) ) { > > but this doesn't seem to work either. By the time you've done RSTRING you've got yourself a char* pointer, so have a look at memchr() in the standard C library. Of course, this means you've now moved away from Ruby programming and into C programming :-) Regards, Brian.