Looking for efficient Ruby C way to append strings

Hi:

I have the following condition:

a = "some text\n"
b = “+ some more text\n”

I am trying to do the following in C:

a.chomp!
a << b[1…-1]

Right now I have

rb_funcall(a, rb_intern(“chop!”), 0, NULL);
// needs to remove ‘+’ from b
rb_str_append(a, b);

It is tempting to increment the internal pointer
of b by one and then append to a.

What I would like to avoid is having to create a
whole new string object with b[1…-1] just to lose it in
the append.

Can one of you Ruby C experts help me out here?

Thanks

···


Jim Freeze

Don’t change the reason, just change the excuses!
– Joe Cointment

Well, to answer my own question, I found rb_str_cat().
Does the trick nicely.

···

On Sunday, 13 April 2003 at 5:02:22 +0900, Jim Freeze wrote:

Hi:

I have the following condition:

a = “some text\n”
b = “+ some more text\n”

I am trying to do the following in C:

a.chomp!
a << b[1…-1]

Right now I have

rb_funcall(a, rb_intern(“chop!”), 0, NULL);
// needs to remove ‘+’ from b
rb_str_append(a, b);


Jim Freeze

Lazlo’s Chinese Relativity Axiom:
No matter how great your triumphs or how tragic your defeats –
approximately one billion Chinese couldn’t care less.

Hi,

···

At Sun, 13 Apr 2003 05:02:22 +0900, Jim Freeze wrote:

rb_funcall(a, rb_intern(“chop!”), 0, NULL);
// needs to remove ‘+’ from b
rb_str_append(a, b);

It is tempting to increment the internal pointer
of b by one and then append to a.

It will certainly corrupt heap. You must never do it
absolutely.


Nobu Nakada