stringi
stringi copied to clipboard
Encoding sleuthing function
Sometimes you know what a character should be, and you know how it's stored in a file, and you want to figure out what encoding it might have been (e.g. https://github.com/hadley/readr/issues/252). It would be helpful to have something to help automate the search, e.g.
x <- "Ü"
encs <- names(stri_enc_list())
conv <- lapply(encs, function(to) stri_conv(x, "UTF-8", to, to_raw = TRUE)[[1]])
names(conv) <- encs
Filter(function(x) identical(x[[1]], charToRaw("\x86")), conv)
good idea, thanks