Replace EncodingDetector::detect with a top-level function