How can I re-encode a text file (or string) so that non-ASCII characters will be represented using Mathematica's standard names?
For example, if the original contents of the file was
then the re-encoded file should contain
"Mathematica7" comes close, but it is too aggressive: it also encodes ASCII characters like
ExportString["xαy", "Text", CharacterEncoding -> "Mathematica7"] (* "\\170\\[Alpha]\\171" *)
I do not want this. Update: Looking more closely, this is probably not the purpose of the
"MathematicaN" character encodings.
I also do not want to change the contents of the file, only change its encoding. This means that re-wrapping lines, eliminating whitespace, changing new lines, etc. is not acceptable.
Why do I need this? I want to take a package file that is UTF-8 encoded and make it platform independent. How such a file gets read by
Get depends on
$CharacterEncoding, which may differ between computers.