unescaper
unescaper copied to clipboard
feat: Unfailable unescaper
Would it be appropriate for this project to also include version of unescape
that cannot fail? Specifically where it would fail at unescaping it just shows the original string, but it continues to try to unescape the rest of the string.
For context I need something with the behavior similar to glib's g_strcompress.
If it would be appropriate for this project, I would be interested in working on a PR.
Would it be appropriate for this project to also include version of
unescape
that cannot fail?
I'm not familiar with glib, but would unescape(s).unwrap_or(s)
do the trick? Is necessary to add another function?
No, it's really more of a best attempt of unescaping. So unescaping what can be unescaped and leaving the rest, in a sort of left to right fashion. They call it "compressing" but is essentially the same idea as unescaping.
If you want to give it a try, use notify-send
on a compatible system (probably only Linux distros) and play with the body
argument (the second positional argument), as it is passed directly to g_strcompress
. It allows the user to type something like \n
on the command line and have the two individual characters be transferred into a single newline character (it handles more sequences other than \n
)