Fast byte replacement on string


I’m implementing a requirement for a Google service that reads in part

With urls…

“To start, repeatedly URL-unescape the URL until it has no more

Do lots of stuff here with url.

Finally “After performing these steps, percent-escape all characters in
the URL which are <= ASCII 32, >= 127, or “%”. The escapes should use
uppercase hex characters.”

Do any of you have a very fast way to do this?

The implementation I have now is dreadfully slow, I’ll spare you my
solution. J

I need a solution that will work with Ruby 1.8.6 & 1.9.1