I know there are system functions for this (and libiconv), but this is so trivial and quick in our implementation.