Functions for converting Unicode strings to UTF-8 and vice versa.
Taken from http://www.cse.ogi.edu/~hallgren/Talks/LHiH/base/lib/UTF8.hs. (c) 2003, OGI School of Science & Engineering, Oregon Health and Science University.
Modified by Martin Norbaeck to pass illegal UTF-8 sequences through unchanged.