extract method for utf8 decoding/encoding

I moved the code for utf8 decoding/encoding to
separate methods, since it is at another level of
abstraction than stringToBytes and bytesToString.