Mercurial > hg > toybox
comparison 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 |
comparison
equal
deleted
inserted
replaced
1524:2ce0f52103a9 | 1525:95cb37adb024 |
---|---|
279 if (!needle) return -1; | 279 if (!needle) return -1; |
280 off = strchr(haystack, needle); | 280 off = strchr(haystack, needle); |
281 if (!off) return -1; | 281 if (!off) return -1; |
282 | 282 |
283 return off-haystack; | 283 return off-haystack; |
284 } | |
285 | |
286 int unescape(char c) | |
287 { | |
288 char *from = "\\abefnrtv", *to = "\\\a\b\033\f\n\r\t\v"; | |
289 int idx = stridx(from, c); | |
290 | |
291 return (idx == -1) ? 0 : to[idx]; | |
284 } | 292 } |
285 | 293 |
286 // If *a starts with b, advance *a past it and return 1, else return 0; | 294 // If *a starts with b, advance *a past it and return 1, else return 0; |
287 int strstart(char **a, char *b) | 295 int strstart(char **a, char *b) |
288 { | 296 { |