commit | 5fcc71581abdf8839d10786d7ac437cc5b0bf4c5 | [log] [tgz] |
---|---|---|
author | Rob Landley <rob@landley.net> | Sat Oct 18 17:14:12 2014 -0500 |
committer | Rob Landley <rob@landley.net> | Sat Oct 18 17:14:12 2014 -0500 |
tree | 4143360f7699d4b2b6f3daecf7ae36a2c625a913 | |
parent | 01138b94e6ac9ff2d1258917f96c0c5c8c124021 [diff] [blame] |
Factor out printf-style escape parsing logic from echo.c.
diff --git a/lib/lib.c b/lib/lib.c index 19d28d2..dc2de12 100644 --- a/lib/lib.c +++ b/lib/lib.c
@@ -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) {