Currently I know only one well-documented way to convert all special characters in an arbitrary string into their FullForm:
In
InputForm, all special characters are written out fully when using"PrintableASCII".ToString["Lamé \[LongRightArrow] \[Alpha]\[Beta]+", InputForm, CharacterEncoding -> "PrintableASCII"]"\"Lam\\[EAcute] \\[LongRightArrow] \\[Alpha]\\[Beta]+\""
But exhaustive checking reveals that for some characters this produces wrong results:
toInputForm[s_String] :=
StringTake[ToString[s, InputForm, CharacterEncoding -> "PrintableASCII"], {2, -2}];
chs = {#, toInputForm[FromCharacterCode[#]]} & /@ Range[128, 65535];
sel = Select[chs, StringLength[#[[2]]] == 1 &];
Grid[Flatten[Transpose /@ Partition[sel, UpTo@11], 1], Frame -> {All, {{True, False}}},
Spacings -> 0.2, FrameStyle -> LightGray]
The outputted characters correspond to the ASCII set, not to the original Unicode code points:
MinMax@ToCharacterCode@StringJoin@sel[[;; , 2]]
{0, 127}
Is there a fix for this? Or is there a robust and efficient way to convert all the special and Unicode characters into their corresponding FullForms?
P.S. An attempt to start from FullForm also produces wrong result:
ToString[FullForm@StringJoin@sel[[;; , 2]], OutputForm]
"\"\\000\\001\\002\\003\\004\\005\\006\\007\\b\\t\\013\\f\\016\\017\\020\\021\\022\\023\\\ 024\\025\\026\\027\\030\\031\\032\\[RawEscape]\\034\\035\\036\\037\\177\""
Exporting as "Package" produces the correct output but it contains ugly header and several redundant newlines:
ExportString[FromCharacterCode[Range[61952, 61983]~Join~{62079}], "Package",
PageWidth -> Infinity]
"(* Created with the Wolfram Language : www.wolfram.com *)"\:f200\:f201\:f202\:f203\:f204\:f205\:f206\:f207\:f208\:f209\:f20a\:f20b\:
f20c\:f20d\:f20e\:f20f\:f210\:f211\:f212\:f213\:f214\:f215\:f216\:f217\:f218\
:f219\:f21a\:f21b\:f21c\:f21d\:f21e\:f21f\:f27f""
I'm hoping for something more elegant than cleaning out this...
