Port bits and pieces more for encoding + string logic.

May help #1255.
Merge branch 'jruby-1_7'