func ParseMetadata(charset string, meta string) (metadata string) { if charset == "latin1" { if res, err := iconv.Conv(meta, "UTF-8", "UTF-8"); err == nil { metadata = res } else if res, err := iconv.Conv(meta, "UTF-8", "SHIFT_JIS"); err == nil { metadata = res } else { metadata, _ = iconv.Conv(meta, "UTF8//TRANSLIT", "UTF8") } } else { // We trust outside sources? burn the books! metadata, _ = iconv.Conv(meta, "UTF-8//TRANSLIT", charset) } return metadata }
// Decode, for example, "ISO-2022-JP" to UTF-8 func convertToUTF8(str string, charset string) string { charset = fixCharset(charset) if charset == "utf-8" { return str } // eg. charset can be "ISO-2022-JP" convstr, err := iconv.Conv(str, "UTF-8", charset) if err == nil { return convstr } return str }