Remove partition/chop trick, fix cast SafeBuffer as pure string

Any subclassing of String messes up gsub's super magic global $~ variables,
it's a known ruby bug discussed at https://github.com/rails/rails/issues/1555