diff options
author | Andrew Gallant <jamslam@gmail.com> | 2018-07-22 09:32:31 -0400 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2018-07-22 09:33:03 -0400 |
commit | b9c922be53fdadb28ddbb02b4b0d0a63f8bdebe7 (patch) | |
tree | 21e927aee8f21629405b33558f6fbfc1fb8067a2 /src/unescape.rs | |
parent | 7a44cad599d7602ccd4395136c14587c159a37a3 (diff) |
ripgrep: better --path-separator error message
This commit improves the error message when --path-separator fails. Namely,
it prints the separator it got and also prints a notice for Windows users
for common failure modes.
Fixes #957
Diffstat (limited to 'src/unescape.rs')
-rw-r--r-- | src/unescape.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/unescape.rs b/src/unescape.rs index c27e6e28..0c7f1c8d 100644 --- a/src/unescape.rs +++ b/src/unescape.rs @@ -11,6 +11,15 @@ enum State { Literal, } +/// Escapes an arbitrary byte slice such that it can be presented as a human +/// readable string. +pub fn escape(bytes: &[u8]) -> String { + use std::ascii::escape_default; + + let escaped = bytes.iter().flat_map(|&b| escape_default(b)).collect(); + String::from_utf8(escaped).unwrap() +} + /// Unescapes a string given on the command line. It supports a limited set of /// escape sequences: /// |