separate hfmt detection from getencoding() as a function