Mercurial > hg > toybox
diff lib/lib.c @ 1525:95cb37adb024 draft
Factor out printf-style escape parsing logic from echo.c.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sat, 18 Oct 2014 17:14:12 -0500 |
parents | e5b52720f539 |
children | b50de98c9708 |
line wrap: on
line diff
--- a/lib/lib.c Thu Oct 16 05:58:35 2014 -0500 +++ b/lib/lib.c Sat Oct 18 17:14:12 2014 -0500 @@ -283,6 +283,14 @@ return off-haystack; } +int unescape(char c) +{ + char *from = "\\abefnrtv", *to = "\\\a\b\033\f\n\r\t\v"; + int idx = stridx(from, c); + + return (idx == -1) ? 0 : to[idx]; +} + // If *a starts with b, advance *a past it and return 1, else return 0; int strstart(char **a, char *b) {