Extract out UTF-8 logic handling into util

This code doesn't depend on any Rubinius internals, so it can be
extracted out into utility helpers. This also provides a place if we add
more optimizations and is easier for a proper attribution.